Apply Component Labels #29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Apply Component Labels | |
| on: | |
| issues: | |
| types: [opened, edited] | |
| jobs: | |
| label-issues: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| issues: write | |
| steps: | |
| - name: Check for Component Selection | |
| uses: actions/github-script@v6 | |
| with: | |
| script: | | |
| const { issue, repository } = context.payload; | |
| const componentMap = { | |
| "UI": "component:ui", | |
| "API Gateway": "component:api-gateway", | |
| "Upload Orchestrator": "component:upload-orchestrator", | |
| "Metadata Service": "component:metadata-service", | |
| "Storage Service": "component:storage-service", | |
| "Log Processor": "components:log-processor", | |
| "Query Service": "components:query-service", | |
| "Analytics Service": "components:analytics-service", | |
| "CLI": "components:cli" | |
| }; | |
| // Extract component field from issue body - handles both single and multiple selections | |
| const componentMatch = issue.body.match(/### Component\n\n(.*?)(?=\n###|\n\n###|$)/s); | |
| if (!componentMatch) { | |
| console.log('No component field found in issue body'); | |
| return; | |
| } | |
| const componentText = componentMatch[1].trim(); | |
| console.log('Component text found:', componentText); | |
| // Parse selected components (handles both dropdown and comma-separated values) | |
| let selectedComponents = []; | |
| // Check if it's a dropdown selection (single line) | |
| if (componentText.includes('\n') === false && componentMap[componentText]) { | |
| selectedComponents = [componentText]; | |
| } else { | |
| // Handle multiple components - split by comma, newline, or bullet points | |
| selectedComponents = componentText | |
| .split(/[,\n•\-\*]/) | |
| .map(comp => comp.trim()) | |
| .filter(comp => comp && componentMap[comp]); | |
| } | |
| console.log('Selected components:', selectedComponents); | |
| if (selectedComponents.length === 0) { | |
| console.log('No valid components found'); | |
| return; | |
| } | |
| // Remove all existing component labels | |
| const currentLabels = issue.labels.map(label => label.name); | |
| const componentLabels = currentLabels.filter(label => label.startsWith('component:')); | |
| console.log('Removing existing component labels:', componentLabels); | |
| for (const label of componentLabels) { | |
| try { | |
| await github.rest.issues.removeLabel({ | |
| issue_number: issue.number, | |
| owner: repository.owner.login, | |
| repo: repository.name, | |
| name: label | |
| }); | |
| } catch (error) { | |
| console.log(`Failed to remove label ${label}:`, error.message); | |
| } | |
| } | |
| // Add new component labels | |
| const newLabels = selectedComponents.map(comp => componentMap[comp]).filter(Boolean); | |
| console.log('Adding new component labels:', newLabels); | |
| if (newLabels.length > 0) { | |
| try { | |
| await github.rest.issues.addLabels({ | |
| issue_number: issue.number, | |
| owner: repository.owner.login, | |
| repo: repository.name, | |
| labels: newLabels | |
| }); | |
| console.log('Successfully added labels:', newLabels); | |
| } catch (error) { | |
| console.log('Failed to add labels:', error.message); | |
| } | |
| } |