forked from nus-cs2103/nus-se-pr-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
73 lines (60 loc) · 2.06 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
// Load dotenv first
require('dotenv').config({ silent: true });
const Promise = require('bluebird');
const SubmissionRepos = require('./src/Whitelist');
const Blacklisted = require('./src/Blacklist');
const Greylisted = require('./src/Greylist');
const Accuser = require('accuser');
const currentLevel = require('./config').currentLevel;
const semesterAccount = require('./config').semesterAccount;
const originAccount = require('./config').originAccount;
const maxLevel = 4;
// interval in miliseconds
// 10 min interval
const accuser = new Accuser({ interval: 600000 });
// Can pass optional argument to do a dry run that checks for required permissions
const isDryRun = process.argv.length > 2 && process.argv[2] === 'dry';
const runMethod = isDryRun ? 'dryCheck' : 'checkAndRun';
const githubAuthToken = {
type: 'oauth',
token: process.env.GITHUB_TOKEN
};
accuser.authenticate(githubAuthToken);
let repoPromises = [];
// Greylisted
for (let level = 1; level <= maxLevel; level += 1) {
const repo = new Greylisted(accuser, originAccount, `addressbook-level${level}`);
repoPromises.push(repo[runMethod]());
}
// Blacklisted
const blackListedOriginRepos = [
'samplerepo-pr-practice',
'samplerepo-workflow-practice',
'samplerepo-things'
];
const blackListedSemesterRepos = [
'samplerepo-pr-practice',
'samplerepo-things'
];
blackListedOriginRepos.forEach(repoName => {
const repo = new Blacklisted(accuser, originAccount, repoName);
repoPromises.push(repo[runMethod]());
});
blackListedSemesterRepos.forEach(repoName => {
const repo = new Blacklisted(accuser, semesterAccount, repoName);
repoPromises.push(repo[runMethod]());
});
// Whitelisted
for (let level = 1; level <= currentLevel; level += 1) {
const repo = new SubmissionRepos(accuser, semesterAccount, `addressbook-level${level}`);
repoPromises.push(repo[runMethod]());
}
Promise.all(repoPromises).then(() => {
if (!isDryRun) {
// start the bot
console.log('Bot Service has started');
accuser.run({ assignee: 'none' });
}
}, () => {
console.log('Not all permissions are satisfied :-)');
});