-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (32 loc) · 1.27 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
const core = require('@actions/core');
const { Toolkit } = require('actions-toolkit');
Toolkit.run(
async tools => {
const repository = tools.context.payload.repository;
const number = tools.context.payload.number;
const commitMessageRegex = core.getInput('commitMessageRegex');
tools.log('Using regex: ' + commitMessageRegex);
const params = {
owner: repository.owner.login,
repo: repository.name,
pull_number: number
}
const commits = (await tools.github.pulls.listCommits(params)).data;
// Check for invalid commit messages
var containInvalidCommitMessage = false;
const regex = new RegExp(commitMessageRegex)
commits.forEach(commit => {
const message = commit.commit.message;
if(!message.match(regex)) {
containInvalidCommitMessage = true;
tools.log('Invalid commit: ' + message);
}
});
if (containInvalidCommitMessage) {
tools.exit.failure("Invalid commits");
} else {
tools.exit.success();
}
},
{ event: ['pull_request.opened', 'pull_request.edited', 'pull_request.synchronize'], secrets: ['GITHUB_TOKEN'] }
)