Created
June 9, 2012 05:54
-
-
Save liquidz/2899679 to your computer and use it in GitHub Desktop.
Scold me if I didn't push to GitHub for 3 days
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
// 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