-
Notifications
You must be signed in to change notification settings - Fork 0
/
github.js
51 lines (46 loc) · 1.75 KB
/
github.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
const request = require('request');
const githubConfig = require('./config/github-config.json');
const getOptions = {
//method : 'get',
uri : 'https://api.github.com/users/' + githubConfig.userName + '/events',
headers: {
'User-Agent' : 'Chrome/83.0.4103.116'
}
}
module.exports = {
existsTodayCommit : function(callback){
request.get(getOptions, function (error, response, body) {
if(error){
console.log('get git events fail, error:', error);
return;
}
if(!response || 404 == response.statusCode) {
console.log('get git events fail, statusCode :', response.statusCode);
return;
}
console.log('get git events complete, statusCode :', response && response.statusCode);
let events = JSON.parse(body);
let eventsLength = Object.keys(events).length;
let today = new Date();
today = new Date(today.getTime() - (((((today.getHours()) * 60) + today.getMinutes()) * 60) + today.getSeconds()) * 1000);
console.log("today : " + today);
let todayStr = today.getFullYear() + '년 ' + (today.getMonth() + 1) + '월 ' + today.getDate() + '일';
for(var i = 0; i < eventsLength; i++) {
let createdEventDate = new Date(events[i].created_at);
if(today.getTime() <= createdEventDate.getTime()){
if('PushEvent' == events[i].type || 'PullRequestEvent' == events[i].type) {
let msg = todayStr + ' 1일 1커밋 완료';
console.log(msg);
return;
}
}else {
let msg = todayStr + ' 1일 1커밋 미완료, 커밋좀 합시다~ :)';
console.log(msg + ', 슬랙 메시지 전송 시도');
callback(msg);
return;
}
}
return;
})
}
}