-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.js
73 lines (58 loc) · 2.09 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
const core = require('@actions/core');
const github = require('@actions/github');
const Config = require('./lib/config')
const Pull = require('./lib/pull');
const renderMessage = require('./lib/message');
async function run() {
try {
console.log(`action: ${github.context.payload.action}`);
console.log(`payload: ${JSON.stringify(github.context.payload)}`);
const config = new Config(core);
console.log(`config: ${JSON.stringify(config)}`);
const pull = new Pull(github.context.payload);
console.log(`pull: ${JSON.stringify(pull)}`);
const token = core.getInput('GITHUB_TOKEN');
const octokit = new github.GitHub(token);
const reviews = await octokit.pulls.listReviews({
owner: pull.owner,
repo: pull.repo,
pull_number: pull.pull_number
});
const checks = await octokit.checks.listForRef({
owner: pull.owner,
repo: pull.repo,
ref: pull.ref
});
pull.compileReviews(reviews);
pull.compileChecks(checks);
console.log(`merge: ${pull.canMerge(config)}`);
if (config.test_mode) {
// comment in test mode
await octokit.issues.createComment({
owner: pull.owner,
repo: pull.repo,
issue_number: pull.pull_number,
body: renderMessage(github.context.payload.action, config, pull)
});
} else {
if (pull.canMerge(config)) {
// merge the pull request
octokit.pulls.merge({
owner: pull.owner,
repo: pull.repo,
pull_number: pull.pull_number,
merge_method: config.merge_method
});
// delete the branch
octokit.git.deleteRef({
owner: pull.owner,
repo: pull.repo,
ref: pull.ref
});
}
}
} catch (error) {
core.setFailed(error.message);
}
}
run();