Skip to content

Instantly share code, notes, and snippets.

@jmhobbs
Last active Dec 19, 2016
Embed
What would you like to do?
git post commit hook to harvest active timer
#!/usr/local/bin/python
import requests
import subprocess
# Configure Your Info Here
DOMAIN = "https://YOU.harvestapp.com"
USERNAME = ""
PASSWORD = ""
# / End Config
headers = {
'Accept': 'application/json',
'User-Agent': 'git post commit hook',
}
log = subprocess.check_output(["git", "log", "--pretty=oneline", "--no-decorate", "--abbrev-commit", "-1", "HEAD"])
response = requests.get("%s/daily" % DOMAIN, headers=headers, auth=(USERNAME, PASSWORD))
today = response.json()
for day_entry in today['day_entries']:
if "timer_started_at" in day_entry:
if not day_entry["notes"]:
day_entry["notes"] = ""
day_entry["notes"] = "\n".join((day_entry["notes"], log))
requests.post("%s/daily/update/%s" % (DOMAIN, day_entry["id"]), data=day_entry, headers=headers, auth=(USERNAME, PASSWORD))
break
  1. Copy to PROJECT/.git/hooks/post-commit
  2. chmod u+x PROJECT/.git/hooks/post-commit
  3. Edit and fix your config
  4. Do some commits.
@jmhobbs

This comment has been minimized.

Copy link
Owner Author

@jmhobbs jmhobbs commented Jan 26, 2015

@jmhobbs

This comment has been minimized.

Copy link
Owner Author

@jmhobbs jmhobbs commented Jan 26, 2015

This is using python from homebrew, if you don't have that, change the first line of the commit hook:

#!/usr/bin/env python

It also needs requests, so make sure that is installed.

sudo pip install requests
@jmhobbs

This comment has been minimized.

Copy link
Owner Author

@jmhobbs jmhobbs commented Jan 26, 2015

I think I prefer a shorter message in mine, so I am changing line 16 to:

log = subprocess.check_output(["git", "log", "--pretty=oneline", "--no-decorate", "--abbrev-commit", "-1", "HEAD"])
@codyjames

This comment has been minimized.

Copy link

@codyjames codyjames commented Jan 26, 2015

Worked like a charm! Pretty freaking cool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment