Skip to content

Commit 0c04e06

Browse files
authored
chore: fix needs attention status update graphql api for priority board (#33349)
### Issue # (if applicable) Closes NA ### Reason for this change Github graphql api to update the needs attention field returns error as it couldn't find the corresponding option id of the value to update. ``` errors: [ { type: 'VALIDATION', path: [Array], locations: [Array], message: 'The single select option Id does not belong to the field' } ], ``` ### Description of changes This change will get the corresponding optionId for the required needs attention field value and is passed to the graphql api. ### Describe any new or updated permissions being added N/A ### Description of how you validated changes * Tested by unit test * Manually ran the graphql api using cli to update the field ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent fbcb732 commit 0c04e06

File tree

3 files changed

+66
-11
lines changed

3 files changed

+66
-11
lines changed

scripts/@aws-cdk/script-tests/prioritization/helpers/mock-data.js

+37-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { PRIORITIES, LABELS, STATUS, ...PROJECT_CONFIG } = require('../../../../../scripts/prioritization/project-config');
1+
const { PRIORITIES, LABELS, STATUS, NEEDS_ATTENTION_STATUS, ...PROJECT_CONFIG } = require('../../../../../scripts/prioritization/project-config');
22

33
const OPTION_IDS = {
44
[PRIORITIES.R1]: 'r1-option-id',
@@ -10,7 +10,10 @@ const OPTION_IDS = {
1010
[STATUS.IN_PROGRESS]: 'in_progress-status-id',
1111
[STATUS.PAUSED]: 'paused-status-id',
1212
[STATUS.ASSIGNED]: 'assigned-status-id',
13-
[STATUS.DONE]: 'done-status-id'
13+
[STATUS.DONE]: 'done-status-id',
14+
[NEEDS_ATTENTION_STATUS.EXTENDED.name]: 'extended-status-id',
15+
[NEEDS_ATTENTION_STATUS.AGING.name]: 'aging-status-id',
16+
[NEEDS_ATTENTION_STATUS.STALLED.name]: 'stalled-status-id'
1417
};
1518

1619
const projectFields = {
@@ -279,7 +282,27 @@ exports.createMockGithubForNeedsAttention = ({
279282
}
280283
});
281284

282-
// First call - fetch project items
285+
// First call - fetch project fields
286+
graphql.mockResolvedValueOnce({
287+
organization: {
288+
projectV2: {
289+
fields: {
290+
nodes: [
291+
{
292+
id: PROJECT_CONFIG.attentionFieldId,
293+
name: 'Needs Attention',
294+
options: Object.values(NEEDS_ATTENTION_STATUS).map(attentionStatus => ({
295+
id: OPTION_IDS[attentionStatus.name],
296+
name: attentionStatus.name
297+
}))
298+
}
299+
]
300+
}
301+
}
302+
}
303+
});
304+
305+
// Second call - fetch project items
283306
graphql.mockResolvedValueOnce({
284307
organization: {
285308
projectV2: {
@@ -295,6 +318,17 @@ exports.createMockGithubForNeedsAttention = ({
295318
}
296319
});
297320

321+
// For field updates
322+
if (items) {
323+
items.forEach(item => {
324+
if (item.status !== STATUS.DONE) { // Skip DONE items
325+
graphql.mockResolvedValueOnce(updateFieldValueInProject);
326+
}
327+
});
328+
} else if (status !== STATUS.DONE) {
329+
graphql.mockResolvedValueOnce(updateFieldValueInProject);
330+
}
331+
298332
return { graphql };
299333
};
300334

scripts/@aws-cdk/script-tests/prioritization/update-attention-status.test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('Needs Attention Status Assignment', () => {
2929
call[1].input?.fieldId === PROJECT_CONFIG.attentionFieldId
3030
);
3131
expect(attentionUpdateCall[1].input.value.singleSelectOptionId)
32-
.toBe(expectedAttentionStatus);
32+
.toBe(OPTION_IDS[expectedAttentionStatus]);
3333
}
3434

3535
describe('Needs Attention Status Tests', () => {
@@ -102,11 +102,11 @@ describe('Needs Attention Status Assignment', () => {
102102

103103
expect(attentionCalls).toHaveLength(3); // Only 3 items should be updated
104104
expect(attentionCalls[0][1].input.value.singleSelectOptionId)
105-
.toBe(NEEDS_ATTENTION_STATUS.EXTENDED.name);
105+
.toBe(OPTION_IDS[NEEDS_ATTENTION_STATUS.EXTENDED.name]);
106106
expect(attentionCalls[1][1].input.value.singleSelectOptionId)
107-
.toBe(NEEDS_ATTENTION_STATUS.AGING.name);
107+
.toBe(OPTION_IDS[NEEDS_ATTENTION_STATUS.AGING.name]);
108108
expect(attentionCalls[2][1].input.value.singleSelectOptionId)
109-
.toBe(NEEDS_ATTENTION_STATUS.STALLED.name);
109+
.toBe(OPTION_IDS[NEEDS_ATTENTION_STATUS.STALLED.name]);
110110
});
111111
});
112112
});

scripts/prioritization/update-attention-status.js

+25-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* This helps maintain visibility of PRs that may need intervention to progress.
1515
*/
1616
const { STATUS, NEEDS_ATTENTION_STATUS, ...PROJECT_CONFIG } = require('./project-config');
17-
const { updateProjectField, fetchProjectItems } = require('./project-api');
17+
const { fetchProjectFields, updateProjectField, fetchProjectItems } = require('./project-api');
1818

1919
const MS_PER_DAY = 1000 * 60 * 60 * 24;
2020

@@ -35,6 +35,20 @@ const getAttentionStatus = (days) => {
3535

3636
module.exports = async ({ github }) => {
3737
try {
38+
const projectFields = await fetchProjectFields({
39+
github,
40+
org: PROJECT_CONFIG.org,
41+
number: PROJECT_CONFIG.projectNumber
42+
});
43+
44+
const attentionField = projectFields.organization.projectV2.fields.nodes.find(
45+
field => field.id === PROJECT_CONFIG.attentionFieldId
46+
);
47+
48+
if (!attentionField) {
49+
throw new Error('Attention field not found in project');
50+
}
51+
3852
let allItems = [];
3953
let hasNextPage = true;
4054
let cursor = null;
@@ -85,16 +99,23 @@ module.exports = async ({ github }) => {
8599

86100
// Only update if attention status needs to be set
87101
if (attentionStatus) {
102+
const attentionFieldOptionId = attentionField.options.find(
103+
(option) => option.name === attentionStatus
104+
)?.id;
105+
106+
if (!attentionFieldOptionId) {
107+
console.error(`No option ID found for attention status: ${attentionStatus}`);
108+
continue;
109+
}
110+
88111
await updateProjectField({
89112
github,
90113
projectId: PROJECT_CONFIG.projectId,
91114
itemId: item.id,
92115
fieldId: PROJECT_CONFIG.attentionFieldId,
93-
value: attentionStatus,
116+
value: attentionFieldOptionId,
94117
});
95118
console.log(`Updated item ${item.id} attention status to ${attentionStatus}`);
96-
} else {
97-
console.log(`No attention status needed for item ${item.id}`);
98119
}
99120
} catch (error) {
100121
console.error(`Error processing item ${item.id}:`, error);

0 commit comments

Comments
 (0)