This repository has been archived by the owner on Jun 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
69 lines (57 loc) · 2.04 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
const defaultsShape = {
message: 'string',
whitelistedTeamID: 'number'
};
function checkForDefaults(defaults) {
const errors = Object.keys(defaultsShape).filter(key => !Object.prototype.hasOwnProperty.call(defaults, key));
if (errors.length > 0) errors.forEach(err => console.error(`Key \`${err}\` of type \`${defaultsShape[err]}\` is missing.`));
}
/**
* @typedef {Object} Config
* @prop {string} message
*
* Anytime a user merges a pull request, they are reminded to delete their branch.
* @param {Object} robot
* @param {Config} defaults
* @param {String} [configFilename]
*/
module.exports = (robot, defaults = {message: "Uh oh! You closed an issue or pull request that you didn't author. Please leave these open for the original author so that they may get the benefit of completing the learning process on their own. Thanks :v:", "whitelistedTeamID" : 239461}, configFilename = 'reopen-closed-issues.yml') => {
checkForDefaults(defaults);
robot.on('issues.closed', checkReopen)
async function checkReopen (context) {
const {issue, sender} = context.payload;
const closer = sender.login;
const author = issue.user.login;
let config;
try {
const {reopenClosedIssues} = await context.config(configFilename);
config = Object.assign({}, defaults, reopenClosedIssues);
} catch (err) {
config = defaults;
}
try {
await context.github.orgs.getTeamMembership( context.repo ({
id: config.whitelistedTeamID,
username: closer
}))
robot.log(`${closer} is a team member`)
} catch (err) {
robot.log(`${closer} is NOT a team member`)
if( closer != author )
{
context.github.issues.createComment(context.repo({
number: issue.number,
body: config.message
}));
return context.github.issues.edit(context.repo({
number: issue.number,
state: "open",
}));
}
else {
return;
}
}
}
console.log('Yay, the teacher-bot/reopen-closed-issues plugin was loaded!');
};