-
Notifications
You must be signed in to change notification settings - Fork 5
30 lines (27 loc) · 1.2 KB
/
commit-message-check.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
name: Check commit messages
run-name: Checking commit messages on branch ${{ github.ref }}
on:
pull_request: # run on every pull request
jobs:
check-commit-messages:
runs-on: ubuntu-latest
steps:
- name: Check commit messages
uses: actions/github-script@v7
with:
script: |
const commitPattern = /#[0-9]{4,5}/;
// Fetch and check each commit in the pull request
const commits = await github.paginate(github.rest.pulls.listCommits, {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number
});
const invalidCommits = commits.filter(commit => {
const message = commit.commit.message;
console.log(`Checking commit ${commit.sha}: ${message}`);
return !commitPattern.test(message);
});
if (invalidCommits.length > 0) {
core.setFailed(`Invalid commit messages in the following commits:\n${invalidCommits.map(commit => ` - ${commit.sha}: ${commit.commit.message}`).join('\n')}\nCommit messages must include a Tuleap ticket number (e.g., #12345).`);
}