Skip to content

Commit

Permalink
Add custom priority label support (#2)
Browse files Browse the repository at this point in the history
Signed-off-by: David Greven <[email protected]>
  • Loading branch information
grevend authored Sep 11, 2022
1 parent f0c8cec commit c75d66f
Show file tree
Hide file tree
Showing 12 changed files with 4,425 additions and 260 deletions.
18 changes: 18 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"env": {
"browser": true,
"es2021": true
},
"extends": "standard-with-typescript",
"rules": {
"@typescript-eslint/no-floating-promises": "off"
},
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module",
"project": "./tsconfig.json"
},
"ignorePatterns": [
"**/*.js"
]
}
6 changes: 3 additions & 3 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: "CodeQL"
name: CodeQL

on:
push:
branches: [ "main" ]
branches: [ 'main' ]
pull_request:
branches: [ "main" ]
branches: [ 'main' ]
schedule:
- cron: '0 0 * * 5'

Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Lint

on:
push:
branches: [ "main" ]
branches: [ 'main' ]
pull_request:
branches: [ "main" ]
branches: [ 'main' ]

jobs:
check:
Expand All @@ -18,5 +18,7 @@ jobs:
uses: github/super-linter/slim@v4
env:
VALIDATE_ALL_CODEBASE: false
DEFAULT_BRANCH: "main"
FILTER_REGEX_EXCLUDE: '(/dist/|/lib/|/node_modules/)'
VALIDATE_TYPESCRIPT_STANDARD: false
DEFAULT_BRANCH: 'main'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
12 changes: 6 additions & 6 deletions .github/workflows/moscow.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
name: MoSCoW Prioritization

on:
pull_request:
types: [labeled, opened, unlabeled, reopened]
pull_request_target:
types: [labeled, opened, unlabeled, reopened]

permissions:
contents: read
issues: write
pull-requests: write

jobs:
check:
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: grevend/[email protected]
with:
token: "${{ secrets.GITHUB_TOKEN }}"
token: '${{ secrets.GITHUB_TOKEN }}'
4 changes: 2 additions & 2 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: Mark stale issues and pull requests
name: Stale Marker

on:
schedule:
- cron: '0 0 * * *'

jobs:
stale:
check:
runs-on: ubuntu-latest
permissions:
issues: write
Expand Down
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,31 @@ MoSCoW prioritization action to manage label-based requirements prioritization
name: MoSCoW Prioritization

on:
pull_request:
types: [labeled, opened, unlabeled, reopened]
pull_request_target:
types: [labeled, opened, unlabeled, reopened]

permissions:
contents: read
issues: write
pull-requests: write

jobs:
check:
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: grevend/[email protected]
with:
token: "${{ secrets.GITHUB_TOKEN }}"
```
_Note: This action requires access to the `GITHUB_TOKEN` to call GitHub's REST API_
_Note: This action requires access to the `GITHUB_TOKEN` to call GitHub's REST API_

### All options

Input | Description | Default
--- | --- | ---
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`
16 changes: 16 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@ inputs:
token:
description: 'The workflows GITHUB_TOKEN secret'
required: true
wont-have-label:
description: 'Label to expect on low-priority PRs'
required: false
default: 'wont have'
could-have-label:
description: 'Label to expect on PRs of little relevance'
required: false
default: 'could have'
should-have-label:
description: 'Label to expect on non-critical PRs'
required: false
default: 'should have'
must-have-label:
description: 'Label to expect on essential PRs'
required: false
default: 'must have'

runs:
using: 'node16'
Expand Down
27 changes: 8 additions & 19 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,38 +39,27 @@ const help = `# MoSCoW Prioritization
Prioritization | Explanation
--- | ---
Must Have | Essential and non-negotiable requirements for the project.
Should Have | Not critical to the success of the project, but of high relevance. Should be taken into account in the project implementation, as long as no impairment of must requirements occurs.
Should Have | Not critical to the success of the project but of high relevance. Should be taken into account in the project implementation, as long as no impairment of must requirements occurs.
Could Have | Of little relevance and is only taken into account if there is still capacity in addition to the requirements for must and should.
Won't Have (this time) | Low priority for the current planning stage, but will be prioritized again for the next release.
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 token = core.getInput('token', { required: true });
const octo = gh.getOctokit(token);
(async () => {
var _a, _b, _c;
(async function () {
try {
const prNum = (_c = (_b = (_a = gh === null || gh === void 0 ? void 0 : gh.context) === null || _a === void 0 ? void 0 : _a.payload) === null || _b === void 0 ? void 0 : _b.pull_request) === null || _c === void 0 ? void 0 : _c.number;
if (!prNum) {
const prNum = gh?.context?.payload?.pull_request?.number;
if (prNum === undefined) {
core.info('This action only works on pull requests!');
return;
}
const { data: pr } = await octo.rest.pulls.get({
...gh.context.repo, pull_number: prNum
});
const hasLabel = pr.labels.some(({ name: label }) => {
switch (label) {
case "Wont Have":
case "Could Have":
case "Should Have":
case "Must Have":
return true;
default:
return false;
}
});
const exists = pr.labels.some(label => labels.includes(label.name));
await octo.rest.issues.createComment({
...gh.context.repo, issue_number: prNum,
body: hasLabel ? complete : help
...gh.context.repo, issue_number: prNum, body: exists ? complete : help
});
}
catch (error) {
Expand Down
Loading

0 comments on commit c75d66f

Please sign in to comment.