Skip to content

Commit 0d4e5f4

Browse files
authored
Auto assign issues based on component:* label (#2063)
1 parent eaafa46 commit 0d4e5f4

File tree

2 files changed

+78
-3
lines changed

2 files changed

+78
-3
lines changed

.github/component_owners.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
# this file is used by .github/workflows/assign-reviewers.yml
1+
# this file is used by .github/workflows/assign-reviewers.yml and .github/workflows/assign-issue-owners.yml
22
#
33
# NOTE component owners must be members of the GitHub OpenTelemetry organization
44
# so that they can be added to @open-telemetry/java-contrib-triagers
5-
# which in turn is required for them to be auto-assigned as reviewers by the automation
5+
# which in turn is required for them to be auto-assigned as reviewers and issue assignees by the automation
66
#
77
# NOTE when updating this file, don't forget to update the README.md files in the associated
88
# components also
99
#
1010
# NOTE when adding/updating one of the component names, don't forget to update the associated
11-
# `comp:*` labels
11+
# `component:*` labels (used for both PR reviews and issue assignment)
1212
components:
1313
aws-resources:
1414
- wangzlei
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
name: Assign issue owners
3+
4+
on:
5+
issues:
6+
types: [labeled]
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
assign-owners:
13+
permissions:
14+
contents: read
15+
issues: write
16+
runs-on: ubuntu-latest
17+
if: startsWith(github.event.label.name, 'component:')
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
21+
22+
- name: Parse component label and assign owners
23+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
24+
with:
25+
script: |
26+
const fs = require('fs');
27+
const yaml = require('js-yaml');
28+
29+
// Extract component name from label
30+
const labelName = context.payload.label.name;
31+
32+
if (!labelName.startsWith('component:')) {
33+
core.setFailed('Label does not match expected pattern');
34+
return;
35+
}
36+
37+
const componentName = labelName.replace('component:', '');
38+
console.log(`Processing component: ${componentName}`);
39+
40+
// Read and parse component_owners.yml
41+
const yamlContent = fs.readFileSync('.github/component_owners.yml', 'utf8');
42+
const data = yaml.load(yamlContent);
43+
44+
if (!data || !data.components) {
45+
core.setFailed('Invalid component_owners.yml structure');
46+
return;
47+
}
48+
49+
const components = data.components;
50+
51+
if (!(componentName in components)) {
52+
core.setFailed(`Component '${componentName}' not found in component_owners.yml`);
53+
return;
54+
}
55+
56+
const owners = components[componentName];
57+
58+
if (!owners || owners.length === 0) {
59+
core.setFailed(`No owners found for component '${componentName}'`);
60+
return;
61+
}
62+
63+
console.log(`Found owners: ${owners.join(', ')}`);
64+
65+
// Assign the issue to the owners
66+
const issueNumber = context.payload.issue.number;
67+
68+
await github.rest.issues.addAssignees({
69+
owner: context.repo.owner,
70+
repo: context.repo.repo,
71+
issue_number: issueNumber,
72+
assignees: owners
73+
});
74+
75+
console.log(`Successfully assigned issue #${issueNumber} to ${owners.join(', ')}`);

0 commit comments

Comments
 (0)