-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
97 lines (84 loc) · 2.84 KB
/
Copy pathserver.js
File metadata and controls
97 lines (84 loc) · 2.84 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
var dotenv = require('dotenv');
dotenv.load();
var GitHub = require('github-api');
var get_token = require('./TOKEN');
var request = require('request');
var validateMessage = require('validate-commit-msg');
var gh = new GitHub({
token : get_token
});
const secret = process.env.WEBHOOK_SECRET;
const http = require('http')
const webHookHandler = require('github-webhook-handler')({
path: '/',
secret: secret
})
http.createServer(handleRequest).listen(3000)
console.log('server started')
webHookHandler.on('pull_request', (event) => {
console.log(`Received PR "${event.payload.pull_request.number}"`);
console.log(`Commits URL "${event.payload.pull_request.commits_url}"`);
request({
url : event.payload.pull_request.commits_url,
headers : {
'User-Agent': 'Hoodie Bot'
}
}, (error, response,body) => {
var commits = JSON.parse(body);
var commitMessages = [];
for(var i = 0; i < commits.length; i++) {
commitMessages.push(commits[i].commit.message);
}
// console.log(commitMessages);
// var valid = validateMessage('chore(index): an example commit message');
for(var i = 0; i < commitMessages.length; i++) {
console.log(commitMessages[i]);
var valid = validateMessage(commitMessages[i]);
console.log(valid);
}
});
})
function handleRequest (request, response) {
// ignore all requests that aren’t POST requests
if (request.method !== 'POST') {
console.log("Get Request Received");
return response.end('ok');
}
// here we pass the current request & response to the webHookHandler we created
// on top. If the request is valid, then the "issue" above handler is called
webHookHandler(request, response, () => response.end('ok'))
}
// module.exports = function (robot) {
// robot.on('issues', handleIssue.bind(null, robot))
// }
//
// function handleIssue (robot, context) {
// const api = context.github
// const {installation, repository, issue} = context.payload
//
// api.issues.createComment({
// owner: repository.owner.login,
// repo: repository.name,
// number: issue.number,
// body: 'Welcome to the robot uprising.'
// })
// }
// module.exports = robot => {
// robot.on('issues.opened', context => {
// const params = context.issue({
// body: 'Hello World!'
// });
// context.github.issues.createComment(params);
// });
// };
// module.exports = robot => {
// robot.on('issues.opened', async context => {
// // `context` extracts information from the event, which can be passed to
// // GitHub API calls. This will return:
// // {owner: 'yourname', repo: 'yourrepo', number: 123, body: 'Hello World!}
// const params = context.issue({body: 'Hello World!'})
// console.log("Issue opened");
// // Post a comment on the issue
// return context.github.issues.createComment(params);
// });
// }