-
Notifications
You must be signed in to change notification settings - Fork 15
53 lines (47 loc) · 1.93 KB
/
check-merge-commit.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# moon: The build system and package manager for MoonBit.
# Copyright (C) 2024 International Digital Economy Academy
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# For inquiries, you can contact us via e-mail at [email protected].
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 prNumber = context.payload.pull_request.number;
const commits = await github.rest.pulls.listCommits({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
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."