Last active
August 29, 2015 14:11
-
-
Save nfm/6710b49d2cd908b9ac55 to your computer and use it in GitHub Desktop.
Quick proof of concept git hook integration with the Paydirt API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[paydirt] | |
apikey = abcdef | |
jobid = 12345 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'httparty' | |
API_ENDPOINT = "https://paydirtapp.com/api/v1/time" | |
commit_message = `git log -1 HEAD --format=format:%s` | |
# Fetch the Paydirt API key with from .git/config | |
api_key = `git config --get paydirt.apikey`.strip | |
# Fetch the Paydirt task this repo is associated with from .git/config | |
# This could be part of the commit message format, or associated with the issue #, or anything really | |
job_id = `git config --get paydirt.jobid`.strip | |
# If commit message ends in [Xm] | |
# This could be extended to match different formats (eg. XhYm, Xh, X.YZh, X:YZ etc) | |
if commit_message.match(/\[(\d+)m\]$/) | |
duration_in_minutes = $1.to_i | |
duration_in_seconds = duration_in_minutes * 60 | |
# Log time in Paydirt towards the appropriate task | |
response = HTTParty.post(API_ENDPOINT, query: { api_key: api_key, job_id: job_id, duration_only: true, duration: duration_in_seconds, date: Date.today }) | |
if response.success? | |
puts "Logged #{duration_in_minutes} minutes in Paydirt" | |
exit 0 | |
else | |
abort "Error: #{response.parsed_response['errors']}" | |
end | |
else | |
exit 0 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment