Skip to content

Commit

Permalink
refactor: use early exit
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 12, 2022
1 parent 6763b3e commit 2ad53de
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/index.js
Expand Up @@ -42,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 Expand Up @@ -116,20 +129,6 @@ module.exports = async function run() {
}
}

// Ignore errors if specified labels are added.
if (ignoreLabels && validationError) {
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.`
);
validationError = null;
break;
}
}
}

if (wip) {
const newStatus =
isWip || validationError != null ? 'pending' : 'success';
Expand Down

0 comments on commit 2ad53de

Please sign in to comment.