Skip to content

Commit

Permalink
feat: #5 - Make filter-label optional
Browse files Browse the repository at this point in the history
  • Loading branch information
williamdes committed Feb 26, 2020
1 parent 7a7cfe9 commit 0fcd6f9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
5 changes: 3 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ inputs:
required: false
default: "^.*$"
filter-label:
description: "The label that will trigger the merge"
required: true
description: "The label that will trigger the merge, (empty or absent to disable the check)"
required: false
default: ""
merge-title:
description: "The merge title"
required: false
Expand Down
32 changes: 21 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const main = async () => {
required: false
});
const filter_label = core.getInput('filter-label', {
required: true
required: false
});
const merge_method = core.getInput('merge-method', {
required: false
Expand Down Expand Up @@ -48,11 +48,15 @@ const main = async () => {
core.info('The pull-request is open.');
}

if (pullRequest.data.labels.indexOf(filter_label) !== -1) {
core.warning('Ignored, the label does not exist on the pull-request.');
return;
if (filter_label.length > 0) {
if (pullRequest.data.labels.indexOf(filter_label) !== -1) {
core.warning('Ignored, the label does not exist on the pull-request.');
return;
} else {
core.info('Label matched.');
}
} else {
core.info('Label matched.');
core.info('Label check is disabled.');
}

if (merge_method === 'fast-forward') {
Expand Down Expand Up @@ -83,12 +87,18 @@ const main = async () => {
}
await octokit.pulls.merge(mergeData)
}
await octokit.issues.removeLabel({
...context.repo,
...context.owner,
issue_number: number,
name: filter_label
});
if (filter_label.length > 0) {
try {
await octokit.issues.removeLabel({
...context.repo,
...context.owner,
issue_number: number,
name: filter_label
});
} catch (error) {
core.warning(error.message || 'Removing the label could have failed.');
}
}
}

main().catch(err => core.setFailed(err.message))

0 comments on commit 0fcd6f9

Please sign in to comment.