Skip to content

Commit

Permalink
Merge pull request #111 from Staffbase/do-not-merge-action
Browse files Browse the repository at this point in the history
✨ Add "Do not Merge" Workflow
  • Loading branch information
0x46616c6b committed Apr 25, 2024
2 parents 62f7304 + 551b37b commit d977ad9
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/template_merge_block.yml
@@ -0,0 +1,55 @@
name: Do Not Merge

on:
workflow_call:
inputs:
label:
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

steps:
- name: Find Comment
if: inputs.comment
uses: peter-evans/find-comment@v3.1.0
id: comment
with:
issue-number: ${{ github.event.pull_request.number }}
body-includes: ⚠️ **This Pull Request is not ready to be merged.**

- 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: |
⚠️ **This Pull Request is not ready to be merged.**
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 }}'."
exit 1
24 changes: 24 additions & 0 deletions README.md
Expand Up @@ -231,6 +231,30 @@ jobs:

</details>

### Merge Block

<details>
<summary>The action can be used to block the merge if a do not merge label is set.</summary>

```yml
name: Merge Block

on:
pull_request:
types: [opened, labeled, unlabeled]

jobs:
block:
uses: Staffbase/gha-workflows/.github/workflows/template_merge_block.yml@v5.2.0
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: false
```

</details>

### Release Drafter

<details>
Expand Down

0 comments on commit d977ad9

Please sign in to comment.