Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 75 additions & 8 deletions .github/workflows/reusable-issue-triage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,25 +108,59 @@ jobs:
uses: actions/github-script@v8
env:
AI_RESPONSE: ${{ steps.ai-triage.outputs.response }}
AVAILABLE_LABELS: ${{ env.AVAILABLE_LABELS }}
with:
script: |
const response = process.env.AI_RESPONSE;
const availableLabelsStr = process.env.AVAILABLE_LABELS;

if (!response || response.trim() === '') {
console.log('No labels selected by AI');
return;
}

const labels = response.replaceAll('```', '').split(',')
if (!availableLabelsStr) {
console.log('No available labels found');
return;
}

// Parse available labels (normalized to lowercase)
const availableLabels = availableLabelsStr.split(',')
.map(l => l.trim().toLowerCase())
.filter(l => l.length > 0);

// Parse AI suggested labels
const suggestedLabels = response.replaceAll('```', '').split(',')
.map(l => l.trim())
.filter(l => l.length > 0);

if (labels.length > 0) {
console.log(`Applying labels: ${labels.join(', ')}`);
// Partition into valid and invalid in a single pass
const { validLabels, invalidLabels } = suggestedLabels.reduce(
(acc, label) => {
if (availableLabels.includes(label.toLowerCase())) {
acc.validLabels.push(label);
} else {
acc.invalidLabels.push(label);
}
return acc;
},
{ validLabels: [], invalidLabels: [] }
);

// Log any invalid labels
if (invalidLabels.length > 0) {
console.log(
`Skipping invalid labels: ${invalidLabels.join(', ')}`
);
}

if (validLabels.length > 0) {
console.log(`Applying labels: ${validLabels.join(', ')}`);
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: labels
labels: validLabels
});
} else {
console.log('No valid labels to apply');
Expand Down Expand Up @@ -317,27 +351,60 @@ jobs:
env:
AI_RESPONSE: ${{ steps.ai-triage.outputs.response }}
ITEM_NUMBER: ${{ inputs.issue_number }}
AVAILABLE_LABELS: ${{ env.AVAILABLE_LABELS }}
with:
script: |
const response = process.env.AI_RESPONSE;
const itemNumber = parseInt(process.env.ITEM_NUMBER);
const availableLabelsStr = process.env.AVAILABLE_LABELS;

if (!response || response.trim() === '') {
console.log('No labels selected by AI');
return;
}

const labels = response.replaceAll('```', '').split(',')
if (!availableLabelsStr) {
console.log('No available labels found');
return;
}

// Parse available labels (normalized to lowercase)
const availableLabels = availableLabelsStr.split(',')
.map(l => l.trim().toLowerCase())
.filter(l => l.length > 0);

// Parse AI suggested labels
const suggestedLabels = response.replaceAll('```', '').split(',')
.map(l => l.trim())
.filter(l => l.length > 0);

if (labels.length > 0) {
console.log(`Applying labels: ${labels.join(', ')}`);
// Partition into valid and invalid in a single pass
const { validLabels, invalidLabels } = suggestedLabels.reduce(
(acc, label) => {
if (availableLabels.includes(label.toLowerCase())) {
acc.validLabels.push(label);
} else {
acc.invalidLabels.push(label);
}
return acc;
},
{ validLabels: [], invalidLabels: [] }
);

// Log any invalid labels
if (invalidLabels.length > 0) {
console.log(
`Skipping invalid labels: ${invalidLabels.join(', ')}`
);
}

if (validLabels.length > 0) {
console.log(`Applying labels: ${validLabels.join(', ')}`);
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: itemNumber,
labels: labels
labels: validLabels
});
} else {
console.log('No valid labels to apply');
Expand Down