mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
fix(label): refuse duplicate label names unless --force
tea label create --name bug twice created a second "bug" label, after which issue edit --add-labels bug failed as ambiguous and issue list --label bug matched nothing. label create (and --file imports) now fail with "label "bug" already exists in alice/project; pass --force to update it", ignoring case; --force updates the existing label. The ambiguity error for labels that already share a name lists their IDs. Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
5 files changed
+92
-10
No files matched your search
@@ -15,6 +15,10 @@ import (
|
||||
func TestLabelCreateAndEditExclusiveArchived(t *testing.T) {
|
||||
calls := 0
|
||||
server := newAuthenticatedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == http.MethodGet {
|
||||
_, _ = w.Write([]byte(`[]`))
|
||||
return
|
||||
}
|
||||
calls++
|
||||
var payload map[string]any
|
||||
require.NoError(t, json.NewDecoder(r.Body).Decode(&payload))
|
||||
@@ -47,3 +51,35 @@ func TestLabelCreateAndEditExclusiveArchived(t *testing.T) {
|
||||
require.Equal(t, 2, calls)
|
||||
require.Empty(t, diagnostics.String())
|
||||
}
|
||||
|
||||
func TestLabelCreateRefusesDuplicateNames(t *testing.T) {
|
||||
var changed []string
|
||||
server := newAuthenticatedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method + " " + r.URL.Path {
|
||||
case "GET /api/v1/repos/alice/project/labels":
|
||||
if r.URL.Query().Get("page") == "1" {
|
||||
_, _ = w.Write([]byte(`[{"id":11,"name":"bug","color":"ee0701","description":"Broken"}]`))
|
||||
return
|
||||
}
|
||||
_, _ = w.Write([]byte(`[]`))
|
||||
case "PATCH /api/v1/repos/alice/project/labels/11":
|
||||
requirePayload(t, `{"color":"000000"}`, r.Body)
|
||||
changed = append(changed, r.Method+" "+r.URL.Path)
|
||||
_, _ = w.Write([]byte(`{"id":11,"name":"bug","color":"000000","description":"Broken"}`))
|
||||
default:
|
||||
changed = append(changed, r.Method+" "+r.URL.Path)
|
||||
_, _ = w.Write([]byte(`{"id":12,"name":"docs"}`))
|
||||
}
|
||||
}))
|
||||
defer server.Close()
|
||||
deps, out, _ := serverDeps(t, server.URL)
|
||||
for _, name := range []string{"bug", "BUG"} {
|
||||
err := Execute(context.Background(), deps, []string{"label", "create", "-R", "alice/project", "--name", name, "--color", "000000"})
|
||||
require.EqualError(t, err, `label "bug" already exists in alice/project; pass --force to update it`)
|
||||
}
|
||||
require.Empty(t, changed)
|
||||
require.Empty(t, out.String())
|
||||
require.NoError(t, Execute(context.Background(), deps, []string{"label", "create", "-R", "alice/project", "--name", "bug", "--color", "000000", "--force", "--json=id,color"}))
|
||||
require.JSONEq(t, `{"id":11,"color":"000000"}`, out.String())
|
||||
require.Equal(t, []string{"PATCH /api/v1/repos/alice/project/labels/11"}, changed)
|
||||
}
|
||||
Reference in new issue
Block a user