Skip to content

Commit

Permalink
Fail action if PR is unprioritized (#15)
Browse files Browse the repository at this point in the history
Signed-off-by: David Greven <[email protected]>
  • Loading branch information
grevend authored Sep 27, 2022
1 parent 7a88a21 commit 109d0b4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
must-have-label | Label to expect on essential PRs | `must have`
fail-if-missing-label | Unprioritized PRs should fail the action | `true`
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
11 changes: 8 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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)
Expand Down

0 comments on commit 109d0b4

Please sign in to comment.