This repository has been archived by the owner on May 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
65 lines (54 loc) · 1.79 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
const core = require('@actions/core');
const { parseUpdateType, isUpdateTypeAllowed } = require('./update-type');
const { context, getOctokit } = require('@actions/github');
async function main() {
const token = core.getInput('github-token', { required: true });
const updateType = core.getInput('update-type');
if (context.eventName !== 'pull_request') {
core.error('Not detected as a pull request, skipping.');
return;
}
const github = getOctokit(token, {
log: console,
});
core.info('Getting pull request...');
const { data: pr } = await github.issues.get({
...context.repo,
issue_number: context.payload.pull_request.number,
});
if (!['dependabot[bot]', 'dependabot-preview[bot]'].includes(pr.user.login)) {
core.error('Pull request is not from Dependabot, skipping.');
return;
}
if (updateType === 'all') {
core.info('All updates ');
} else {
const actualUpdateType = parseUpdateType(pr.body);
core.info(`Detected update type "${actualUpdateType}".`);
if (isUpdateTypeAllowed(updateType, actualUpdateType)) {
core.info('The update type is allowed!');
} else {
core.error('The update type is NOT allowed, skipping.');
return;
}
}
core.info(`Approving pull request #${pr.number}"...`);
await github.pulls.createReview({
...context.repo,
pull_number: pr.number,
event: 'APPROVE',
});
core.info(`Approved pull request #${pr.number}"!`);
core.info(`Merging pull request "#${pr.number}"...`);
await github.pulls.merge({
...context.repo,
pull_number: pr.number,
});
core.info(`Merged pull request "#${pr.number}"!`);
}
process.on('unhandledRejection', handleError);
main().catch(handleError);
function handleError(err) {
console.error(err);
core.setFailed(`Unhandled error: ${err}`);
}