-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgithub-events.js
51 lines (48 loc) · 1.23 KB
/
github-events.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
require('dotenv').load();
var Pusher = require('pusher');
var GitHubApi = require("github");
var prettyjson = require("prettyjson");
var pusher = new Pusher({
appId: process.env.PUSHER_APP_ID,
key: process.env.PUSHER_KEY,
secret: process.env.PUSHER_SECRET
});
var github = new GitHubApi({
// required
version: "3.0.0",
// optional
debug: false,
protocol: "https",
headers: {
"user-agent": "JSOxford-RTHack" // GitHub is happy with a unique user agent
}
});
github.authenticate({
type: "oauth",
key: process.env.GH_KEY,
secret: process.env.GH_SECRET
})
var now = new Date();
var getNewEvents = function(){
github.events.getFromOrg({
org: "JSOxford"
}, function(err, res) {
if(err) {
console.log(err);
return;
}
var newEvents = [],
i=0, len=res.length;
for(i=0;i<len;i++){
if(new Date(res[i].created_at) > now){
newEvents.push(res[i]);
}
}
for(i=0,len=newEvents.length;i<len;i++){
pusher.trigger('github', 'org-event', newEvents[i]);
}
now = new Date();
});
setTimeout(getNewEvents, 3000);
};
setTimeout(getNewEvents, 3000);