Skip to content

Commit

Permalink
feat: Add ignoreLabels option to opt-out of validation for certain …
Browse files Browse the repository at this point in the history
…PRs (#174)
  • Loading branch information
kenji-miyake committed Apr 13, 2022
1 parent 1ec37d3 commit 277c230
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 2 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/lint-pr-title-preview-ignoreLabels.yml
@@ -0,0 +1,27 @@
name: 'Lint PR title preview (current branch, ignoreLabels enabled)'
on:
pull_request:
types:
- opened
- edited
- synchronize
- labeled
- unlabeled

jobs:
main:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
- run: yarn install
- run: yarn build
- uses: ./
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
ignoreLabels: |
bot
ignore-semantic-pull-request
7 changes: 7 additions & 0 deletions README.md
Expand Up @@ -82,6 +82,13 @@ The action works without configuration, however you can provide options for cust
validateSingleCommitMatchesPrTitle: true
# If you use GitHub Enterprise, you can set this to the URL of your server
githubBaseUrl: https://github.myorg.com/api/v3
# 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.
ignoreLabels: |
bot
ignore-semantic-pull-request
```

## Event triggers
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Expand Up @@ -35,3 +35,6 @@ inputs:
githubBaseUrl:
description: "If you use Github Enterprise, you can set this to the URL of your server (e.g. https://github.myorg.com/api/v3)"
required: false
ignoreLabels:
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."
required: false
16 changes: 15 additions & 1 deletion src/index.js
Expand Up @@ -14,7 +14,8 @@ module.exports = async function run() {
subjectPatternError,
validateSingleCommit,
validateSingleCommitMatchesPrTitle,
githubBaseUrl
githubBaseUrl,
ignoreLabels
} = parseConfig();

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

// Ignore errors if specified labels are added.
if (ignoreLabels) {
const labelNames = pullRequest.labels.map((label) => label.name);
for (const labelName of labelNames) {
if (ignoreLabels.includes(labelName)) {
core.info(
`Validation was skipped because the PR label "${labelName}" was found.`
);
return;
}
}
}

// Pull requests that start with "[WIP] " are excluded from the check.
const isWip = wip && /^\[WIP\]\s/.test(pullRequest.title);

Expand Down
8 changes: 7 additions & 1 deletion src/parseConfig.js
Expand Up @@ -52,6 +52,11 @@ module.exports = function parseConfig() {
githubBaseUrl = ConfigParser.parseString(process.env.INPUT_GITHUBBASEURL);
}

let ignoreLabels;
if (process.env.INPUT_IGNORELABELS) {
ignoreLabels = ConfigParser.parseEnum(process.env.INPUT_IGNORELABELS);
}

return {
types,
scopes,
Expand All @@ -61,6 +66,7 @@ module.exports = function parseConfig() {
subjectPatternError,
validateSingleCommit,
validateSingleCommitMatchesPrTitle,
githubBaseUrl
githubBaseUrl,
ignoreLabels
};
};

0 comments on commit 277c230

Please sign in to comment.