-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathpullRequestChecker.js
41 lines (33 loc) · 1.09 KB
/
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
38
39
40
41
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.paginate(
"GET /repos/{owner}/{repo}/pulls/{pull_number}/commits",
{
...context.repo,
pull_number: context.issue.number,
per_page: 100,
},
);
debug(`${commits.length} commit(s) in the pull request`);
let blockedCommits = 0;
for (const { commit: { message }, sha, url } of commits) {
const isAutosquash = message.startsWith("fixup!") || message.startsWith("squash!");
if (isAutosquash) {
error(`Commit ${sha} is an autosquash commit: ${url}`);
blockedCommits++;
}
}
if (blockedCommits) {
throw Error(`${blockedCommits} commit(s) need to be squashed`);
}
}
}
module.exports = PullRequestChecker;