Skip to content

Commit fb02cfa

Browse files
committed
chore: Issue template can have multiple components
1 parent ba7c760 commit fb02cfa

4 files changed

Lines changed: 63 additions & 19 deletions

File tree

.github/ISSUE_TEMPLATE/bug.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ body:
2222
id: component
2323
attributes:
2424
label: "Component"
25+
multiple: true
2526
options:
2627
- "UI"
2728
- "API Gateway"

.github/ISSUE_TEMPLATE/chore.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ body:
1717
id: component
1818
attributes:
1919
label: "Component"
20+
multiple: true
2021
options:
2122
- "UI"
2223
- "API Gateway"

.github/ISSUE_TEMPLATE/feature.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ body:
2424
id: component
2525
attributes:
2626
label: "Component"
27+
multiple: true
2728
options:
2829
- "UI"
2930
- "API Gateway"

.github/workflows/apply-component-label.yml

Lines changed: 60 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,70 @@ jobs:
2626
"CLI": "components:cli"
2727
};
2828
29-
// Get selected component from form (if any)
30-
const componentField = issue.body.match(/### Component\n\n(.*?)(\n|$)/)?.[1]?.trim();
31-
const componentLabel = componentMap[componentField];
29+
// Extract component field from issue body - handles both single and multiple selections
30+
const componentMatch = issue.body.match(/### Component\n\n(.*?)(?=\n###|\n\n###|$)/s);
31+
if (!componentMatch) {
32+
console.log('No component field found in issue body');
33+
return;
34+
}
35+
36+
const componentText = componentMatch[1].trim();
37+
console.log('Component text found:', componentText);
38+
39+
// Parse selected components (handles both dropdown and comma-separated values)
40+
let selectedComponents = [];
41+
42+
// Check if it's a dropdown selection (single line)
43+
if (componentText.includes('\n') === false && componentMap[componentText]) {
44+
selectedComponents = [componentText];
45+
} else {
46+
// Handle multiple components - split by comma, newline, or bullet points
47+
selectedComponents = componentText
48+
.split(/[,\n•\-\*]/)
49+
.map(comp => comp.trim())
50+
.filter(comp => comp && componentMap[comp]);
51+
}
3252
33-
// Remove existing component labels
53+
console.log('Selected components:', selectedComponents);
54+
55+
if (selectedComponents.length === 0) {
56+
console.log('No valid components found');
57+
return;
58+
}
59+
60+
// Remove all existing component labels
3461
const currentLabels = issue.labels.map(label => label.name);
3562
const componentLabels = currentLabels.filter(label => label.startsWith('component:'));
3663
37-
if (componentLabels.length > 0) {
38-
await github.rest.issues.removeLabel({
39-
issue_number: issue.number,
40-
owner: repository.owner.login,
41-
repo: repository.name,
42-
name: componentLabels[0]
43-
});
64+
console.log('Removing existing component labels:', componentLabels);
65+
66+
for (const label of componentLabels) {
67+
try {
68+
await github.rest.issues.removeLabel({
69+
issue_number: issue.number,
70+
owner: repository.owner.login,
71+
repo: repository.name,
72+
name: label
73+
});
74+
} catch (error) {
75+
console.log(`Failed to remove label ${label}:`, error.message);
76+
}
4477
}
4578
46-
// Add new component label
47-
if (componentLabel) {
48-
await github.rest.issues.addLabels({
49-
issue_number: issue.number,
50-
owner: repository.owner.login,
51-
repo: repository.name,
52-
labels: [componentLabel]
53-
});
79+
// Add new component labels
80+
const newLabels = selectedComponents.map(comp => componentMap[comp]).filter(Boolean);
81+
console.log('Adding new component labels:', newLabels);
82+
83+
if (newLabels.length > 0) {
84+
try {
85+
await github.rest.issues.addLabels({
86+
issue_number: issue.number,
87+
owner: repository.owner.login,
88+
repo: repository.name,
89+
labels: newLabels
90+
});
91+
console.log('Successfully added labels:', newLabels);
92+
} catch (error) {
93+
console.log('Failed to add labels:', error.message);
94+
}
5495
}

0 commit comments

Comments
 (0)