-
Notifications
You must be signed in to change notification settings - Fork 1
/
git-status.js
64 lines (54 loc) · 1.62 KB
/
git-status.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var request = require('request');
var http = require('http');
var fs = require('fs');
var args = process.argv;
var path = args[1];
var script_path = path.split('\\');
script_path.pop();
script_path = script_path.join('/');
var config = fs.readFileSync(script_path + '/config.json');
config = JSON.parse(config);
var server_status = 'good';
var flowdock_api_token = config.flowdock_api_token;
if (args.indexOf('-once') >= 0)
getServerStatus();
else
setInterval(getServerStatus, 30000);
function getServerStatus() {
console.log('getServerStatus: ' + server_status);
try {
request('https://status.github.com/api/last-message.json', serverStatusRequest);
}
catch (e) {
console.log('Could not retrieve github server status: ' + e.message);
}
}
function serverStatusRequest(error, response, body) {
response = JSON.parse(body);
if (server_status != response.status) {
updateStatus(response.status);
console.log('server status changed: ' + server_status);
try {
sendUpdateStatus(response.body);
}
catch(e) {
console.log('Sending to flowdock failed: ' + e.message);
}
}
}
function updateStatus(status) {
server_status = status;
}
function sendUpdateStatus(message) {
var options = {
'url': 'https://api.flowdock.com/v1/messages/chat/' + flowdock_api_token,
'qs': {
'content': message,
"external_user_name": config.external_user_name || 'git-status',
'tags': config.tags || ['git-status']
}
};
var req = request.post(options, function(error, response, body) {
console.log(body);
});
}