From fc8dc483a7fed9ccaa71b0cdf90793a53a452596 Mon Sep 17 00:00:00 2001 From: Epica3055 Date: Tue, 20 May 2025 18:15:53 +0800 Subject: [PATCH 1/2] add workflow Block PRs with "NO-MERGE" label --- .../block-PR-with-no-merge-label.yml | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/block-PR-with-no-merge-label.yml diff --git a/.github/workflows/block-PR-with-no-merge-label.yml b/.github/workflows/block-PR-with-no-merge-label.yml new file mode 100644 index 00000000000..1cc14656db4 --- /dev/null +++ b/.github/workflows/block-PR-with-no-merge-label.yml @@ -0,0 +1,26 @@ +# .github/workflows/block-no-merge-label.yml +name: Block PRs with "NO-MERGE" label + +on: + pull_request: + types: [labeled, unlabeled, synchronize, opened, reopened] + +jobs: + check-label: + runs-on: ubuntu-latest + steps: + - name: Check for "NO-MERGE" label + uses: actions/github-script@v7 + with: + script: | + const labels = await github.rest.issues.listLabelsOnIssue({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number + }); + + const hasNoMerge = labels.data.some(label => contains(label.name, 'NO-MERGE')); + + if (hasNoMerge) { + core.setFailed('This pull request has a "NO-MERGE" label.'); + } \ No newline at end of file From 21fa28193f3993c4e7dfd7291bbfc4361cc5a205 Mon Sep 17 00:00:00 2001 From: Epica3055 Date: Wed, 21 May 2025 09:39:45 +0800 Subject: [PATCH 2/2] update yml --- .github/workflows/block-PR-with-no-merge-label.yml | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/.github/workflows/block-PR-with-no-merge-label.yml b/.github/workflows/block-PR-with-no-merge-label.yml index 1cc14656db4..563cf905147 100644 --- a/.github/workflows/block-PR-with-no-merge-label.yml +++ b/.github/workflows/block-PR-with-no-merge-label.yml @@ -13,14 +13,7 @@ jobs: uses: actions/github-script@v7 with: script: | - const labels = await github.rest.issues.listLabelsOnIssue({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.issue.number - }); - - const hasNoMerge = labels.data.some(label => contains(label.name, 'NO-MERGE')); - - if (hasNoMerge) { - core.setFailed('This pull request has a "NO-MERGE" label.'); + const labels = context.payload.pull_request.labels.map(label => label.name); + if (labels.includes("NO-MERGE")) { + core.setFailed("This pull request has a NO-MERGE label and cannot be merged."); } \ No newline at end of file