Skip to content

Commit 199a0ca

Browse files
authored
feat: post better effort comment with no auto-setting (#28)
1 parent bd775b0 commit 199a0ca

File tree

6 files changed

+56
-118
lines changed

6 files changed

+56
-118
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ It reacts to `issues` and `pull_request` events, and does the following:
2020
- `effortMapping`: JSON string with map where:
2121
- string key is a valid 'effort' field value
2222
- number value is maximum duration in days
23-
for example: {"two days": 2, "workweek": 5}. Defaults to `{"two days": 2, "workweek": 5}`.
23+
for example: {"two days": 2, "workweek": 5}.
24+
Defaults to `[{"pattern": "two days", "value": 2},{"pattern": "the longest one", "value": 1e1000}]`.
25+
`1e1000` is JSON for `Infinity`
2426
- `monthlyMilestoneName`: Name of the 'monthly milestone' field on the project board. Defaults to `monthly milestone`.
2527
- `quarterlyMilestoneName`: Name of the 'quarterly milestone' field on the project board. Defaults to `quarterly milestone`.
2628

action.js

Lines changed: 46 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module.exports = async (
3030
issueStatusValue = 'todo',
3131
includeEffort = true,
3232
effortName = 'effort',
33-
effortMapping = '{"two days": 2, "workweek": 5}',
33+
effortMapping = '[{"pattern": "two days", "value": 2},{"pattern": "the longest one", "value": 1e1000}]',
3434
monthlyMilestoneName = 'monthly milestone',
3535
quarterlyMilestoneName = 'quarterly milestone',
3636
basePath = '.'
@@ -126,9 +126,7 @@ module.exports = async (
126126
};
127127
};
128128

129-
let effortFieldId;
130-
let effortValueId;
131-
let effortHumanReadable;
129+
let effortMessage;
132130
let isDraftPr;
133131
if (isPr) {
134132
// assign author if a PR
@@ -187,6 +185,7 @@ module.exports = async (
187185
if (includeEffort) {
188186
// get weekdays since PR's first commit
189187
let prCreatedAt = new Date();
188+
effortMessage = `Please set effort on project item card:\n\n`;
190189
prCommitData.forEach(commit => {
191190
const commitDate = new Date(commit.commit.authoredDate);
192191
if (commitDate < prCreatedAt) {
@@ -197,75 +196,71 @@ module.exports = async (
197196

198197
// map days spent to effort size pattern
199198
let milestonePattern;
200-
for (const [pattern, dayCount] of Object.entries(JSON.parse(effortMapping))) {
201-
if (workingDaysSinceCreated < dayCount) {
202-
milestonePattern = pattern;
199+
let effortMappingObj = JSON.parse(effortMapping);
200+
for (const element of effortMappingObj) {
201+
if (workingDaysSinceCreated < element.value) {
202+
milestonePattern = element.pattern;
203203
break;
204204
}
205205
};
206206
if (!milestonePattern) {
207-
bail("cannot estimate effort")
208-
}
209-
// select effort ID based on pattern
207+
bail("cannot estimate effort");
208+
};
209+
// list human-readable efforts
210+
projectFieldOptions.forEach(field => {
211+
if (field.name === effortName) {
212+
field.options.forEach(effort => {
213+
effortMappingObj.forEach(element => {
214+
if (effort.name.toLowerCase().includes(element.pattern.toLowerCase())) {
215+
if (element.value !== Infinity) {
216+
effortMessage += ` - ${effort.name}: ${element.value} day(s) or less,\n`;
217+
} else {
218+
effortMessage += ` - ${effort.name}: longer than any of above.\n`;
219+
};
220+
}
221+
});
222+
});
223+
};
224+
});
225+
// suggest an effort value
210226
projectFieldOptions.forEach(field => {
211227
if (field.name === effortName) {
212-
effortFieldId = field.id;
213228
field.options.forEach(effort => {
214229
if (effort.name.toLowerCase().includes(milestonePattern.toLowerCase())) {
215-
effortValueId = effort.id;
216-
effortHumanReadable = effort.name;
230+
effortMessage += `\nBased on first commit date, ${effort.name} should be adequate.`;
217231
};
218232
});
219233
};
220234
});
221235
};
222236
};
223237

224-
if (isPr) { // set status, milestones & maybe effort if a PR
238+
if (isPr) { // set status, milestones & notify about effort if a PR
239+
const assignProjectFieldsQuery = fs.readFileSync(`${basePath}/graphql/projectNoEffortItemAssignFields.gql`, 'utf8');
240+
const assignProjectFieldsParams = {
241+
project: projectId,
242+
item: projectItemId,
243+
status_field: statusFieldId,
244+
status_value: prStatusValueId,
245+
primary_milestone_field: monthlyMilestoneFieldId,
246+
primary_milestone_value: monthlyMilestoneValueId,
247+
secondary_milestone_field: quarterlyMilestoneFieldId,
248+
secondary_milestone_value: quarterlyMilestoneValueId
249+
};
250+
try {
251+
await github.graphql(assignProjectFieldsQuery, assignProjectFieldsParams);
252+
} catch (error) {
253+
bail(error.message);
254+
};
225255
if (includeEffort) {
226-
const assignProjectFieldsQuery = fs.readFileSync(`${basePath}/graphql/projectEffortItemAssignFields.gql`, 'utf8');
227-
const assignProjectFieldsParams = {
228-
project: projectId,
229-
item: projectItemId,
230-
status_field: statusFieldId,
231-
status_value: prStatusValueId,
232-
effort_field: effortFieldId,
233-
effort_value: effortValueId,
234-
primary_milestone_field: monthlyMilestoneFieldId,
235-
primary_milestone_value: monthlyMilestoneValueId,
236-
secondary_milestone_field: quarterlyMilestoneFieldId,
237-
secondary_milestone_value: quarterlyMilestoneValueId
238-
};
239-
try {
240-
await github.graphql(assignProjectFieldsQuery, assignProjectFieldsParams);
241-
} catch (error) {
242-
bail(error.message);
243-
};
244256
await github.rest.issues.createComment({
245257
owner: context.repo.owner,
246258
repo: context.repo.repo,
247259
issue_number: context.payload.pull_request.number,
248-
body: `Effort has been estimated to ${effortHumanReadable}.
249-
This is based on date of first commit and mapping: ${effortMapping}`
260+
body: effortMessage
250261
});
251-
coreGlob.info("set project fields including effort");
262+
coreGlob.info("set project fields suggesting effort");
252263
} else {
253-
const assignProjectFieldsQuery = fs.readFileSync(`${basePath}/graphql/projectNoEffortItemAssignFields.gql`, 'utf8');
254-
const assignProjectFieldsParams = {
255-
project: projectId,
256-
item: projectItemId,
257-
status_field: statusFieldId,
258-
status_value: prStatusValueId,
259-
primary_milestone_field: monthlyMilestoneFieldId,
260-
primary_milestone_value: monthlyMilestoneValueId,
261-
secondary_milestone_field: quarterlyMilestoneFieldId,
262-
secondary_milestone_value: quarterlyMilestoneValueId
263-
};
264-
try {
265-
await github.graphql(assignProjectFieldsQuery, assignProjectFieldsParams);
266-
} catch (error) {
267-
bail(error.message);
268-
};
269264
coreGlob.info("set project fields omitting effort");
270265
}
271266
} else { // set status if an Issue

action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ inputs:
4141
JSON string with map where:
4242
- string key is a valid 'effort' field value
4343
- number value is maximum duration in days
44-
for example: {"two days": 2, "workweek": 5}
44+
for example: [{"pattern": "two days", "value": 2},{"pattern": "the longest one", "value": 1e1000}]
4545
required: false
46-
default: '{"two days": 2, "workweek": 5}'
46+
default: '[{"pattern": "two days", "value": 2},{"pattern": "the longest one", "value": 1e1000}]'
4747
monthlyMilestoneName:
4848
description: Name of the 'monthly milestone' field on the project board
4949
required: false

graphql/projectEffortItemAssignFields.gql

Lines changed: 0 additions & 61 deletions
This file was deleted.

test/.env.sample

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
ACT_TEST=true
22
GITHUB_REPOSITORY='change_me_org/change_me_repo'
33
GH_REPO=$GITHUB_REPOSITORY
4-
newItemStatus='todo'
4+
newIssueStatus='todo'
5+
newPrStatus='todo'
56
statusName='status'
67
effortName='effort'
78
monthlyMilestoneName='monthly milestone'
89
quarterlyMilestoneName='quarterly milestone'
9-
effortMapping='{"two days": 2, "workweek": 5}'
10+
effortMapping='[{"pattern": "two days", "value": 2},{"pattern": "the longest one", "value": 1e1000}]'

test/.github/workflows/workflow.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ jobs:
2626
label: needs triage
2727
statusName: ${{ env.statusName }}
2828
includeEffort: "true"
29-
statusValue: ${{ env.newItemStatus }}
29+
prStatusValue: ${{ env.newPrStatus }}
30+
issueStatusValue: ${{ env.newIssueStatus }}
3031
effortName: ${{ env.effortName }}
3132
effortMapping: ${{ env.effortMapping }}
3233
monthlyMilestoneName: ${{ env.monthlyMilestoneName }}

0 commit comments

Comments
 (0)