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 <me@silverwind.io>
Co-authored-by: Giteabot <teabot@gitea.io>
This commit is contained in:
authored and GitHub committed 2026-10-31 17:31:55 +01:00
1 parent 9cd06bf57f
commit 7df657116c
3 files changed
+15 -2

No files matched your search

+4 -1
View File
@@ -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
+3 -1
View File
@@ -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
@@ -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)