Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/scripts/do-not-merge-block.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Fails the workflow if any of the specified labels are present on the PR.
*
* Inputs (via environment):
* FAIL_LABELS: comma-separated list of labels to check (default: "do-not-merge")
*/

module.exports = async ({ context, core }) => {
const failLabels = (process.env.FAIL_LABELS || "do-not-merge")
.split(",")
.map((l) => l.trim().toLowerCase())
.filter(Boolean);

const pr = context.payload.pull_request;
if (!pr) {
core.info("This action is only applicable to pull requests.");
return;
}

const prLabels = (pr.labels || []).map((l) => l.name.toLowerCase());
const found = failLabels.find((label) => prLabels.includes(label));

if (found) {
const msg = `❌ This PR has a label that blocks merging: \`${found}\`.\nPlease remove the label to proceed.`;
core.summary.addRaw(msg);
core.setFailed(msg);
return;
}

core.info(`No blocking labels found. Blocking labels checked: [${failLabels.join(", ")}]`);
};
39 changes: 39 additions & 0 deletions .github/workflows/do-not-merge-block.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
###
# This workflow fails if a PR has a blocking label (e.g., "do-not-merge").
#
# To customize blocking labels, set the FAIL_LABELS variable (comma-separated).
# Default: "do-not-merge"
#
# To set the variable, you can use the GitHub CLI:
# gh variable set FAIL_LABELS --body "do-not-merge,dnm"
###

name: Do Not Merge Blocker

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

permissions: {}

jobs:
do-not-merge-block:
name: Do Not Merge Block
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: read
# Skip on merge group events
if: ${{ github.event_name == 'pull_request' }}
steps:
- uses: actions/checkout@v4

- name: Fail if blocking label present
uses: actions/github-script@v7
env:
FAIL_LABELS: ${{ vars.DO_NOT_MERGE_LABELS || 'do-not-merge' }}
with:
script: |
const script = require('./.github/scripts/do-not-merge-block.js');
await script({ context, core });
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"bracketSpacing": true,
"printWidth": 120,
"proseWrap": "always",
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "all",
"useTabs": false
}