Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ignoreLabels option to force ignore errors #174

Merged
merged 12 commits into from Apr 13, 2022
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
kenji-miyake marked this conversation as resolved.
Show resolved Hide resolved
- 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
kenji-miyake marked this conversation as resolved.
Show resolved Hide resolved
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:
kenji-miyake marked this conversation as resolved.
Show resolved Hide resolved
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
};
};