Skip to content

Commit 7aff4dc

Browse files
authored
ci(project-sync): fill in item priority (#35191)
### Reason for this change Priority field is not set from the item (issue or PR) labels. ### Description of changes Sets the priority field for project items. ### Describe any new or updated permissions being added N/A ### Description of how you validated changes Unit tests and manual testing. ### 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 e07c89b commit 7aff4dc

File tree

13 files changed

+116
-16
lines changed

13 files changed

+116
-16
lines changed

tools/@aws-cdk/project-sync/lib/github.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ const issueQuery = `
66
author {
77
login
88
}
9+
labels(first: 32) {
10+
nodes {
11+
name
12+
}
13+
}
914
timelineItems(last: 16) {
1015
nodes{
1116
... on IssueComment {
@@ -78,6 +83,11 @@ const prQuery = `
7883
author {
7984
login
8085
}
86+
labels(first: 32) {
87+
nodes {
88+
name
89+
}
90+
}
8191
timelineItems(last: 16) {
8292
nodes {
8393
... on PullRequestCommit {
@@ -242,6 +252,14 @@ export class Github {
242252
id
243253
fields(first: 100) {
244254
nodes {
255+
... on ProjectV2SingleSelectField {
256+
id
257+
name
258+
options {
259+
name
260+
id
261+
}
262+
}
245263
... on ProjectV2Field {
246264
id
247265
name

tools/@aws-cdk/project-sync/lib/issue-sync.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Github } from './github.js';
22
import { PROJECT_NUMBER, REPOSITORY } from './config.js';
3-
import { projectIds } from './utils.js';
3+
import { projectIds, getPriorityFromLabels } from './utils.js';
44

55
export const syncIssue = async (issue: string) => {
66
const github = Github.default();
@@ -36,7 +36,7 @@ export const syncIssueData = async (issueDetails: any) => {
3636
return;
3737
}
3838

39-
const { projectId, createFieldId, updateFieldId, authorFieldId } = await projectIds(github);
39+
const { projectId, createFieldId, updateFieldId, authorFieldId, priorityField } = await projectIds(github);
4040

4141
// Get timeline items to determine the last update date (excluding github-actions)
4242
const timelineItems = issueDetails.timelineItems?.nodes ?? [];
@@ -60,11 +60,18 @@ export const syncIssueData = async (issueDetails: any) => {
6060
if (reactionDate > updateDate) {updateDate = reactionDate;}
6161
}
6262

63-
const result = await github.setProjectItem(projectId, projectItemId, {
63+
const fields: Record<string, any> = {
6464
[createFieldId]: { date: creationDate },
6565
[updateFieldId]: { date: updateDate },
6666
[authorFieldId]: { text: issueDetails.author?.login || '' },
67-
});
67+
};
68+
69+
const priorityOptionId = getPriorityFromLabels(issueDetails.labels?.nodes || [], priorityField);
70+
if (priorityOptionId) {
71+
fields[priorityField.id] = { singleSelectOptionId: priorityOptionId };
72+
}
73+
74+
const result = await github.setProjectItem(projectId, projectItemId, fields);
6875
console.log('Result from mutation request: ');
6976
console.dir(JSON.stringify(result));
7077
};

tools/@aws-cdk/project-sync/lib/pr-sync.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Github } from './github.js';
22
import { PROJECT_NUMBER, REPOSITORY } from './config.js';
3-
import { projectIds } from './utils.js';
3+
import { projectIds, getPriorityFromLabels } from './utils.js';
44

55
export const syncPr = async (pr: string) => {
66
const github = Github.default();
@@ -36,7 +36,7 @@ export const syncPrData = async (prDetails: any) => {
3636
return;
3737
}
3838

39-
const { projectId, createFieldId, updateFieldId, authorFieldId } = await projectIds(github);
39+
const { projectId, createFieldId, updateFieldId, authorFieldId, priorityField } = await projectIds(github);
4040

4141
// Get timeline items to determine the last update date (excluding github-actions)
4242
const timelineItems = prDetails.timelineItems?.nodes ?? [];
@@ -60,11 +60,18 @@ export const syncPrData = async (prDetails: any) => {
6060
if (reactionDate > updateDate) {updateDate = reactionDate;}
6161
}
6262

63-
const result = await github.setProjectItem(projectId, projectItemId, {
63+
const fields: Record<string, any> = {
6464
[createFieldId]: { date: creationDate },
6565
[updateFieldId]: { date: updateDate },
6666
[authorFieldId]: { text: prDetails.author?.login || '' },
67-
});
67+
};
68+
69+
const priorityOptionId = getPriorityFromLabels(prDetails.labels?.nodes || [], priorityField);
70+
if (priorityOptionId) {
71+
fields[priorityField.id] = { singleSelectOptionId: priorityOptionId };
72+
}
73+
74+
const result = await github.setProjectItem(projectId, projectItemId, fields);
6875
console.log('Result from mutation request: ');
6976
console.dir(JSON.stringify(result));
7077
};

tools/@aws-cdk/project-sync/lib/sync-all.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export async function syncAll() {
4444
console.log(`Processing issue #${issueNumber}: ${issue.title}`);
4545

4646
try {
47+
await new Promise(resolve => setTimeout(resolve, 500));
4748
await syncIssueData(issue);
4849
console.log(`Successfully synced issue #${issueNumber}`);
4950
} catch (error) {
@@ -57,6 +58,7 @@ export async function syncAll() {
5758
console.log(`Processing PR #${prNumber}: ${pr.title}`);
5859

5960
try {
61+
await new Promise(resolve => setTimeout(resolve, 500));
6062
await syncPrData(pr);
6163
console.log(`Successfully synced PR #${prNumber}`);
6264
} catch (error) {

tools/@aws-cdk/project-sync/lib/utils.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,39 @@
11
import { PROJECT_NUMBER } from './config';
22
import { Github } from './github';
33

4+
export const PRIORITIES = {
5+
p0: 'P0',
6+
p1: 'P1',
7+
p2: 'P2',
8+
p3: 'P3',
9+
};
10+
411
export const projectIds = async (github: Github) : Promise<{
512
projectId: string;
613
createFieldId: string;
714
updateFieldId: string;
815
authorFieldId: string;
16+
priorityField: {
17+
id: string;
18+
options: Record<keyof typeof PRIORITIES, string>;
19+
};
920
}> => {
1021
const projectInfo = await github.getProjectInfo(PROJECT_NUMBER);
1122
const projectId = projectInfo.data.repository.projectV2.id!;
1223

1324
let createFieldId = undefined;
1425
let updateFieldId = undefined;
1526
let authorFieldId = undefined;
27+
let priorityField = {
28+
id: undefined,
29+
options: {
30+
p0: undefined,
31+
p1: undefined,
32+
p2: undefined,
33+
p3: undefined,
34+
},
35+
};
36+
1637
for (const field of projectInfo.data.repository.projectV2.fields.nodes) {
1738
if (field.name === 'Create date') {
1839
createFieldId = field.id;
@@ -23,6 +44,24 @@ export const projectIds = async (github: Github) : Promise<{
2344
if (field.name === 'Item author') {
2445
authorFieldId = field.id;
2546
}
47+
if (field.name === 'Priority') {
48+
priorityField.id = field.id;
49+
for (const option of field.options) {
50+
switch (option.name) {
51+
case 'P0':
52+
priorityField.options.p0 = option.id;
53+
break;
54+
case 'P1':
55+
priorityField.options.p1 = option.id;
56+
break;
57+
case 'P2':
58+
priorityField.options.p2 = option.id;
59+
break;
60+
case 'P3':
61+
priorityField.options.p3 = option.id;
62+
}
63+
}
64+
}
2665
}
2766

2867
if (createFieldId === undefined) {
@@ -37,10 +76,31 @@ export const projectIds = async (github: Github) : Promise<{
3776
throw new Error('Project field "Item author" not found');
3877
}
3978

79+
if (priorityField.id === undefined) {
80+
throw new Error('Project field "Priority" not found');
81+
}
82+
83+
for (const [priorityLabel, priorityProjectLabel] of Object.entries(PRIORITIES)) {
84+
if (priorityField.options[priorityLabel as keyof typeof PRIORITIES] === undefined) {
85+
throw new Error(`Project field "Priority" does not have a "${priorityProjectLabel}" option.`);
86+
}
87+
}
88+
4089
return {
4190
projectId,
4291
createFieldId,
4392
updateFieldId,
4493
authorFieldId,
94+
priorityField: priorityField as any,
4595
};
4696
};
97+
98+
export const getPriorityFromLabels = (labels: any[], priorityField: { options: Record<keyof typeof PRIORITIES, string> }): string | undefined => {
99+
for (const label of labels) {
100+
const labelName = label.name.toLowerCase();
101+
if (labelName in PRIORITIES && priorityField.options[labelName as keyof typeof PRIORITIES]) {
102+
return priorityField.options[labelName as keyof typeof PRIORITIES];
103+
}
104+
}
105+
return undefined;
106+
};

tools/@aws-cdk/project-sync/test/issue-sync.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ describe('Issue Sync', () => {
3030
PVTF_lADOACIPmc4A7TlPzgvqxXA: { date: new Date('2021-08-04T15:40:27Z') },
3131
PVTF_lADOACIPmc4A7TlPzgv350s: { date: new Date('2025-06-30T15:47:05Z') },
3232
PVTF_lADOACIPmc4A7TlPzgyBz60: { text: 'naseemkullah' },
33+
PVTSSF_lADOACIPmc4A7TlPzgvpNe8: { singleSelectOptionId: '0a877460' },
3334
});
3435
});
3536

@@ -43,8 +44,9 @@ describe('Issue Sync', () => {
4344
// and the expected creation and update dates
4445
expect(mockGithub.setProjectItem).toHaveBeenCalledWith('PVT_kwDOACIPmc4A7TlP', 'PVTI_lADOACIPmc4A7TlPzgbamKo', {
4546
PVTF_lADOACIPmc4A7TlPzgvqxXA: { date: new Date('2024-07-09T08:10:25Z') },
46-
PVTF_lADOACIPmc4A7TlPzgv350s: { date: new Date('2025-07-08T15:43:28Z') },
47+
PVTF_lADOACIPmc4A7TlPzgv350s: { date: new Date('2025-07-25T16:56:19Z') },
4748
PVTF_lADOACIPmc4A7TlPzgyBz60: { text: 'greg5123334' },
49+
PVTSSF_lADOACIPmc4A7TlPzgvpNe8: { singleSelectOptionId: '0a877460' },
4850
});
4951
});
5052

@@ -60,6 +62,7 @@ describe('Issue Sync', () => {
6062
PVTF_lADOACIPmc4A7TlPzgvqxXA: { date: new Date('2025-01-28T09:56:52Z') },
6163
PVTF_lADOACIPmc4A7TlPzgv350s: { date: new Date('2025-06-12T16:00:02Z') },
6264
PVTF_lADOACIPmc4A7TlPzgyBz60: { text: 'aubsamai' },
65+
PVTSSF_lADOACIPmc4A7TlPzgvpNe8: { singleSelectOptionId: '0a877460' },
6366
});
6467
});
6568

tools/@aws-cdk/project-sync/test/pr-sync.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ describe('PR Sync', () => {
2828
// and the expected creation and update dates
2929
expect(mockGithub.setProjectItem).toHaveBeenCalledWith('PVT_kwDOACIPmc4A7TlP', 'PVTI_lADOACIPmc4A7TlPzgceg5g', {
3030
PVTF_lADOACIPmc4A7TlPzgvqxXA: { date: new Date('2025-07-11T04:45:56Z') },
31-
PVTF_lADOACIPmc4A7TlPzgv350s: { date: new Date('2025-07-19T01:34:52Z') },
31+
PVTF_lADOACIPmc4A7TlPzgv350s: { date: new Date('2025-08-07T06:44:13Z') },
3232
PVTF_lADOACIPmc4A7TlPzgyBz60: { text: 'badmintoncryer' },
33+
PVTSSF_lADOACIPmc4A7TlPzgvpNe8: {
34+
singleSelectOptionId: 'da944a9c',
35+
},
3336
});
3437
});
3538
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"data":{"repository":{"issue":{"createdAt":"2021-08-04T15:40:27Z","author":{"login":"naseemkullah"},"timelineItems":{"nodes":[{},{},{"createdAt":"2025-05-01T13:54:36Z","author":{"login":"hassanazharkhan"}},{"createdAt":"2025-05-01T14:18:48Z","author":{"login":"hassanazharkhan"}},{"createdAt":"2025-05-01T15:49:47Z","author":{"login":"chase-robbins"}},{"createdAt":"2025-05-01T22:14:06Z","author":{"login":"SimonCMoore"}},{},{"createdAt":"2025-05-02T15:55:16Z","author":{"login":"dgcole"}},{"createdAt":"2025-06-27T13:16:35Z","actor":{"login":"Abogical"}},{},{"createdAt":"2025-06-30T15:47:05Z","actor":{"login":"Abogical"}},{},{},{},{},{}]},"reactions":{"nodes":[{"createdAt":"2025-05-01T18:36:05Z"}]},"projectItems":{"nodes":[{"id":"PVTI_lADOACIPmc4AFShhzgCNksA","project":{"number":65}},{"id":"PVTI_lADOACIPmc4A7TlPzgbanR8","project":{"number":302}}]}}}}}
1+
{"data":{"repository":{"issue":{"createdAt":"2021-08-04T15:40:27Z","author":{"login":"naseemkullah"},"labels":{"nodes":[{"name":"bug"},{"name":"p1"},{"name":"@aws-cdk/aws-cloudfront"},{"name":"@aws-cdk/aws-s3-deployment"}]},"timelineItems":{"nodes":[{"createdAt":"2025-05-01T13:54:36Z","author":{"login":"hassanazharkhan"}},{"createdAt":"2025-05-01T14:18:48Z","author":{"login":"hassanazharkhan"}},{"createdAt":"2025-05-01T15:49:47Z","author":{"login":"chase-robbins"}},{"createdAt":"2025-05-01T22:14:06Z","author":{"login":"SimonCMoore"}},{},{"createdAt":"2025-05-02T15:55:16Z","author":{"login":"dgcole"}},{"createdAt":"2025-06-27T13:16:35Z","actor":{"login":"Abogical"}},{},{"createdAt":"2025-06-30T15:47:05Z","actor":{"login":"Abogical"}},{},{},{},{},{},{},{}]},"reactions":{"nodes":[{"createdAt":"2025-05-01T18:36:05Z"}]},"projectItems":{"nodes":[{"id":"PVTI_lADOACIPmc4AFShhzgCNksA","project":{"number":65}},{"id":"PVTI_lADOACIPmc4A7TlPzgbanR8","project":{"number":302}}]}}}}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"data":{"repository":{"issue":{"createdAt":"2024-07-09T08:10:25Z","author":{"login":"greg5123334"},"timelineItems":{"nodes":[{"createdAt":"2025-03-26T23:22:30Z","author":{"login":"pahud"}},{"createdAt":"2025-03-26T23:22:37Z","actor":{"login":"pahud"}},{"createdAt":"2025-03-26T23:22:42Z","actor":{"login":"pahud"}},{"createdAt":"2025-04-02T09:25:32Z","author":{"login":"TheHolyWaffle"}},{},{},{},{},{},{},{"createdAt":"2025-05-09T22:39:35Z","actor":{"login":"QuantumNeuralCoder"}},{},{},{"createdAt":"2025-06-19T08:38:33Z","author":{"login":"Reiss-Cashmore"}},{"createdAt":"2025-07-08T15:43:28Z","author":{"login":"CharlesJones88"}},{}]},"reactions":{"nodes":[{"createdAt":"2025-07-07T08:56:57Z"}]},"projectItems":{"nodes":[{"id":"PVTI_lADOACIPmc4Av_32zgYvp8Y","project":{"number":263}},{"id":"PVTI_lADOACIPmc4A7TlPzgbamKo","project":{"number":302}}]}}}}}
1+
{"data":{"repository":{"issue":{"createdAt":"2024-07-09T08:10:25Z","author":{"login":"greg5123334"},"labels":{"nodes":[{"name":"bug"},{"name":"p1"},{"name":"@aws-cdk/aws-dynamodb"},{"name":"effort/small"}]},"timelineItems":{"nodes":[{"createdAt":"2025-03-26T23:22:42Z","actor":{"login":"pahud"}},{"createdAt":"2025-04-02T09:25:32Z","author":{"login":"TheHolyWaffle"}},{},{},{},{},{},{},{"createdAt":"2025-05-09T22:39:35Z","actor":{"login":"QuantumNeuralCoder"}},{},{},{"createdAt":"2025-06-19T08:38:33Z","author":{"login":"Reiss-Cashmore"}},{"createdAt":"2025-07-08T15:43:28Z","author":{"login":"CharlesJones88"}},{},{"createdAt":"2025-07-25T16:56:19Z","actor":{"login":"pahud"}},{}]},"reactions":{"nodes":[{"createdAt":"2025-07-24T15:18:18Z"}]},"projectItems":{"nodes":[{"id":"PVTI_lADOACIPmc4Av_32zgYvp8Y","project":{"number":263}},{"id":"PVTI_lADOACIPmc4A7TlPzgbamKo","project":{"number":302}}]}}}}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"data":{"repository":{"issue":{"createdAt":"2025-01-28T09:56:52Z","author":{"login":"aubsamai"},"timelineItems":{"nodes":[{"createdAt":"2025-05-20T14:07:47Z","author":{"login":"kumsmrit"}},{},{},{"createdAt":"2025-05-22T07:56:17Z","actor":{"login":"kumsmrit"}},{"createdAt":"2025-05-26T14:55:04Z","actor":{"login":"kumsmrit"}},{"createdAt":"2025-05-26T16:05:58Z","author":{"login":"github-actions"}},{"createdAt":"2025-05-26T16:05:59Z","actor":{"login":"github-actions"}},{},{"createdAt":"2025-05-31T20:05:40Z","actor":{"login":"github-actions"}},{"createdAt":"2025-05-31T20:21:39Z","actor":{"login":"github-actions"}},{"createdAt":"2025-06-12T16:00:02Z","actor":{"login":"kumsmrit"}},{"createdAt":"2025-06-12T16:06:30Z","author":{"login":"github-actions"}},{"createdAt":"2025-06-12T16:06:30Z","actor":{"login":"github-actions"}},{"createdAt":"2025-06-17T16:06:43Z","actor":{"login":"github-actions"}},{"createdAt":"2025-06-17T16:06:43Z","actor":{"login":"github-actions"}},{"createdAt":"2025-06-17T16:06:44Z","actor":{"login":"github-actions"}}]},"reactions":{"nodes":[]},"projectItems":{"nodes":[{"id":"PVTI_lADOACIPmc4AaumQzgWws_M","project":{"number":179}},{"id":"PVTI_lADOACIPmc4AbZkFzgWyTLQ","project":{"number":189}},{"id":"PVTI_lADOACIPmc4Av_32zgazLYE","project":{"number":263}},{"id":"PVTI_lADOACIPmc4A7TlPzgbamBo","project":{"number":302}}]}}}}}
1+
{"data":{"repository":{"issue":{"createdAt":"2025-01-28T09:56:52Z","author":{"login":"aubsamai"},"labels":{"nodes":[{"name":"bug"},{"name":"p1"},{"name":"@aws-cdk/core"},{"name":"response-requested"},{"name":"effort/small"},{"name":"closed-for-staleness"}]},"timelineItems":{"nodes":[{"createdAt":"2025-05-20T14:07:47Z","author":{"login":"kumsmrit"}},{},{},{"createdAt":"2025-05-22T07:56:17Z","actor":{"login":"kumsmrit"}},{"createdAt":"2025-05-26T14:55:04Z","actor":{"login":"kumsmrit"}},{"createdAt":"2025-05-26T16:05:58Z","author":{"login":"github-actions"}},{"createdAt":"2025-05-26T16:05:59Z","actor":{"login":"github-actions"}},{},{"createdAt":"2025-05-31T20:05:40Z","actor":{"login":"github-actions"}},{"createdAt":"2025-05-31T20:21:39Z","actor":{"login":"github-actions"}},{"createdAt":"2025-06-12T16:00:02Z","actor":{"login":"kumsmrit"}},{"createdAt":"2025-06-12T16:06:30Z","author":{"login":"github-actions"}},{"createdAt":"2025-06-12T16:06:30Z","actor":{"login":"github-actions"}},{"createdAt":"2025-06-17T16:06:43Z","actor":{"login":"github-actions"}},{"createdAt":"2025-06-17T16:06:43Z","actor":{"login":"github-actions"}},{"createdAt":"2025-06-17T16:06:44Z","actor":{"login":"github-actions"}}]},"reactions":{"nodes":[]},"projectItems":{"nodes":[{"id":"PVTI_lADOACIPmc4AaumQzgWws_M","project":{"number":179}},{"id":"PVTI_lADOACIPmc4AbZkFzgWyTLQ","project":{"number":189}},{"id":"PVTI_lADOACIPmc4Av_32zgazLYE","project":{"number":263}},{"id":"PVTI_lADOACIPmc4A7TlPzgbamBo","project":{"number":302}}]}}}}}

0 commit comments

Comments
 (0)