add check-merge-commit.yml #1
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Check for Merge Commits | |
on: | |
pull_request: | |
branches: main | |
jobs: | |
check-merge-commit: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out the repository | |
uses: actions/checkout@v4 | |
- name: Get all commit messages | |
id: get-commit-messages | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const pr = context.payload.pull_request; | |
const commits = await github.pulls.listCommits({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: pr.number, | |
per_page: 100 | |
}); | |
const commitMessages = commits.data.map(commit => commit.commit.message); | |
const hasMergeCommit = commitMessages.some(message => message.startsWith('Merge branch') || message.startsWith('Merge pull request')); | |
if (hasMergeCommit) { | |
core.setFailed('Pull request contains merge commit(s).'); | |
} | |
- name: Check for merge commits | |
if: failure() | |
run: echo "This pull request contains merge commit(s) and has been marked as failed." |