Skip to content

Commit 5293242

Browse files
authored
fix: effort setting (#22)
1 parent 39fe94f commit 5293242

File tree

5 files changed

+72
-8
lines changed

5 files changed

+72
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ It reacts to `issues` and `pull_request` events, and does the following:
1212

1313
- `project`: Project board number (`github.com/orgs/foo/projects/N`)
1414
- `token`: A personal access token with write:org capabilities.
15-
- `todo_label`: Initial label for new issues/PRs. Defaults to `needs triage`.
15+
- `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`.
1717
- `statusValue`: Name of the 'todo' status on the project board. Defaults to `needs triage`.
1818
- `effortName`: Name of the 'effort' field on the project board `effort`.

action.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,16 +205,15 @@ module.exports = async (
205205
};
206206

207207
// set milestones & effort
208-
if (!isPr || (isPr && !isDraftPr)) {
209-
const assignProjectFieldsQuery = fs.readFileSync(`${basePath}/graphql/projectItemAssignFields.gql`, 'utf8');
208+
if (includeEffort && (isPr && !isDraftPr)) {
209+
const assignProjectFieldsQuery = fs.readFileSync(`${basePath}/graphql/projectEffortItemAssignFields.gql`, 'utf8');
210210
const assignProjectFieldsParams = {
211211
project: projectId,
212212
item: projectItemId,
213213
status_field: statusFieldId,
214214
status_value: statusValueId,
215215
effort_field: effortFieldId,
216216
effort_value: effortValueId,
217-
effort_included: isPr && includeEffort,
218217
primary_milestone_field: monthlyMilestoneFieldId,
219218
primary_milestone_value: monthlyMilestoneValueId,
220219
secondary_milestone_field: quarterlyMilestoneFieldId,
@@ -226,6 +225,25 @@ module.exports = async (
226225
bail(error.message);
227226
};
228227
};
228+
229+
if (!isPr || (!isDraftPr && !includeEffort)) {
230+
const assignProjectFieldsQuery = fs.readFileSync(`${basePath}/graphql/projectNoEffortItemAssignFields.gql`, 'utf8');
231+
const assignProjectFieldsParams = {
232+
project: projectId,
233+
item: projectItemId,
234+
status_field: statusFieldId,
235+
status_value: statusValueId,
236+
primary_milestone_field: monthlyMilestoneFieldId,
237+
primary_milestone_value: monthlyMilestoneValueId,
238+
secondary_milestone_field: quarterlyMilestoneFieldId,
239+
secondary_milestone_value: quarterlyMilestoneValueId
240+
};
241+
try {
242+
await github.graphql(assignProjectFieldsQuery, assignProjectFieldsParams);
243+
} catch (error) {
244+
bail(error.message);
245+
};
246+
}
229247
}
230248

231249
/**

action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ inputs:
1212
token:
1313
description: GitHub Token with org:write
1414
required: true
15-
todo_label:
15+
todoLabel:
1616
description: Initial label for new issues/PRs
1717
required: false
1818
default: "needs triage"
@@ -56,7 +56,7 @@ runs:
5656
if: ${{ ! env.ACT_TEST }}
5757
uses: andymckay/labeler@e6c4322d0397f3240f0e7e30a33b5c5df2d39e90
5858
with:
59-
add-labels: "${{ inputs.todo_label }}"
59+
add-labels: "${{ inputs.todoLabel }}"
6060
ignore-if-assigned: true
6161
ignore-if-labeled: true
6262
- name: Fetch project data

graphql/projectItemAssignFields.gql renamed to graphql/projectEffortItemAssignFields.gql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ mutation (
55
$status_value: String!
66
$effort_field: ID!
77
$effort_value: String!
8-
$effort_included: Boolean! = false
98
$primary_milestone_field: ID!
109
$primary_milestone_value: String!
1110
$secondary_milestone_field: ID!
@@ -30,7 +29,7 @@ mutation (
3029
fieldId: $effort_field
3130
value: { singleSelectOptionId: $effort_value }
3231
}
33-
) @include(if: $effort_included) {
32+
) {
3433
projectV2Item {
3534
id
3635
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
mutation (
2+
$project: ID!
3+
$item: ID!
4+
$status_field: ID!
5+
$status_value: String!
6+
$primary_milestone_field: ID!
7+
$primary_milestone_value: String!
8+
$secondary_milestone_field: ID!
9+
$secondary_milestone_value: String!
10+
) {
11+
status: updateProjectV2ItemFieldValue(
12+
input: {
13+
projectId: $project
14+
itemId: $item
15+
fieldId: $status_field
16+
value: { singleSelectOptionId: $status_value }
17+
}
18+
) {
19+
projectV2Item {
20+
id
21+
}
22+
}
23+
primary_milestone: updateProjectV2ItemFieldValue(
24+
input: {
25+
projectId: $project
26+
itemId: $item
27+
fieldId: $primary_milestone_field
28+
value: { iterationId: $primary_milestone_value }
29+
}
30+
) {
31+
projectV2Item {
32+
id
33+
}
34+
}
35+
secondary_milestone: updateProjectV2ItemFieldValue(
36+
input: {
37+
projectId: $project
38+
itemId: $item
39+
fieldId: $secondary_milestone_field
40+
value: { iterationId: $secondary_milestone_value }
41+
}
42+
) {
43+
projectV2Item {
44+
id
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)