pcdshub / engineering_tools

A repository of scripts, configuration useful for the PCDS team
Other
4 stars 26 forks source link

Helper Scripts for Maintaining Github Forks #51

Open ZLLentz opened 4 years ago

ZLLentz commented 4 years ago

Expected Behavior

We should have helper scripts for the Github workflow:

Current Behavior

No such scripts currently exist

Possible Solution

Port over @ZLLentz's tools and clean them up

git_setup_fork ()
{
    usage="git_setup_fork <repo>";
    if [ -z "${1}" ]; then
        echo "${usage}";
        return;
    fi;
    REPO=`basename "${1}"`;
    UPSTREAM=`dirname "${1}"`;
    GITHUB_USERNAME="ZLLentz";
    git clone "git@github.com:${GITHUB_USERNAME}/${REPO}.git";
    pushd "${REPO}";
    git remote add upstream "git@github.com:${UPSTREAM}/${REPO}.git";
    popd
}
git_sync_upstream ()
{
    git checkout master;
    git fetch upstream;
    git pull upstream master;
    git push origin master
}

Context

In the engineering general, there is some consensus that maintaining a fork is a pain point.

ZryletTC commented 4 years ago

Synchronizing is pretty simple but how do you fork from a script? The only answer I can think of is using Github's REST API. Is that what you're thinking?

Also where are these cool ZLLentz tools? I wanna see 👀

klauer commented 4 years ago

hub fork / gh fork New, official cli tool: https://github.com/cli/cli Old, still convenient tool: https://github.com/github/hub

ZryletTC commented 4 years ago

Are we going to include one of those in the pcds-env then?

ZLLentz commented 4 years ago

Sorry, I was going to copy in my little scripts here as a starting point but got distracted with the other questions in the presentation today. I'll do that now.

edit: snippits added to the issue text

ZLLentz commented 4 years ago

gh looks super interesting- I didn't even consider this might be a possibility

klauer commented 4 years ago

It's a big part of my normal workflow, along with being able to list/view PRs and issues. I've always installed it by way of brew, but it apparently exists on conda-forge.

If it might help the average PCDS user, perhaps it'd be worth including in our environment.

ZLLentz commented 4 years ago

Can you give an example of when you would use the gh command as part of your workflow? I see a lot of nice-looking pieces but nothing that screams "use me a lot"- what am I missing?

klauer commented 4 years ago

I think the functionality it offers could just be considered "niceties" for those that like the command-line. For the purposes of writing scripts that make changes on a lot of repos, they're indispensable - which admittedly is not our target audience here.

With hub/gh, I find clicking around GitHub's interface only truly necessary when I need to review a PR and add a bunch of comments.

Contributing to others' PRs:

$ gh pr list
$ gh pr checkout 123
$ git commit -a -m '...'
$ git push

Making a fork, and quickly opening a PR:

$ gh repo fork

# this is admittedly very command-line user focused:
$ gh pr create

Quickly handling remotes - not sure gh does this, but hub does and it's nice:

$ hub remote add pcdshub
$ hub remote -v
pcdshub  git@github.com:pcdshub/currentreponame.git (fetch)

Quickly jumping to the repo webpage by way of gh repo view --web or just viewing its README in color without the --web.

Checking issue lists by way of gh issue list and grepping through them, etc.