File tree Expand file tree Collapse file tree 3 files changed +79
-0
lines changed
Expand file tree Collapse file tree 3 files changed +79
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * Fails the workflow if any of the specified labels are present on the PR.
3+ *
4+ * Inputs (via environment):
5+ * FAIL_LABELS: comma-separated list of labels to check (default: "do-not-merge")
6+ */
7+
8+ module . exports = async ( { context, core } ) => {
9+ const failLabels = ( process . env . FAIL_LABELS || "do-not-merge" )
10+ . split ( "," )
11+ . map ( ( l ) => l . trim ( ) . toLowerCase ( ) )
12+ . filter ( Boolean ) ;
13+
14+ const pr = context . payload . pull_request ;
15+ if ( ! pr ) {
16+ core . info ( "This action is only applicable to pull requests." ) ;
17+ return ;
18+ }
19+
20+ const prLabels = ( pr . labels || [ ] ) . map ( ( l ) => l . name . toLowerCase ( ) ) ;
21+ const found = failLabels . find ( ( label ) => prLabels . includes ( label ) ) ;
22+
23+ if ( found ) {
24+ const msg = `❌ This PR has a label that blocks merging: \`${ found } \`.\nPlease remove the label to proceed.` ;
25+ core . summary . addRaw ( msg ) ;
26+ core . setFailed ( msg ) ;
27+ return ;
28+ }
29+
30+ core . info ( `No blocking labels found. Blocking labels checked: [${ failLabels . join ( ", " ) } ]` ) ;
31+ } ;
Original file line number Diff line number Diff line change 1+ # ##
2+ # This workflow fails if a PR has a blocking label (e.g., "do-not-merge").
3+ #
4+ # To customize blocking labels, set the FAIL_LABELS variable (comma-separated).
5+ # Default: "do-not-merge"
6+ #
7+ # To set the variable, you can use the GitHub CLI:
8+ # gh variable set FAIL_LABELS --body "do-not-merge,dnm"
9+ # ##
10+
11+ name : Do Not Merge Blocker
12+
13+ on :
14+ pull_request :
15+ types : [opened, labeled, unlabeled]
16+ merge_group :
17+
18+ permissions : {}
19+
20+ jobs :
21+ do-not-merge-block :
22+ name : Do Not Merge Block
23+ runs-on : ubuntu-latest
24+ timeout-minutes : 5
25+ permissions :
26+ contents : read
27+ # Skip on merge group events
28+ if : ${{ github.event_name == 'pull_request' }}
29+ steps :
30+ - uses : actions/checkout@v4
31+
32+ - name : Fail if blocking label present
33+ uses : actions/github-script@v7
34+ env :
35+ FAIL_LABELS : ${{ vars.DO_NOT_MERGE_LABELS || 'do-not-merge' }}
36+ with :
37+ script : |
38+ const script = require('./.github/scripts/do-not-merge-block.js');
39+ await script({ context, core });
Original file line number Diff line number Diff line change 1+ {
2+ "bracketSpacing": true,
3+ "printWidth": 120,
4+ "proseWrap": "always",
5+ "singleQuote": false,
6+ "tabWidth": 2,
7+ "trailingComma": "all",
8+ "useTabs": false
9+ }
You can’t perform that action at this time.
0 commit comments