Skip to content

Commit 19e603b

Browse files
authored
chore: retain existing status in the priority board on github action trigger (#33402)
### Issue # (if applicable) Closes N/A ### Reason for this change The existing PR's in the prioritization board with updated status such as In `Progress`, `Assigned` is automatically reset to the `Ready` status when the github action workflow is triggered for the same PR. ### Description of changes In this PR, made changes to check if a PR is already in the board first and if it is then we maintain the existing status and won't update the status. If the PR is new, then it will be added to board and also the status will be set to `Ready`. ### Describe any new or updated permissions being added N/A ### Description of how you validated changes * Update unit tests * Ran locally in test repo ### 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 a7d7373 commit 19e603b

File tree

8 files changed

+339
-150
lines changed

8 files changed

+339
-150
lines changed

scripts/@aws-cdk/script-tests/prioritization/assign-priority.test.js

Lines changed: 125 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { PRIORITIES, LABELS, STATUS, ...PROJECT_CONFIG} = require('../../../../scripts/prioritization/project-config');
22
const {
3-
createMockPR,
4-
createMockGithub,
3+
createMockPR,
4+
createMockGithubForPriority,
55
OPTION_IDS
66
} = require('./helpers/mock-data');
77

@@ -13,39 +13,58 @@ describe('Priority Assignment (R1, R3, R4)', () => {
1313
let mockContext;
1414

1515
beforeEach(() => {
16-
mockGithub = createMockGithub();
1716
jest.clearAllMocks();
1817
});
1918

2019
async function verifyProjectState(expectedPriority, expectedStatus) {
21-
const calls = mockGithub.graphql.mock.calls;
22-
23-
if (!expectedPriority) {
24-
const priorityUpdateCall = calls.find(call =>
25-
call[1].input?.fieldId === PROJECT_CONFIG.priorityFieldId
26-
);
27-
expect(priorityUpdateCall).toBeUndefined();
28-
return;
29-
}
30-
31-
const priorityUpdateCall = calls.find(call =>
32-
call[1].input?.fieldId === PROJECT_CONFIG.priorityFieldId
33-
);
34-
const statusUpdateCall = calls.find(call =>
35-
call[1].input?.fieldId === PROJECT_CONFIG.statusFieldId
36-
);
37-
38-
// Verify priority was set correctly
39-
expect(priorityUpdateCall[1].input.value.singleSelectOptionId)
40-
.toBe(OPTION_IDS[expectedPriority]);
41-
42-
// Verify status was set to Ready
43-
expect(statusUpdateCall[1].input.value.singleSelectOptionId)
44-
.toBe(OPTION_IDS[expectedStatus]);
20+
const calls = mockGithub.graphql.mock.calls;
21+
22+
if (!expectedPriority) {
23+
const priorityUpdateCall = calls.find(call =>
24+
call[1].input?.fieldId === PROJECT_CONFIG.priorityFieldId
25+
);
26+
expect(priorityUpdateCall).toBeUndefined();
27+
return;
28+
}
29+
30+
const fetchItemResponse = await mockGithub.graphql.mock.results[1].value;
31+
const existingItem = fetchItemResponse?.node?.projectItems?.nodes?.[0];
32+
33+
// Find priority update call
34+
const priorityUpdateCall = calls.find(call =>
35+
call[1].input?.fieldId === PROJECT_CONFIG.priorityFieldId
36+
);
37+
38+
// Verify priority was set correctly
39+
expect(priorityUpdateCall[1].input.value.singleSelectOptionId)
40+
.toBe(OPTION_IDS[expectedPriority]);
41+
42+
// Check if item exists in project
43+
if (existingItem) {
44+
// For existing items, verify no status update was attempted
45+
const statusUpdateCall = calls.find(call =>
46+
call[1].input?.fieldId === PROJECT_CONFIG.statusFieldId
47+
);
48+
expect(statusUpdateCall).toBeUndefined();
49+
50+
const actualStatus = existingItem.fieldValues.nodes
51+
.find(node => node.field?.name === 'Status')?.name;
52+
expect(actualStatus).toBe(expectedStatus);
53+
} else {
54+
// For new items, verify status was set to Ready
55+
const statusUpdateCall = calls.find(call =>
56+
call[1].input?.fieldId === PROJECT_CONFIG.statusFieldId
57+
);
58+
expect(statusUpdateCall[1].input.value.singleSelectOptionId)
59+
.toBe(OPTION_IDS[STATUS.READY]);
60+
}
4561
}
4662

63+
4764
describe('R1 Priority Tests', () => {
4865
test('should assign R1 and Ready status to non-draft PR with contribution/core label', async () => {
66+
mockGithub = createMockGithubForPriority();
67+
4968
const pr = createMockPR({
5069
draft: false,
5170
labels: [LABELS.CORE]
@@ -58,6 +77,8 @@ describe('Priority Assignment (R1, R3, R4)', () => {
5877
});
5978

6079
test('should assign R1 and Ready status to non-draft PR with contribution/core and needs-maintainer-review labels', async () => {
80+
mockGithub = createMockGithubForPriority();
81+
6182
const pr = createMockPR({
6283
draft: false,
6384
labels: [LABELS.CORE, LABELS.MAINTAINER_REVIEW]
@@ -70,6 +91,8 @@ describe('Priority Assignment (R1, R3, R4)', () => {
7091
});
7192

7293
test('should not add draft PR with contribution/core label to project', async () => {
94+
mockGithub = createMockGithubForPriority();
95+
7396
const pr = createMockPR({
7497
draft: true,
7598
labels: [LABELS.CORE]
@@ -80,10 +103,29 @@ describe('Priority Assignment (R1, R3, R4)', () => {
80103
await assignPriority({ github: mockGithub, context: mockContext });
81104
await verifyProjectState(null);
82105
});
106+
107+
test('should retain existing status when updating priority to R1', async () => {
108+
mockGithub = createMockGithubForPriority({
109+
existingPriority: PRIORITIES.R3,
110+
existingStatus: STATUS.IN_PROGRESS
111+
});
112+
113+
const pr = createMockPR({
114+
draft: false,
115+
labels: [LABELS.CORE]
116+
});
117+
118+
mockContext = { payload: { pull_request: pr } };
119+
120+
await assignPriority({ github: mockGithub, context: mockContext });
121+
await verifyProjectState(PRIORITIES.R1, STATUS.IN_PROGRESS);
122+
});
83123
});
84124

85125
describe('R3 Priority Tests', () => {
86126
test('should assign R3 and Ready status to non-draft PR with needs-maintainer-review label', async () => {
127+
mockGithub = createMockGithubForPriority();
128+
87129
const pr = createMockPR({
88130
draft: false,
89131
labels: [LABELS.MAINTAINER_REVIEW]
@@ -96,6 +138,8 @@ describe('Priority Assignment (R1, R3, R4)', () => {
96138
});
97139

98140
test('should not assign R3 to draft PR with needs-maintainer-review label', async () => {
141+
mockGithub = createMockGithubForPriority();
142+
99143
const pr = createMockPR({
100144
draft: true,
101145
labels: [LABELS.MAINTAINER_REVIEW]
@@ -106,10 +150,29 @@ describe('Priority Assignment (R1, R3, R4)', () => {
106150
await assignPriority({ github: mockGithub, context: mockContext });
107151
await verifyProjectState(null);
108152
});
153+
154+
test('should retain existing status when updating priority to R3', async () => {
155+
mockGithub = createMockGithubForPriority({
156+
existingPriority: PRIORITIES.R4,
157+
existingStatus: STATUS.IN_PROGRESS
158+
});
159+
160+
const pr = createMockPR({
161+
draft: false,
162+
labels: [LABELS.MAINTAINER_REVIEW]
163+
});
164+
165+
mockContext = { payload: { pull_request: pr } };
166+
167+
await assignPriority({ github: mockGithub, context: mockContext });
168+
await verifyProjectState(PRIORITIES.R3, STATUS.IN_PROGRESS);
169+
});
109170
});
110171

111172
describe('R4 Priority Tests', () => {
112173
test('should assign R4 and Ready status to PR with pr/reviewer-clarification-requested and needs-community-review labels', async () => {
174+
mockGithub = createMockGithubForPriority();
175+
113176
const pr = createMockPR({
114177
draft: true,
115178
labels: [
@@ -125,6 +188,8 @@ describe('Priority Assignment (R1, R3, R4)', () => {
125188
});
126189

127190
test('should assign R4 and Ready status to PR with pr-linter/exemption-requested and needs-community-review labels', async () => {
191+
mockGithub = createMockGithubForPriority();
192+
128193
const pr = createMockPR({
129194
draft: true,
130195
labels: [
@@ -140,6 +205,8 @@ describe('Priority Assignment (R1, R3, R4)', () => {
140205
});
141206

142207
test('should assign R4 and Ready status to PR with pr/reviewer-clarification-requested and needs-maintainer-review labels', async () => {
208+
mockGithub = createMockGithubForPriority();
209+
143210
const pr = createMockPR({
144211
draft: true,
145212
labels: [
@@ -155,6 +222,8 @@ describe('Priority Assignment (R1, R3, R4)', () => {
155222
});
156223

157224
test('should assign R4 and Ready status to PR with pr-linter/exemption-requested and needs-maintainer-review labels', async () => {
225+
mockGithub = createMockGithubForPriority();
226+
158227
const pr = createMockPR({
159228
labels: [
160229
LABELS.EXEMPTION_REQUESTED,
@@ -169,6 +238,8 @@ describe('Priority Assignment (R1, R3, R4)', () => {
169238
});
170239

171240
test('should assign R4 and Ready status to PR with pr/reviewer-clarification-requested label and no review labels', async () => {
241+
mockGithub = createMockGithubForPriority();
242+
172243
const pr = createMockPR({
173244
labels: [LABELS.CLARIFICATION_REQUESTED]
174245
});
@@ -180,6 +251,8 @@ describe('Priority Assignment (R1, R3, R4)', () => {
180251
});
181252

182253
test('should assign R4 and Ready status to PR with pr-linter/exemption-requested label and no review labels', async () => {
254+
mockGithub = createMockGithubForPriority();
255+
183256
const pr = createMockPR({
184257
draft: true,
185258
labels: [LABELS.EXEMPTION_REQUESTED]
@@ -190,10 +263,31 @@ describe('Priority Assignment (R1, R3, R4)', () => {
190263
await assignPriority({ github: mockGithub, context: mockContext });
191264
await verifyProjectState(PRIORITIES.R4, STATUS.READY);
192265
});
266+
267+
test('should retain existing status when updating priority to R4', async () => {
268+
mockGithub = createMockGithubForPriority({
269+
existingPriority: PRIORITIES.R5,
270+
existingStatus: STATUS.PAUSED
271+
});
272+
273+
const pr = createMockPR({
274+
labels: [
275+
LABELS.CLARIFICATION_REQUESTED,
276+
LABELS.COMMUNITY_REVIEW
277+
]
278+
});
279+
280+
mockContext = { payload: { pull_request: pr } };
281+
282+
await assignPriority({ github: mockGithub, context: mockContext });
283+
await verifyProjectState(PRIORITIES.R4, STATUS.PAUSED);
284+
});
193285
});
194286

195287
describe('Priority Precedence Tests', () => {
196288
test('should assign R1 over R3 when PR has both contribution/core and needs-maintainer-review labels', async () => {
289+
mockGithub = createMockGithubForPriority();
290+
197291
const pr = createMockPR({
198292
draft: false,
199293
labels: [
@@ -209,6 +303,8 @@ describe('Priority Assignment (R1, R3, R4)', () => {
209303
});
210304

211305
test('should assign R1 over R4 when PR has both contribution/core and pr/reviewer-clarification-requested labels', async () => {
306+
mockGithub = createMockGithubForPriority();
307+
212308
const pr = createMockPR({
213309
draft: false,
214310
labels: [
@@ -223,6 +319,8 @@ describe('Priority Assignment (R1, R3, R4)', () => {
223319
});
224320

225321
test('should not assign any priority when no matching labels', async () => {
322+
mockGithub = createMockGithubForPriority();
323+
226324
const pr = createMockPR({
227325
draft: false,
228326
labels: []

0 commit comments

Comments
 (0)