From 109d0b4dd624ea0ae0cddfdb4647c1be0d3b7245 Mon Sep 17 00:00:00 2001 From: David Greven Date: Tue, 27 Sep 2022 09:44:41 +0200 Subject: [PATCH] Fail action if PR is unprioritized (#15) Signed-off-by: David Greven --- README.md | 3 ++- action.yml | 4 ++++ dist/index.js | 11 ++++++++--- src/action.ts | 8 ++++++-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 70ded3f..3ab30ae 100644 --- a/README.md +++ b/README.md @@ -39,4 +39,5 @@ token | The workflows `GITHUB_TOKEN` secret | wont-have-label | Label to expect on low-priority PRs | `wont have` could-have-label | Label to expect on PRs of little relevance | `could have` should-have-label | Label to expect on non-critical PRs | `should have` -must-have-label | Label to expect on essential PRs | `must have` \ No newline at end of file +must-have-label | Label to expect on essential PRs | `must have` +fail-if-missing-label | Unprioritized PRs should fail the action | `true` \ No newline at end of file diff --git a/action.yml b/action.yml index c38b2a6..aa44f47 100644 --- a/action.yml +++ b/action.yml @@ -26,6 +26,10 @@ inputs: description: 'Label to expect on essential PRs' required: false default: 'must have' + fail-if-missing-label: + description: 'Unprioritized PRs should fail the action' + required: false + default: 'true' runs: using: 'node16' diff --git a/dist/index.js b/dist/index.js index 2349043..327ffee 100644 --- a/dist/index.js +++ b/dist/index.js @@ -44,7 +44,8 @@ Could Have | Of little relevance and is only taken into account if there is stil Won't Have (this time) | Low priority for the current planning stage but will be prioritized again for the next release. `; const complete = 'Excellent, the MoSCoW prioritization is finished! :label:'; -const labels = [core.getInput('wont-have-label', { required: false }), core.getInput('could-have-label', { required: false }), core.getInput('should-have-label', { required: false }), core.getInput('must-have-label', { required: false })]; +const labels = [core.getInput('wont-have-label'), core.getInput('could-have-label'), core.getInput('should-have-label'), core.getInput('must-have-label')]; +const fails = core.getInput('fail-if-missing-label') === 'true'; const token = core.getInput('token', { required: true }); const octo = gh.getOctokit(token); (async function () { @@ -61,6 +62,9 @@ const octo = gh.getOctokit(token); await octo.rest.issues.createComment({ ...gh.context.repo, issue_number: prNum, body: exists ? complete : help }); + if (!exists && fails) { + core.setFailed('The associated pull request is currently unprioritized!'); + } } catch (error) { core.error(error); @@ -1145,8 +1149,9 @@ exports.context = new Context.Context(); * @param token the repo PAT or GITHUB_TOKEN * @param options other options to set */ -function getOctokit(token, options) { - return new utils_1.GitHub(utils_1.getOctokitOptions(token, options)); +function getOctokit(token, options, ...additionalPlugins) { + const GitHubWithPlugins = utils_1.GitHub.plugin(...additionalPlugins); + return new GitHubWithPlugins(utils_1.getOctokitOptions(token, options)); } exports.getOctokit = getOctokit; //# sourceMappingURL=github.js.map diff --git a/src/action.ts b/src/action.ts index dda1f21..8c673d1 100644 --- a/src/action.ts +++ b/src/action.ts @@ -14,8 +14,8 @@ Won't Have (this time) | Low priority for the current planning stage but will be ` const complete = 'Excellent, the MoSCoW prioritization is finished! :label:' -const labels = [core.getInput('wont-have-label', { required: false }), core.getInput('could-have-label', { required: false }), core.getInput('should-have-label', { required: false }), core.getInput('must-have-label', { required: false })] - +const labels = [core.getInput('wont-have-label'), core.getInput('could-have-label'), core.getInput('should-have-label'), core.getInput('must-have-label')] +const fails = core.getInput('fail-if-missing-label') === 'true' const token = core.getInput('token', { required: true }) const octo = gh.getOctokit(token); @@ -36,6 +36,10 @@ const octo = gh.getOctokit(token); await octo.rest.issues.createComment({ ...gh.context.repo, issue_number: prNum, body: exists ? complete : help }) + + if (!exists && fails) { + core.setFailed('The associated pull request is currently unprioritized!') + } } catch (error: any) { core.error(error) core.setFailed(error.message)