Skip to content

Commit

Permalink
add check-merge-commit.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
lijunchen committed Jul 23, 2024
1 parent 9959496 commit 57c9d69
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/check-merge-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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."

0 comments on commit 57c9d69

Please sign in to comment.