Skip to content

Instantly share code, notes, and snippets.

@jmhobbs
Last active December 19, 2016 04:36
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmhobbs/4747e794a47943f8e2ab to your computer and use it in GitHub Desktop.
Save jmhobbs/4747e794a47943f8e2ab to your computer and use it in GitHub Desktop.
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
Copy link
Author

jmhobbs commented Jan 26, 2015

@jmhobbs
Copy link
Author

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
Copy link
Author

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
Copy link

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