mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
fix(repo): archive after the other edits in repo edit
Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
2 files changed
+33
-1
No files matched your search
@@ -171,7 +171,11 @@ $ tea repo edit --default-merge-style squash --add-topic cli --add-topic go`,
|
||||
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{}) {
|
||||
item, err := service.Edit(cmd.Context(), t.Repo, options)
|
||||
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)
|
||||
}
|
||||
}
|
||||
if archive {
|
||||
if _, err := service.Edit(cmd.Context(), repo, services.RepositoryEdit{Archived: &archive}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
var edited []string
|
||||
local := cmd.LocalFlags()
|
||||
cmd.Flags().Visit(func(flag *pflag.Flag) {
|
||||
|
||||
@@ -5,7 +5,9 @@ package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -63,3 +65,24 @@ func TestRepositoryEditReportsTheChangedSettings(t *testing.T) {
|
||||
require.Empty(t, out.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)
|
||||
}
|
||||
Reference in new issue
Block a user