1

I'm looking to scratch an itch. At my company we use GitHub and name our development branches based on the corresponding GitHub issue for the repo.

Often times, I'll have several development branches, so when I do git branch, I see:

$ git branch
  10
  119
* 83
  92
$ 

Is there any tool/plug-in that can pull the issue title from GitHub and print it alongside the branch name? For example:

$ git branch
  10    Do some cool work
  119   Fix some bug
* 83    Invent more time
  92    Get it to brew coffee
thinkski
  • 1,236
  • 1
  • 13
  • 23
  • You an annotiate your branch name at creation time, see http://stackoverflow.com/questions/11886132/can-i-add-a-message-note-comment-when-creating-a-new-branch-in-git – DavidN Jun 15 '16 at 03:50
  • Neat, although how can I see the descriptions for all branches in one view, for instance if I'm hunting for the branch from 2 weeks ago that brews coffee? And I'm still inputting the info twice in two places. – thinkski Jun 15 '16 at 04:58

1 Answers1

3

You can use the GitHub REST API and jq to get the name for an issue, for example:

curl -fsS "https://api.github.com/repos/YOUR_ORG/YOUR_REPO/issues/3" | jq  '.title'

It doesn't matter whether "3" is an issue or a pull request, the API will respond with the issue title either way.

You can integrate this into git using an alias. Create a shell script that works for the git branch output, that is, a script that reads standard input line by line, checks if the branch name is numeric, invokes the curl command if needed, and formats the output the way you want it.

Finally, create an alias:

git config alias.brr = '!git branch | /path/to/your/script'

...and run git brr to get your output.

If the repository is private, you need to supply an OAuth token in the curl command, like so:

curl -H 'Authorization: token 01234567890abcdef' \
     -fsS "https://api.github.com/repos/YOUR_ORG/YOUR_REPO/issues/3"

The token can be created in your account settings.

DavidN
  • 7,947
  • 2
  • 17
  • 21
Barend
  • 16,572
  • 1
  • 52
  • 76
  • 1
    Nice! I also found Hub, a cli wrapper tool around git (https://hub.github.com) that has a `git issue` command. Working on a pull request to adapt the branch command to do just this with it (they have the token authorization, including two-factor which I use, already baked in. – thinkski Jun 15 '16 at 19:17