Skip to content

Checking commit messages on branch refs/pull/2139/merge #95

Checking commit messages on branch refs/pull/2139/merge

Checking commit messages on branch refs/pull/2139/merge #95

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).`);
}