@@ -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