Skip to content

Commit

Permalink
feat: add ignoreLabels option to force ignore errors
Browse files Browse the repository at this point in the history
Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>
  • Loading branch information
Kenji Miyake committed Apr 11, 2022
1 parent 1ec37d3 commit 6c82aeb
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 2 deletions.
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

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
```

## 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 specified labels are added to a PR, you can ignore the validation result. It is useful for PRs created by bots."
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);
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}].`
);
core.info(`The ignored error message is: ${validationError}`);
validationError = null;
}
}

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
};
};

0 comments on commit 6c82aeb

Please sign in to comment.