From 7df657116c7341faf9745891d65c8914a95e07b8 Mon Sep 17 00:00:00 2001 From: leo <80651389+civilwarinfrance@users.noreply.github.com> Date: Sat, 31 Oct 2026 09:31:55 -0700 Subject: [PATCH] fix(api): honor label archive options (#40008) Updating a label through the API without `is_archived`, for example to rename or recolor it, silently unarchived it. Creating an organization label also ignored `is_archived`. - Keep a label's archive state when a PATCH omits `is_archived`, for repository and organization labels - Honor `is_archived` when creating organization labels, as repository labels already do AI-assisted by Codex (GPT-6); prepared and tested by the assistant. --------- Co-authored-by: Hello-Liar <80651389+Hello-Liar@users.noreply.github.com> Co-authored-by: silverwind Co-authored-by: Giteabot --- routers/api/v1/org/label.go | 5 ++++- routers/api/v1/repo/label.go | 4 +++- tests/integration/api_issue_label_test.go | 8 ++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/routers/api/v1/org/label.go b/routers/api/v1/org/label.go index 77574e41d37..cb9497e097a 100644 --- a/routers/api/v1/org/label.go +++ b/routers/api/v1/org/label.go @@ -100,6 +100,7 @@ func CreateLabel(ctx *context.APIContext) { OrgID: ctx.Org.Organization.ID, Description: form.Description, } + label.SetArchived(form.IsArchived) if err := issues_model.NewLabel(ctx, label); err != nil { ctx.APIErrorInternal(err) return @@ -202,7 +203,9 @@ func EditLabel(ctx *context.APIContext) { if form.Description != nil { l.Description = *form.Description } - l.SetArchived(form.IsArchived != nil && *form.IsArchived) + if form.IsArchived != nil { + l.SetArchived(*form.IsArchived) + } if err := issues_model.UpdateLabel(ctx, l); err != nil { ctx.APIErrorInternal(err) return diff --git a/routers/api/v1/repo/label.go b/routers/api/v1/repo/label.go index ec29cf326bf..e77140b3563 100644 --- a/routers/api/v1/repo/label.go +++ b/routers/api/v1/repo/label.go @@ -224,7 +224,9 @@ func EditLabel(ctx *context.APIContext) { if form.Description != nil { l.Description = *form.Description } - l.SetArchived(form.IsArchived != nil && *form.IsArchived) + if form.IsArchived != nil { + l.SetArchived(*form.IsArchived) + } if err := issues_model.UpdateLabel(ctx, l); err != nil { ctx.APIErrorInternal(err) return diff --git a/tests/integration/api_issue_label_test.go b/tests/integration/api_issue_label_test.go index 01e32ead015..859a797162a 100644 --- a/tests/integration/api_issue_label_test.go +++ b/tests/integration/api_issue_label_test.go @@ -79,11 +79,13 @@ func TestAPIModifyLabels(t *testing.T) { // CreateLabel req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateLabelOption{ Name: "TestL 1", + IsArchived: true, Color: "abcdef", Description: "test label", }).AddTokenAuth(token) resp := MakeRequest(t, req, http.StatusCreated) apiLabel := DecodeJSON(t, resp, &api.Label{}) + assert.True(t, apiLabel.IsArchived) labelFilter.ID = apiLabel.ID dbLabel := unittest.AssertExistsAndLoadBean(t, labelFilter) assert.Equal(t, dbLabel.Name, apiLabel.Name) @@ -127,6 +129,12 @@ func TestAPIModifyLabels(t *testing.T) { resp = MakeRequest(t, req, http.StatusOK) apiLabel = DecodeJSON(t, resp, &api.Label{}) assert.Equal(t, newColor, apiLabel.Color) + assert.True(t, apiLabel.IsArchived) + req = NewRequestWithJSON(t, "PATCH", singleURLStr, &api.EditLabelOption{ + IsArchived: new(false), + }).AddTokenAuth(token) + resp = MakeRequest(t, req, http.StatusOK) + assert.False(t, DecodeJSON(t, resp, &api.Label{}).IsArchived) req = NewRequestWithJSON(t, "PATCH", singleURLStr, &api.EditLabelOption{ Color: &newColorWrong, }).AddTokenAuth(token)