diff --git a/.github/workflows/pr-size-check.yml b/.github/workflows/pr-size-check.yml index 670a11587ea9d5b39079a38b11eccb813b4e9e7f..940c619e0cfd308728b24c42264a580d6e93592c 100644 --- a/.github/workflows/pr-size-check.yml +++ b/.github/workflows/pr-size-check.yml @@ -11,12 +11,9 @@ name: PR Size Check on: - pull_request_target: + pull_request: types: [opened, synchronize] -permissions: - contents: read - jobs: check-size: if: github.repository_owner == 'zed-industries' @@ -74,15 +71,18 @@ jobs: } } - // Remove existing size labels, then apply the current one + // Update size label only if the classification changed const existingLabels = (await github.rest.issues.listLabelsOnIssue({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number, })).data.map(l => l.name); - for (const label of existingLabels) { - if (label.startsWith('size/')) { + const existingSizeLabels = existingLabels.filter(l => l.startsWith('size/')); + const alreadyCorrect = existingSizeLabels.length === 1 && existingSizeLabels[0] === sizeLabel; + + if (!alreadyCorrect) { + for (const label of existingSizeLabels) { await github.rest.issues.removeLabel({ owner: context.repo.owner, repo: context.repo.repo, @@ -90,27 +90,27 @@ jobs: name: label, }); } - } - // Create the label if it doesn't exist (ignore 422 = already exists) - try { - await github.rest.issues.createLabel({ + // Create the label if it doesn't exist (ignore 422 = already exists) + try { + await github.rest.issues.createLabel({ + owner: context.repo.owner, + repo: context.repo.repo, + name: sizeLabel, + color: labelColor, + }); + } catch (e) { + if (e.status !== 422) throw e; + } + + await github.rest.issues.addLabels({ owner: context.repo.owner, repo: context.repo.repo, - name: sizeLabel, - color: labelColor, + issue_number: context.issue.number, + labels: [sizeLabel], }); - } catch (e) { - if (e.status !== 422) throw e; } - await github.rest.issues.addLabels({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.issue.number, - labels: [sizeLabel], - }); - // For large PRs (400+ LOC): auto-apply large-pr label and comment once if (totalChanges >= 400) { // Auto-apply the large-pr label