Toolbox missing some controls #16
This file contains 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: Add Labels Based on Selected Tools | |
on: | |
issues: | |
types: [opened] | |
permissions: | |
issues: write # Ensure the workflow has permission to write to issues | |
jobs: | |
add_labels: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check and add tool-specific labels | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const issueBody = context.payload.issue.body; | |
console.log("Issue Body:", issueBody); | |
// Refined regex to capture selected tools | |
const toolsField = issueBody.match(/### Which tool\(s\) are affected\?\n([\s\S]*?)\n###/); | |
const toolsRaw = toolsField ? toolsField[1] : ''; | |
console.log("Raw Tools Field:", toolsRaw); | |
// Split tools by ',' and clean up whitespace | |
const tools = toolsRaw.split(',').map(tool => tool.trim()).filter(tool => tool !== "_No response_"); | |
console.log("Parsed Tools:", tools); | |
// Define labels to add based on the selected tools | |
const labelsToAdd = []; | |
if (tools.includes("Hot Design™")) { | |
labelsToAdd.push("tool/Hot Design™"); | |
} | |
if (tools.includes("Hot Reload")) { | |
labelsToAdd.push("tool/Hot Reload"); | |
} | |
if (tools.includes("Design-to-Code")) { | |
labelsToAdd.push("tool/Design-to-Code"); | |
} | |
// Add the labels to the issue if any were matched | |
if (labelsToAdd.length > 0) { | |
console.log("Adding Labels:", labelsToAdd); | |
await github.rest.issues.addLabels({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.payload.issue.number, | |
labels: labelsToAdd, | |
}); | |
} else { | |
console.log("No matching labels to add."); | |
} |