-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
34 lines (25 loc) · 1.1 KB
/
app.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
const core = require('@actions/core');
const github = require('@actions/github');
const conventionalCommitsParser = require('conventional-commits-parser');
try {
const allowedPullRequestTypesInputKey = 'allowed-pull-request-types';
let allowedPullRequestTypes = core
.getInput(allowedPullRequestTypesInputKey, { required: true })
.trim()
.split(',');
const pullRequestContext = github.context.payload.pull_request;
if (!pullRequestContext) {
throw new Error(`This action can only be invoked in 'pull_request' events. Otherwise the pull request can't be inferred.`);
}
const { header, type } = conventionalCommitsParser.sync(pullRequestContext.title);
core.notice(`Inspecting pull request title '${header}'.`);
if (!type) {
throw new Error(`No commit type found in pull request title '${header}'.`);
}
if (!allowedPullRequestTypes.includes(type)) {
throw new Error(`Invalid commit type '${type}' found in pull request title '${header}', please use one of ${allowedPullRequestTypes}.`);
}
core.notice('Success.');
} catch (error) {
core.setFailed(error.message);
}