Skip to content

Alternate controls for FPS mode #64

Alternate controls for FPS mode

Alternate controls for FPS mode #64

Workflow file for this run

name: Issue Labeler
on:
issues:
types: [opened]
jobs:
labeler:
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Parse and label issue
uses: actions/github-script@v7
with:
script: |
const issue = context.payload.issue;
const title = issue.title;
const number = issue.number;
const repo = context.repo;
const labelsToAdd = new Set();
let newTitle = title;
// known mappings
const coreMappings = {
'bug': 'bug',
'feature request': 'feature-request',
'mg1': 'MG1/MG2',
'mg2': 'MG1/MG2',
'mgs2': 'MGS2',
'mgs3': 'MGS3'
};
// fetch existing labels in the repo
const repoLabelsResp = await github.rest.issues.listLabelsForRepo({
owner: repo.owner,
repo: repo.repo,
per_page: 100
});
const existingLabels = new Set(repoLabelsResp.data.map(l => l.name));
const tagRegex = /\[([^\]]+)\]/gi;
let match;
while ((match = tagRegex.exec(title)) !== null) {
const rawTag = match[1].trim();
// split on / | & and normalize
const parts = rawTag.split(/[/|&]/).map(s => s.trim().toLowerCase());
for (const part of parts) {
const mapped = coreMappings[part] || match[1].trim();
if (existingLabels.has(mapped)) {
labelsToAdd.add(mapped);
} else {
console.log(`⚠️ Skipping unknown label: ${mapped}`);
}
}
// remove tag text from title
newTitle = newTitle.replace(match[0], '').trim();
}
// clean up leading colon and spaces
newTitle = newTitle.replace(/^[:\s]+/, '').trim();
if (labelsToAdd.size > 0) {
console.log(`✅ Adding labels: ${Array.from(labelsToAdd).join(', ')}`);
await github.rest.issues.addLabels({
...repo,
issue_number: number,
labels: Array.from(labelsToAdd)
});
} else {
console.log(`ℹ️ No known labels to add`);
}
if (newTitle !== title) {
console.log(`✏️ Updating title: "${newTitle}"`);
await github.rest.issues.update({
...repo,
issue_number: number,
title: newTitle
});
} else {
console.log(`ℹ️ Title unchanged`);
}