Fix post-receive hook's API postings.

(imported from commit 98021d3ee5e84b533e17ec741538be60925b4e87)
This commit is contained in:
Tim Abbott 2012-10-03 14:48:51 -04:00
parent d5d3694451
commit e53dbbd756
1 changed files with 19 additions and 5 deletions

View File

@ -19,9 +19,23 @@ import subprocess
sys.path.append(os.path.dirname(os.path.dirname(os.readlink(__file__)))) sys.path.append(os.path.dirname(os.path.dirname(os.readlink(__file__))))
import api.common import api.common
client = api.common.HumbugAPI(email="humbug+commits@humbughq.com", client = api.common.HumbugAPI(email="humbug+commits@humbughq.com",
api_key=options.api_key, api_key="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
verbose=False, verbose=False)
site=options.site)
def check_output(*popenargs, **kwargs):
if 'stdout' in kwargs:
raise ValueError('stdout argument not allowed, it will be overridden.')
process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs)
output, unused_err = process.communicate()
retcode = process.poll()
if retcode:
cmd = kwargs.get("args")
if cmd is None:
cmd = popenargs[0]
raise subprocess.CalledProcessError(retcode, cmd, output=output)
return output
subprocess.check_output = check_output
args = sys.stdin.read() args = sys.stdin.read()
oldrev, newrev, refname = args.split() oldrev, newrev, refname = args.split()
@ -30,12 +44,12 @@ if refname in ["refs/heads/master", "refs/heads/test-post-receive"]:
subprocess.check_call(["ssh", "app.humbughq.com", "--", "env", "-u", "GIT_DIR", subprocess.check_call(["ssh", "app.humbughq.com", "--", "env", "-u", "GIT_DIR",
"/home/humbug/humbug/tools/update-deployment", "/home/humbug/humbug/tools/update-deployment",
oldrev, newrev, refname]) oldrev, newrev, refname])
commits = subprocess.check_output(["git", "log", "--pretty=%s", "%s..%s" % (oldrev, newrev)]) commits = subprocess.check_output(["git", "log", "--pretty=- %s", "%s..%s" % (oldrev, newrev)])
message_data = { message_data = {
"type": "class", "type": "class",
"class": "devel", "class": "devel",
"instance": "commits", "instance": "commits",
"content": "Commit %s pushed to %s! Commits include:\n" % (newrev, refname) + commits, "content": "The following commits were just pushed to %s:\n\n" % (refname.replace("refs/heads/", ""),) + commits,
"recipient": "tabbott@humbughq.com", "recipient": "tabbott@humbughq.com",
} }
client.send_message(message_data) client.send_message(message_data)