From a40ce1fce39f3016cb45d832ccafcb127a5874be Mon Sep 17 00:00:00 2001 From: Falk Scheerschmidt Date: Thu, 25 Apr 2024 11:54:42 +0200 Subject: [PATCH] Add comment for merge block workflow --- .github/workflows/template_merge_block.yml | 40 +++++++++++++++++++--- README.md | 3 ++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/.github/workflows/template_merge_block.yml b/.github/workflows/template_merge_block.yml index 3b413f49..ab264b5c 100644 --- a/.github/workflows/template_merge_block.yml +++ b/.github/workflows/template_merge_block.yml @@ -7,18 +7,48 @@ on: required: false type: string default: do not merge + comment: + required: false + type: boolean + default: true jobs: do-not-merge: - name: Check runs-on: ubuntu-22.04 - # contains(search, item) is not case-sensitive - # Therefore 'Do Not Merge' and 'DO NOT MERGE' will also match - # see https://docs.github.com/en/actions/learn-github-actions/expressions#contains steps: - - name: fail if label exists + - name: Find Comment + if: ${{ inputs.comment }} && contains(github.event.pull_request.labels.*.name, inputs.label) + uses: peter-evans/find-comment@v3.1.0 + id: comment + with: + issue-number: ${{ github.event.pull_request.number }} + body-includes: The merge is blocked. Remove the label '${{ inputs.label }}' to proceed. + + - name: Comment on PR + if: ${{ inputs.comment }} && contains(github.event.pull_request.labels.*.name, inputs.label) && steps.comment.outputs.comment-id == '' + uses: peter-evans/create-or-update-comment@v4.0.0 + with: + issue-number: ${{ github.event.pull_request.number }} + body: | + ⚠️ **The merge is blocked.** + + Remove the label '${{ inputs.label }}' to proceed. + + - name: Delete Comment + if: ${{ inputs.comment }} && !contains(github.event.pull_request.labels.*.name, inputs.label) && steps.comment.outputs.comment-id != '' + uses: actions/github-script@v7.0.1 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + github.rest.issues.deleteComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: ${{ steps.comment.outputs.comment-id }} + }) + + - name: Fail if label exists to block merge if: contains(github.event.pull_request.labels.*.name, inputs.label) run: | echo "This PR has the label '${{ inputs.label }}'." diff --git a/README.md b/README.md index abe8349a..096a6e81 100644 --- a/README.md +++ b/README.md @@ -249,7 +249,10 @@ jobs: with: # optional: name of the label if the PR should not be merged, default: do not merge label: merge block + # optional: comment when the PR is blocked, default: true + comment: true ``` + ### Release Drafter