2009/10/12

GitHub from the command line

Here are a couple of shell aliases that I’ve found useful recently. To use, add them to your .bash_profile file. All of these commands are intended to be run from the working directory of a Git repository that is connected to GitHub.

  • Used in the following, more useful, commands, this returns the GitHub identifier for a repository: (E.g., wspr/thesis)

    alias githubname='git config -l | grep '\''remote.origin.url'\'' | sed -En   '\''s/remote.origin.url=git(@|:\/\/)github.com(:|\/)(.+)\/(.+).git/\3\/\4/p'\'''
    
  • On Mac OS X, this opens your GitHub project in the default browser: (I’m guessing it needs some adjustment to work under Linux.)

    alias github='open https://github.com/`githubname`'
    
  • Similarly, this one opens up the Issues page:

    alias issues='open https://github.com/`githubname`/issues'
    
  • Finally, this one returns the number of open issues in the GitHub project:

    alias countissues='curl -s http://github.com/api/v2/yaml/issues/list/`githubname`/open -- | grep '\''\- number:'\'' | wc -l'
    

Via the GitHub Issue API, it’s possible to extract all sorts of useful information programmatically that could come in handy for project management. Use the output of this URL to get all the juicy info:

http://github.com/api/v2/yaml/issues/list/`githubname`/open

For example, I’d like to write a script to report summary details of all open issues across all of my projects/repositories. Saving it up for a rainy day.

It would also be interesting to write a script to run before pushing that checks which issues you’re closing (via the closes #xyz commit log interface) and shows a brief summary for confirmation before sending off the commits. That’s for a rainy weekend.