diff --git a/.github/workflows/pr-labeler.yml b/.github/workflows/pr-labeler.yml index f1954abc..86d54279 100644 --- a/.github/workflows/pr-labeler.yml +++ b/.github/workflows/pr-labeler.yml @@ -46,6 +46,32 @@ jobs: else if (changedLines > 9) label = 'size:S'; else label = 'size:XS'; + console.log("Fetching existing labels..."); + const labels = await github.rest.issues.listLabelsOnIssue({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + }); + + const sizeLabels = labels.data + .filter(label => label.name.startsWith('size:')) + .map(label => label.name); + + if (sizeLabels.length > 0) { + console.log(`Removing existing size labels: ${sizeLabels.join(', ')}`); + for (const label of sizeLabels) { + await github.rest.issues.removeLabel({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + name: label, + }); + } + console.log("Existing size labels removed."); + } else { + console.log("No existing size labels to remove."); + } + if (label) { console.log(`Applying label "${label}" to the pull request...`); await github.rest.issues.addLabels({