Skip to content

uv scripts cluttering up the file system with venvs #391

uv scripts cluttering up the file system with venvs

uv scripts cluttering up the file system with venvs #391

name: Auto-label issues from Area checkbox
on:
issues:
types: [opened, edited]
permissions:
issues: write
jobs:
label-from-area:
runs-on: ubuntu-latest
steps:
- name: Apply labels based on Area checkboxes
uses: actions/github-script@v7
with:
script: |
const mapping = {
"datasets, data readers, data preparation and transfer": "data",
"model": "model",
"science": "science",
"infrastructure and engineering": "infra",
"evaluation, export and visualization": "eval",
"documentation": "documentation"
};
const issue = context.payload.issue;
const body = issue.body || "";
// Get current labels on the issue
const currentLabels = (issue.labels || []).map(l => l.name);
const labelsToAdd = new Set();
// Helper to escape regex special characters
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
// Detect checked checkboxes for each mapping key
for (const [areaText, labelName] of Object.entries(mapping)) {
// GitHub form markdown looks like: "- [x] model"
const pattern = new RegExp(`-\\s*\\[x\\]\\s*${escapeRegExp(areaText)}`, "i");
if (pattern.test(body)) {
labelsToAdd.add(labelName);
}
}
// If there is any "model:xxx" label, also add plain "model"
const hasModelVariant = currentLabels.some(l => /^model:.+$/i.test(l));
if (hasModelVariant) {
labelsToAdd.add("model");
}
// If there is any "data:xxx" label, also add plain "data"
const hasDataVariant = currentLabels.some(l => /^data:.+$/i.test(l));
if (hasDataVariant) {
labelsToAdd.add("data");
}
// Remove any labels that are already present so we don't duplicate
for (const label of currentLabels) {
if (labelsToAdd.has(label)) {
labelsToAdd.delete(label);
}
}
const finalLabels = Array.from(labelsToAdd);
if (finalLabels.length === 0) {
core.info("No new labels to add.");
return;
}
core.info(`Adding labels: ${finalLabels.join(", ")}`);
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels: finalLabels
});