Skip to content

Instantly share code, notes, and snippets.

@dlo
Created November 24, 2009 06:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dlo/241697 to your computer and use it in GitHub Desktop.
Save dlo/241697 to your computer and use it in GitHub Desktop.
git hook to push issues to github
#!/usr/bin/env python
"""
LICENSE
=======
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar
14 rue de Plaisance, 75014 Paris, France
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
Instructions
============
1. Place this and `post-commit` in the .git/hooks folder.
2. Commit message must contain `gh-#`.
3. This script will update Github and will comment the issue with a
link to the appropriate commit. Note: it will remove any reference to
the `gh-#` mentioned earlier. Hence "Fixes issue gh-53" will just
become "Fixes issue". You can change this if it's annoying.
"""
import sys
import httplib
import urllib
import re
import json
USER=''
TOKEN=''
REPO=''
commit=sys.argv[1]
msg=commit.split('\n')[5]
number=re.sub(r'[^\d]', '', msg)
head=sys.argv[2].split(' ')[0]
if len(number) > 0:
conn=httplib.HTTPSConnection("github.com")
msg=re.sub(r'gh-\d+', '', msg)
data={
'login': USER,
'token': TOKEN,
'comment': '%s: %s' % (head, msg)
}
data = urllib.urlencode(data)
print "[github] connecting..."
conn.request('POST', '/api/v2/json/issues/comment/%s/%s/%s' % (USER, REPO, \
number), data, {})
request = conn.getresponse()
if 'comment' in json.loads(request.read()):
print "[github] success! issue %s updated" % number
#!/bin/sh
commit=$(git cat-file -p HEAD)
head=$(git show-ref -h)
p=$(pwd)
$p/.git/hooks/issue.py "$commit" "$head"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment