Skip to content

Commit bd775b0

Browse files
authored
feat: separate init status for PRs and Issues (#27)
1 parent eb9225e commit bd775b0

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ It reacts to `issues` and `pull_request` events, and does the following:
1414
- `token`: A personal access token with write:org capabilities.
1515
- `todoLabel`: Initial label for new issues/PRs. Defaults to `needs triage`.
1616
- `statusName`: Name of the 'status' field on the project board. Defaults to `status`.
17-
- `statusValue`: Name of the 'todo' status on the project board. Defaults to `needs triage`.
17+
- `prStatusValue`: Name of the 'todo' status on the project board. Defaults to `todo`.
18+
- `issueStatusValue`: Name of the 'todo' status on the project board. Defaults to `todo`.
1819
- `effortName`: Name of the 'effort' field on the project board `effort`.
1920
- `effortMapping`: JSON string with map where:
2021
- string key is a valid 'effort' field value
@@ -47,7 +48,8 @@ jobs:
4748
token: ${{ secrets.PLANNING_AUTOMATION_TOKEN }}
4849
todo_label: needs triage
4950
statusName: status
50-
statusValue: needs triage
51+
prStatusValue: todo
52+
issueStatusValue: todo
5153
effortName: effort
5254
effortMapping: '{"two days": 2, "workweek": 5}'
5355
monthlyMilestoneName: monthly milestone

action.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ let coreGlob
1010
* @param {string} organization GitHub organization name
1111
* @param {number} projectNumber project ID as seen in project board URL
1212
* @param {string} statusName status field name to be set
13-
* @param {string} statusValue status name to be assigned
13+
* @param {string} prStatusValue PR status name to be assigned
14+
* @param {string} issueStatusValue Issue status name to be assigned
1415
* @param {Boolean} includeEffort if true, set effort
1516
* @param {string} effortName effort field name to be set
1617
* @param {string} effortMapping JSON effort name - days map
@@ -25,7 +26,8 @@ module.exports = async (
2526
organization = '',
2627
projectNumber,
2728
statusName = 'status',
28-
statusValue = 'todo',
29+
prStatusValue = 'todo',
30+
issueStatusValue = 'todo',
2931
includeEffort = true,
3032
effortName = 'effort',
3133
effortMapping = '{"two days": 2, "workweek": 5}',
@@ -59,14 +61,21 @@ module.exports = async (
5961

6062
// get todo status
6163
let statusFieldId;
62-
let statusValueId;
64+
let prStatusValueId;
65+
let issueStatusValueId;
6366
projectFieldOptions.forEach(field => {
6467
if (field.name === statusName) {
6568
statusFieldId = field.id;
6669
field.options.forEach(status => {
67-
if (status.name.toLowerCase().includes(statusValue.toLowerCase()))
68-
statusValueId = status.id;
70+
if (status.name.toLowerCase().includes(prStatusValue.toLowerCase()))
71+
prStatusValueId = status.id;
72+
if (status.name.toLowerCase().includes(issueStatusValue.toLowerCase()))
73+
issueStatusValueId = status.id;
6974
});
75+
if (!prStatusValueId)
76+
bail("cannot find PR target status")
77+
if (!issueStatusValueId)
78+
bail("cannot find Issue target status")
7079
};
7180
});
7281

@@ -194,7 +203,9 @@ module.exports = async (
194203
break;
195204
}
196205
};
197-
206+
if (!milestonePattern) {
207+
bail("cannot estimate effort")
208+
}
198209
// select effort ID based on pattern
199210
projectFieldOptions.forEach(field => {
200211
if (field.name === effortName) {
@@ -217,7 +228,7 @@ module.exports = async (
217228
project: projectId,
218229
item: projectItemId,
219230
status_field: statusFieldId,
220-
status_value: statusValueId,
231+
status_value: prStatusValueId,
221232
effort_field: effortFieldId,
222233
effort_value: effortValueId,
223234
primary_milestone_field: monthlyMilestoneFieldId,
@@ -244,7 +255,7 @@ module.exports = async (
244255
project: projectId,
245256
item: projectItemId,
246257
status_field: statusFieldId,
247-
status_value: statusValueId,
258+
status_value: prStatusValueId,
248259
primary_milestone_field: monthlyMilestoneFieldId,
249260
primary_milestone_value: monthlyMilestoneValueId,
250261
secondary_milestone_field: quarterlyMilestoneFieldId,
@@ -263,7 +274,7 @@ module.exports = async (
263274
project: projectId,
264275
item: projectItemId,
265276
status_field: statusFieldId,
266-
status_value: statusValueId,
277+
status_value: issueStatusValueId,
267278
};
268279
try {
269280
await github.graphql(assignProjectFieldsQuery, assignProjectFieldsParams);

action.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ inputs:
2020
description: Name of the 'status' field on the project board
2121
required: false
2222
default: status
23-
statusValue:
23+
prStatusValue:
24+
description: Name of the 'todo' status on the project board
25+
required: false
26+
default: todo
27+
issueStatusValue:
2428
description: Name of the 'todo' status on the project board
2529
required: false
2630
default: todo
@@ -74,7 +78,8 @@ runs:
7478
`${{ inputs.organization }}`,
7579
${{ inputs.project }},
7680
`${{ inputs.statusName }}`,
77-
`${{ inputs.statusValue }}`,
81+
`${{ inputs.prStatusValue }}`,
82+
`${{ inputs.issueStatusValue }}`,
7883
${{ inputs.includeEffort }},
7984
`${{ inputs.effortName }}`,
8085
`${{ inputs.effortMapping }}`,

0 commit comments

Comments
 (0)