Skip to content

Instantly share code, notes, and snippets.

@liquidz
Created June 9, 2012 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liquidz/2899679 to your computer and use it in GitHub Desktop.
Save liquidz/2899679 to your computer and use it in GitHub Desktop.
Scold me if I didn't push to GitHub for 3 days
// Initializing variables
var githubAccessToken = 'GitHub Access Token';
var days = 3;
var message = 'GitHub: WOOOORK!!!!!';
// End of variables initializing
var isNull = function(x){
return (x === null || x === undefined);
};
var getDateFromString = function(timeStr){
var res = timeStr.match(/(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)Z/);
return new Date(parseInt(res[1], 10)
, parseInt(res[2], 10) - 1
, parseInt(res[3], 10)
, parseInt(res[4], 10)
, parseInt(res[5], 10)
, parseInt(res[6], 10));
};
var diffDate = function(from, to){
var diff = from - to;
return Math.floor(diff / 86400000);
};
var notify = function(title, body){
var n = device.notifications.createNotification(title);
if(! isNull(body)){ n.content = body; }
n.show();
};
console.log("Started script: Scold me if I didn't push to GitHub for " + days + " days");
device.screen.on('unlock', function(){
device.ajax({
url: 'https://api.github.com/user/repos?sort=pushed'
, type: 'GET'
, headers: { 'Authorization': 'token ' + githubAccessToken }
}, function(_body, statusText, response){
if(! isNull(_body)){
var latestRepo = JSON.parse(_body)[0]
, pushedDate = getDateFromString(latestRepo.pushed_at)
;
if(diffDate(new Date(), pushedDate) > days){
notify(message);
}
}
}, function(textStatus, response){
console.error('error: ', { message: textStatus, status: response.status });
});
});
console.log("Completed script: Scold me if I didn't push to GitHub for " + days + " days");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment