forked from xt0rted/block-autosquash-commits-action
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpullRequestChecker.js
41 lines (33 loc) · 1.03 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 { sha, url, parents } of commits) {
const isMergeCommit = parents.length > 1;
if (isMergeCommit) {
error(`Commit ${sha} is an merge commit: ${url}`);
blockedCommits++;
}
}
if (blockedCommits) {
throw Error(`${blockedCommits} commit(s) cannot be merged`);
}
}
}
module.exports = PullRequestChecker;