Skip to content

Commit

Permalink
Add comment for merge block workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
0x46616c6b committed Apr 25, 2024
1 parent fd3811e commit a40ce1f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
40 changes: 35 additions & 5 deletions .github/workflows/template_merge_block.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}'."
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

</details>

### Release Drafter
Expand Down

0 comments on commit a40ce1f

Please sign in to comment.