fix(repo): archive after the other edits in repo edit

Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
bircni committed 2026-10-12 20:35:08 +02:00
1 parent 1fa954b74b
commit f51af883c6
2 files changed
+33 -1

No files matched your search

+10 -1
View File
@@ -171,7 +171,11 @@ $ tea repo edit --default-merge-style squash --add-topic cli --add-topic go`,
return err return err
} }
} }
repo := t.Repo // Gitea refuses topic changes on an archived repository, so archiving comes last.
repo, archive := t.Repo, options.Archived != nil && *options.Archived
if archive {
options.Archived = nil
}
if options != (services.RepositoryEdit{}) { if options != (services.RepositoryEdit{}) {
item, err := service.Edit(cmd.Context(), t.Repo, options) item, err := service.Edit(cmd.Context(), t.Repo, options)
if err != nil { if err != nil {
@@ -189,6 +193,11 @@ $ tea repo edit --default-merge-style squash --add-topic cli --add-topic go`,
return fmt.Errorf("remove topic %q: %w", topic, err) return fmt.Errorf("remove topic %q: %w", topic, err)
} }
} }
if archive {
if _, err := service.Edit(cmd.Context(), repo, services.RepositoryEdit{Archived: &archive}); err != nil {
return err
}
}
var edited []string var edited []string
local := cmd.LocalFlags() local := cmd.LocalFlags()
cmd.Flags().Visit(func(flag *pflag.Flag) { cmd.Flags().Visit(func(flag *pflag.Flag) {
+23
View File
@@ -5,7 +5,9 @@ package app
import ( import (
"context" "context"
"io"
"net/http" "net/http"
"strings"
"testing" "testing"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@@ -63,3 +65,24 @@ func TestRepositoryEditReportsTheChangedSettings(t *testing.T) {
require.Empty(t, out.String()) require.Empty(t, out.String())
require.Equal(t, "✓ Edited repository alice/project (add-topic, description, remove-topic, visibility)\n", diagnostics.String()) require.Equal(t, "✓ Edited repository alice/project (add-topic, description, remove-topic, visibility)\n", diagnostics.String())
} }
func TestRepositoryEditArchivesAfterTheOtherChanges(t *testing.T) {
var requests []string
server := newAuthenticatedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
data, _ := io.ReadAll(r.Body)
request := r.Method + " " + r.URL.Path
if strings.Contains(string(data), `"archived":true`) {
request += " archived"
}
requests = append(requests, request)
_, _ = w.Write([]byte(`{"full_name":"alice/project"}`))
}))
defer server.Close()
deps, _, _ := serverDeps(t, server.URL)
require.NoError(t, Execute(context.Background(), deps, []string{"repo", "edit", "alice/project", "-d", "CLI", "--archived", "--add-topic", "cli", "--yes"}))
require.Equal(t, []string{
"PATCH /api/v1/repos/alice/project",
"PUT /api/v1/repos/alice/project/topics/cli",
"PATCH /api/v1/repos/alice/project archived",
}, requests)
}