-
Notifications
You must be signed in to change notification settings - Fork 6
39 lines (35 loc) · 1.41 KB
/
check-commit-count.yml
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
name: CI
on:
pull_request:
types: [opened, synchronize]
jobs:
check-commits:
runs-on: ubuntu-latest
steps:
- name: Check number of commits in PR
id: commits
uses: actions/github-script@v6
with:
script: |
const payload = await github.rest.pulls.listCommits({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
return payload.data.length;
- name: Post comment if commits are fewer than 2
if: steps.commits.outputs.result < 2
uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: 'This pull request does not contain the minimum required number of commits (2). Please add more commits.'
});
- name: Fail the job if fewer than 2 commits
if: steps.commits.outputs.result < 2
run: |
echo "Failing the job because there are fewer than 2 commits."
exit 1