-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
113 lines (96 loc) · 4.46 KB
/
index.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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Checks API example
// See: https://developer.github.com/v3/checks/ to learn more
/**
* This is the main entrypoint to your Probot app
* @param {import('probot').Application} app
*/
module.exports = app => {
app.on('pull_request.opened', check)
async function check(context) {
const https = require('https');
const fetch = require('node-fetch');
const headers = {
"User-Agent": "Chinmay-KB"
};
const insult_api = 'https://evilinsult.com/generate_insult.php?lang=en&type=json';
const issues_api_prefix = 'https://api.github.com/repos/';
const issues_api_suffix = '/issues?state=open'
const pr = context.payload.pull_request;
const repo = context.payload.repository.full_name;
const pr_number = pr.number;
const sender = pr.user.login;
const semi_url = '/repos/' + pr + issues_api_suffix;
const issues_url = issues_api_prefix + repo + issues_api_suffix;
let flag = true;
let insult = '';
fetch(issues_url).then((res) => res.json()).then((data) => {
for (var i = 0; i < data.length; i++) {
var issue = data[i];
if (issue['assignees'] != null) {
if (issue['assignees'].length != 0) {
for (var j = 0; j < issue['assignees'].length; j++) {
if (issue['assignees'][j]['login'] == sender) {
flag = false;
break;
}
}
}
}
}
fetch(insult_api).then((res) => res.json()).then((data) => {
insult = data['insult'];
context.log.info(insult);
const params = context.issue({ body: '*' + insult + '*' + '\n Congratulations to @' + sender + ' towards his contribution to spamtoberfest!! ' });
flag = context.isBot ? false : flag;
if (flag) { //TODO: Change to new implementation
context.github.issues.addLabels(context.issue({
labels: ['spam', 'spamtoberfest', 'invalid', 'spamprbot-reject']
}));
context.github.issues.createComment(params);
} else {
context.github.issues.createComment(context.issue({ body: "This pull request seems genuine" }));
context.github.issues.addLabels(context.issue({
labels: ['spamprbot-approved']
}));
}
});
});
// https.request(options, (resp) => {
// let data = '';
// resp.on('data', (chunk) => {
// data += chunk;
// });
// // The whole response has been received. Print out the result.
// resp.on('end', () => {
// context.log.info(data);
// for (var i = 0; i < data.length; i++) {
// var issue = data[i];
// if (issue['assignees'] != null) {
// if (issue['assignees'].length != 0) {
// for (var j = 0; j < issue['assignees'].length; j++) {
// if (issue['assignees'][j]['login'] == sender) {
// flag = false;
// break;
// }
// }
// }
// }
// }
// const params = context.issue({ body: 'Congratulations to @' + sender + ' towards his contribution to spamtoberfest!! ' });
// if (flag) { //TODO: Change to new implementation
// context.github.issues.addLabels(context.issue({
// labels: ['spam', 'spamtoberfest']
// }));
// // context.github.issues.createComment(params);
// } else
// context.github.issues.createComment(context.issue({ body: "This pull request seems genuine" }));
// });
// }).on("error", (err) => {
// console.log("Error: " + err.message);
// });
// For more information on building apps:
// https://probot.github.io/docs/
// To get your app running against GitHub, see:
// https://probot.github.io/docs/development/
}
}