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
25 changes: 25 additions & 0 deletions .github/workflows/lint-pr-title-preview-ignoreLabels.yml
@@ -0,0 +1,25 @@
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

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
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -82,6 +82,8 @@ 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
ignoreLabels: |
bot
kenji-miyake marked this conversation as resolved.
Show resolved Hide resolved
```

## 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 specified labels are added to a PR, you can ignore the validation result. It is useful for PRs created by bots."
kenji-miyake marked this conversation as resolved.
Show resolved Hide resolved
required: false
15 changes: 14 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 Down Expand Up @@ -115,6 +116,18 @@ module.exports = async function run() {
}
}

// Ignore errors if specified labels are added.
if (ignoreLabels && validationError) {
const label_names = pullRequest.labels.map((label) => label.name);
kenji-miyake marked this conversation as resolved.
Show resolved Hide resolved
if (label_names.some((label_name) => ignoreLabels.includes(label_name))) {
core.info(
`The validation error was ignored because one of the PR label [${label_names}] was in [${ignoreLabels}].`
kenji-miyake marked this conversation as resolved.
Show resolved Hide resolved
);
core.info(`The ignored error message is: ${validationError}`);
amannn marked this conversation as resolved.
Show resolved Hide resolved
validationError = null;
}
}
kenji-miyake marked this conversation as resolved.
Show resolved Hide resolved

if (wip) {
const newStatus =
isWip || validationError != null ? 'pending' : 'success';
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
};
};