-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathindex.js
57 lines (50 loc) · 1.24 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
/**
* GitHub dependencies
*/
const { setFailed, getInput } = require( '@actions/core' );
const { context, GitHub } = require( '@actions/github' );
/**
* Internal dependencies
*/
const assignFixedIssues = require( './assign-fixed-issues' );
const addFirstTimeContributorLabel = require( './add-first-time-contributor-label' );
const addMilestone = require( './add-milestone' );
const debug = require( './debug' );
const automations = [
{
event: 'pull_request',
action: 'opened',
task: assignFixedIssues,
},
{
event: 'pull_request',
action: 'opened',
task: addFirstTimeContributorLabel,
},
{
event: 'pull_request',
action: 'closed',
task: addMilestone,
},
];
( async function main() {
const token = getInput( 'github_token' );
if ( ! token ) {
setFailed( 'main: Input `github_token` is required' );
return;
}
const octokit = new GitHub( token );
debug(
`main: Received event = '${ context.eventName }', action = '${ context.payload.action }'`
);
for ( const { event, action, task } of automations ) {
if (
event === context.eventName &&
action === context.payload.action
) {
debug( `main: Starting task ${ task.name }` );
await task( context.payload, octokit );
}
}
debug( 'main: All done!' );
} )();