Created
April 1, 2012 08:13
-
-
Save hamstar/2273229 to your computer and use it in GitHub Desktop.
Quick and dirty github issue time tracker
This file contains hidden or 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
<?php | |
/** | |
* Ask me http://example.com/get_time.php?issue_id=hamstar-Wikimate-9&key=X7v54j | |
* Returns time | |
*/ | |
$API_KEY = "X7v54j"; | |
// TODO precons | |
if ( $_GET['key'] != $API_KEY ) | |
die('access denied'); | |
$issue = $_GET['issue_id']; | |
$fn = "times/$issue"; | |
if ( !file_exists( $fn ) ) | |
die("0h0m"); | |
echo file_get_contents( $fn ); |
This file contains hidden or 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
// Git Time Tracker Greasemonkey Script | |
// version 0.1 BETA! | |
// 2005-04-22 | |
// Copyright (c) 2005, Robert McLeod | |
// Released under the GPL license | |
// http://www.gnu.org/copyleft/gpl.html | |
// | |
// -------------------------------------------------------------------- | |
// | |
// This is a Greasemonkey user script to track time in git. | |
// | |
// Currently single user (no breakdown on time spent per user per issue) | |
// | |
// You will need to add the server side scripts somewhere and add your | |
// URL and api key below. | |
// | |
// -------------------------------------------------------------------- | |
// | |
// ==UserScript== | |
// @name Git Time Tracker | |
// @namespace https://gist.github.com/2273229 | |
// @description Script to track time on github | |
// @include https://github.com/*/*/issues/* | |
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js | |
// ==/UserScript== | |
// api setting | |
api_key = "X7v54j"; | |
api_url = "http://example.com/"; | |
// Get the issue id | |
url = window.location.href; | |
issue_id = url.replace('https://github.com/','') | |
.replace('issues/','') | |
.replace(/\//g,'-'); | |
// Add the time tracker stuff | |
sidebar = $("div.discussion-sidebar"); | |
sidebar.append($('<hr>')); | |
sidebar.append($('<p>').html( "<strong>Time Spent</strong>" )); | |
sidebar.append($('<p>').attr('id', 'tracked-time').text("loading...").css('font-size','large')); | |
sidebar.append($('<p>').html("<a href='javascript:void(0)' id='set-time-link'>Set Time</a>")); | |
// get the time from the storage | |
get_time_url = api_url + "get_time.php?key=" + api_key +"&issue_id=" + issue_id; | |
GM_xmlhttpRequest({ | |
method: "GET", | |
url: get_time_url, | |
onload: function(r) { | |
$('#tracked-time').text( r.responseText ); | |
} | |
}); | |
document.addEventListener('click', function(event) { | |
// event.target is the element that was clicked | |
if ( event.target.id == 'set-time-link' ) { | |
time = prompt("Enter the time spent"); | |
set_time_url = api_url + "set_time.php?key=" | |
+ api_key +"&issue_id=" + issue_id | |
+ "&time="+time; | |
GM_xmlhttpRequest({ | |
method: "GET", | |
url: set_time_url, | |
onload: function(r) { | |
$('#tracked-time').text( r.responseText ); | |
} | |
}); | |
// if you want to prevent the default click action | |
// (such as following a link), use these two commands: | |
event.stopPropagation(); | |
event.preventDefault(); | |
} | |
}, true); |
This file contains hidden or 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
<?php | |
/** | |
* Feed me http://example.com/set_time.php?time=25m&issue_id=hamstar-Wikimate-9&key=X7v54j | |
*/ | |
$API_KEY = "X7v54j"; | |
// TODO precons | |
if ( $_GET['key'] != $API_KEY ) | |
die('access denied'); | |
$issue = $_GET['issue_id']; | |
$time = substr( $_GET['time'], 0, 50 ); | |
$fn = "times/$issue"; | |
file_put_contents( $fn, $time ); | |
echo $time; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment