fix(scripts): preserve existing labels when auto-closing duplicate issues#76986
Open
AliAltivate wants to merge 1 commit into
Open
fix(scripts): preserve existing labels when auto-closing duplicate issues#76986AliAltivate wants to merge 1 commit into
AliAltivate wants to merge 1 commit into
Conversation
closeIssueAsDuplicate() closed the issue with a single PATCH whose body
included `labels: ['duplicate']`. GitHub's "Update an issue" endpoint
*replaces* the issue's entire label set with the array it receives
("Pass one or more labels to replace the set of labels on this issue"),
so every auto-closed duplicate had all of its triage labels (bug,
area:*, platform:*, priority, needs-info, ...) silently wiped, leaving
only `duplicate`.
Add the `duplicate` label via the "Add labels to an issue" endpoint
(POST /issues/{n}/labels), which appends to the existing labels, and
drop `labels` from the PATCH so it only closes the issue and sets
state_reason: 'duplicate'. The label is added before the close so a
partial failure leaves the issue open and retryable rather than closed
without its triage metadata.
Co-Authored-By: Claude <noreply@anthropic.com>
This was referenced Jul 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
scripts/auto-close-duplicates.tscloses each detected duplicate with a singlePATCH /repos/{owner}/{repo}/issues/{n}:Per GitHub's REST API, the Update an issue endpoint's
labelsfield replaces the full label set — docs: "Pass one or more labels to replace the set of labels on this issue."So every issue auto-closed as a duplicate has all of its other labels silently wiped (
bug,area:*,platform:*, priority,needs-info, …), leaving onlyduplicate. That destroys triage/analytics metadata on closed issues. This script runs in.github/workflows/auto-close-duplicates.yml.The fix
Add the
duplicatelabel with the Add labels to an issue endpoint (POST /issues/{n}/labels), which appends to the existing labels — docs: "the labels to add to the issue's existing labels" — and droplabelsfrom thePATCHso it only closes the issue and setsstate_reason: 'duplicate':The label is added before the close so a partial failure leaves the issue open and retryable, rather than closed without its triage metadata.
Verification
labelsreference in the file — single-site change.bun(the script's runtime).🤖 Generated with Claude Code