forked from xt0rted/block-autosquash-commits-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pullRequestChecker.js
37 lines (29 loc) · 1021 Bytes
/
pullRequestChecker.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
const { debug, error } = require("@actions/core");
const {
context,
getOctokit,
} = require("@actions/github");
class PullRequestChecker {
constructor(repoToken) {
this.client = getOctokit(repoToken);
}
async process() {
const commits = await this.client.rest.pulls.listCommits({
...context.repo,
pull_number: context.issue.number,
});
debug(`${commits.data.length} commit(s) in the pull request`);
let blockedCommits = 0;
for (const commit of commits.data) {
const isAutosquash = commit.commit.message.startsWith("fixup!") || commit.commit.message.startsWith("squash!");
if (isAutosquash) {
error(`Commit ${commit.sha} is an autosquash commit: ${commit.url}`);
blockedCommits++;
}
}
if (blockedCommits) {
throw Error(`${blockedCommits} commit(s) need to be squashed`);
}
}
}
module.exports = PullRequestChecker;