Skip to content

add check-merge-commit.yml #1

add check-merge-commit.yml

add check-merge-commit.yml #1

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."