Skip to content

Commit 9959a9e

Browse files
authored
chore: add workflow to auto add p1 bugs to project board (#33205)
### Issue # (if applicable) N/A. ### Reason for this change N/A ### Description of changes Adding a github workflow that get triggered whenever an issue has a label added to it. ### Description of how you validated changes Tested the flow in another private repo and board. ### 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 1b35c4e commit 9959a9e

File tree

3 files changed

+79
-2
lines changed

3 files changed

+79
-2
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: P1 Bug Prioritization
2+
on:
3+
issues:
4+
types:
5+
- labeled
6+
7+
jobs:
8+
prioritize:
9+
if: github.repository == 'aws/aws-cdk' && contains(github.event.issue.labels.*.name, 'bug') && contains(github.event.issue.labels.*.name, 'p1')
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- name: Add P1 Bug to project
14+
uses: actions/github-script@v7
15+
with:
16+
github-token: ${{ secrets.PROJEN_GITHUB_TOKEN }}
17+
script: |
18+
const script = require('./scripts/prioritization/assign-bug-priority.js')
19+
await script({github, context})
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const { PRIORITIES, LABELS, STATUS, ...PROJECT_CONFIG } = require('./project-config');
2+
const {
3+
updateProjectField,
4+
addItemToProject,
5+
fetchProjectFields,
6+
} = require('./project-api');
7+
8+
module.exports = async ({ github, context }) => {
9+
async function addToProject(issue) {
10+
console.log(`Processing issue #${issue.number}...`);
11+
12+
// Get project fields
13+
const projectFields = await fetchProjectFields({
14+
github,
15+
org: PROJECT_CONFIG.org,
16+
number: PROJECT_CONFIG.projectNumber
17+
});
18+
const priorityField = projectFields.organization.projectV2.fields.nodes.find(
19+
(field) => field.id === PROJECT_CONFIG.priorityFieldId
20+
);
21+
22+
const addResult = await addItemToProject({
23+
github,
24+
projectId: PROJECT_CONFIG.projectId,
25+
contentId: issue.node_id,
26+
});
27+
28+
const itemId = addResult.addProjectV2ItemById.item.id;
29+
30+
const priorityR6OptionId = priorityField.options.find(
31+
(option) => option.name === PRIORITIES.R6
32+
)?.id;
33+
34+
if (!priorityR6OptionId) {
35+
throw new Error(`Cannot find Id of the R6 priority option.
36+
Found: ${priorityField.options.map(op => op.name)}`);
37+
}
38+
39+
await updateProjectField({
40+
github,
41+
projectId: PROJECT_CONFIG.projectId,
42+
itemId: itemId,
43+
fieldId: PROJECT_CONFIG.priorityFieldId,
44+
value: priorityR6OptionId,
45+
});
46+
}
47+
48+
const issue = context.payload.issue;
49+
const labels = issue.labels.map((l) => l.name);
50+
if (labels.includes(LABELS.P1) && labels.includes(LABELS.BUG)) {
51+
await addToProject(issue);
52+
} else {
53+
// do nothing
54+
}
55+
};

scripts/prioritization/project-config.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@ const LABELS = {
33
MAINTAINER_REVIEW: 'pr/needs-maintainer-review',
44
COMMUNITY_REVIEW: 'pr/needs-community-review',
55
CLARIFICATION_REQUESTED: 'pr/reviewer-clarification-requested',
6-
EXEMPTION_REQUESTED: 'pr-linter/exemption-requested'
6+
EXEMPTION_REQUESTED: 'pr-linter/exemption-requested',
7+
P1: 'p1',
8+
BUG: 'bug'
79
};
810

911
const PRIORITIES = {
1012
R1: '🚨 R1',
1113
R2: '🔥 R2',
1214
R3: '🎯 R3',
1315
R4: '💭 R4',
14-
R5: '📆 R5'
16+
R5: '📆 R5',
17+
R6: '🐛 R6'
1518
};
1619

1720
const STATUS = {

0 commit comments

Comments
 (0)