Skip to content

Commit 277c230

Browse files
authored
feat: Add ignoreLabels option to opt-out of validation for certain PRs (#174)
1 parent 1ec37d3 commit 277c230

File tree

5 files changed

+59
-2
lines changed

5 files changed

+59
-2
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: 'Lint PR title preview (current branch, ignoreLabels enabled)'
2+
on:
3+
pull_request:
4+
types:
5+
- opened
6+
- edited
7+
- synchronize
8+
- labeled
9+
- unlabeled
10+
11+
jobs:
12+
main:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
- uses: actions/setup-node@v2
17+
with:
18+
node-version: 16
19+
- run: yarn install
20+
- run: yarn build
21+
- uses: ./
22+
env:
23+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24+
with:
25+
ignoreLabels: |
26+
bot
27+
ignore-semantic-pull-request

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ The action works without configuration, however you can provide options for cust
8282
validateSingleCommitMatchesPrTitle: true
8383
# If you use GitHub Enterprise, you can set this to the URL of your server
8484
githubBaseUrl: https://github.myorg.com/api/v3
85+
# If the PR contains one of these labels, the validation is skipped.
86+
# Multiple labels can be separated by newlines.
87+
# If you want to rerun the validation when labels change, you might want
88+
# to use the `labeled` and `unlabeled` event triggers in your workflow.
89+
ignoreLabels: |
90+
bot
91+
ignore-semantic-pull-request
8592
```
8693
8794
## Event triggers

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ inputs:
3535
githubBaseUrl:
3636
description: "If you use Github Enterprise, you can set this to the URL of your server (e.g. https://github.myorg.com/api/v3)"
3737
required: false
38+
ignoreLabels:
39+
description: "If the PR contains one of these labels, the validation is skipped. Multiple labels can be separated by newlines. If you want to rerun the validation when labels change, you might want to use the `labeled` and `unlabeled` event triggers in your workflow."
40+
required: false

src/index.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ module.exports = async function run() {
1414
subjectPatternError,
1515
validateSingleCommit,
1616
validateSingleCommitMatchesPrTitle,
17-
githubBaseUrl
17+
githubBaseUrl,
18+
ignoreLabels
1819
} = parseConfig();
1920

2021
const client = github.getOctokit(process.env.GITHUB_TOKEN, {
@@ -41,6 +42,19 @@ module.exports = async function run() {
4142
pull_number: contextPullRequest.number
4243
});
4344

45+
// Ignore errors if specified labels are added.
46+
if (ignoreLabels) {
47+
const labelNames = pullRequest.labels.map((label) => label.name);
48+
for (const labelName of labelNames) {
49+
if (ignoreLabels.includes(labelName)) {
50+
core.info(
51+
`Validation was skipped because the PR label "${labelName}" was found.`
52+
);
53+
return;
54+
}
55+
}
56+
}
57+
4458
// Pull requests that start with "[WIP] " are excluded from the check.
4559
const isWip = wip && /^\[WIP\]\s/.test(pullRequest.title);
4660

src/parseConfig.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ module.exports = function parseConfig() {
5252
githubBaseUrl = ConfigParser.parseString(process.env.INPUT_GITHUBBASEURL);
5353
}
5454

55+
let ignoreLabels;
56+
if (process.env.INPUT_IGNORELABELS) {
57+
ignoreLabels = ConfigParser.parseEnum(process.env.INPUT_IGNORELABELS);
58+
}
59+
5560
return {
5661
types,
5762
scopes,
@@ -61,6 +66,7 @@ module.exports = function parseConfig() {
6166
subjectPatternError,
6267
validateSingleCommit,
6368
validateSingleCommitMatchesPrTitle,
64-
githubBaseUrl
69+
githubBaseUrl,
70+
ignoreLabels
6571
};
6672
};

0 commit comments

Comments
 (0)