mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
feat(repo): validate create templates, publish local projects, verify edits
repo create --license NOPE returned Gitea's HTTP 500 internals. License, .gitignore and label templates are now checked against the server's lists, case-insensitively, and complete with Tab. --source DIR adds the new repository as a remote of a local Git repository and --push pushes its current branch; --public is the explicit opposite of --private, and -d/-g/-l and the new alias follow gh. --trust-model now offers the names Gitea accepts. A prompted name is confirmed with the visibility, owner and host, and creation reports "✓ Created repository ..." and the URL. repo edit --default-branch nope exited 0 without changing anything; the branch must now exist. Edit gains --visibility, --enable-issues/-wiki/ -pull-requests/-projects, --allow-merge-commit/-squash/-rebase, --delete-branch-on-merge, --default-merge-style and --add-topic/ --remove-topic, and reports which settings it changed. repo migrate names the repository after the source URL, validates --service before prompting, and reports the import with the URL. Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
9 files changed
+742
-308
No files matched your search
@@ -12,17 +12,54 @@ import (
|
||||
)
|
||||
|
||||
func TestRepositoryEditPreservesExplicitClearsAndFalse(t *testing.T) {
|
||||
calls := 0
|
||||
var requests []string
|
||||
server := newAuthenticatedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
calls++
|
||||
require.Equal(t, http.MethodPatch, r.Method)
|
||||
require.Equal(t, "/api/v1/repos/alice/project", r.URL.Path)
|
||||
requirePayload(t, `{"name":"renamed","website":"","default_branch":"main","archived":false,"private":false,"template":false,"has_actions":false}`, r.Body)
|
||||
_, _ = w.Write([]byte(`{"name":"renamed","full_name":"alice/renamed","website":"","default_branch":"main"}`))
|
||||
requests = append(requests, r.Method+" "+r.URL.Path)
|
||||
switch r.Method + " " + r.URL.Path {
|
||||
case "GET /api/v1/repos/alice/project/branches/main":
|
||||
_, _ = w.Write([]byte(`{"name":"main"}`))
|
||||
case "PATCH /api/v1/repos/alice/project":
|
||||
requirePayload(t, `{"name":"renamed","website":"","default_branch":"main","archived":false,"private":false,"template":false,"has_actions":false,"has_wiki":false,"default_merge_style":"squash"}`, r.Body)
|
||||
_, _ = w.Write([]byte(`{"name":"renamed","full_name":"alice/renamed","website":"","default_branch":"main"}`))
|
||||
case "GET /api/v1/repos/alice/renamed":
|
||||
_, _ = w.Write([]byte(`{"name":"renamed","full_name":"alice/renamed","website":"","default_branch":"main"}`))
|
||||
default:
|
||||
t.Errorf("unexpected request %s %s", r.Method, r.URL.Path)
|
||||
}
|
||||
}))
|
||||
defer server.Close()
|
||||
deps, out, _ := serverDeps(t, server.URL)
|
||||
require.NoError(t, Execute(context.Background(), deps, []string{"repo", "edit", "-R", "alice/project", "--name", "renamed", "--website=", "--default-branch", "main", "--archived=false", "--private=false", "--as-template=false", "--actions=false", "--json=name,website,default_branch"}))
|
||||
require.NoError(t, Execute(context.Background(), deps, []string{"repo", "edit", "-R", "alice/project", "--name", "renamed", "--website=", "--default-branch", "main", "--archived=false", "--private=false", "--as-template=false", "--actions=false", "--enable-wiki=false", "--default-merge-style", "squash", "--json=name,website,default_branch"}))
|
||||
require.JSONEq(t, `{"name":"renamed","website":"","default_branch":"main"}`, out.String())
|
||||
require.Equal(t, 1, calls)
|
||||
require.Equal(t, []string{"GET /api/v1/repos/alice/project/branches/main", "PATCH /api/v1/repos/alice/project", "GET /api/v1/repos/alice/renamed"}, requests)
|
||||
}
|
||||
|
||||
func TestRepositoryEditRejectsAMissingDefaultBranch(t *testing.T) {
|
||||
var requests []string
|
||||
server := newAuthenticatedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
requests = append(requests, r.Method+" "+r.URL.Path)
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
}))
|
||||
defer server.Close()
|
||||
deps, _, _ := serverDeps(t, server.URL)
|
||||
err := Execute(context.Background(), deps, []string{"repo", "edit", "alice/project", "--default-branch", "nope"})
|
||||
require.EqualError(t, err, `branch "nope" not found in alice/project`)
|
||||
require.Equal(t, []string{"GET /api/v1/repos/alice/project/branches/nope"}, requests)
|
||||
}
|
||||
|
||||
func TestRepositoryEditReportsTheChangedSettings(t *testing.T) {
|
||||
var requests []string
|
||||
server := newAuthenticatedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
requests = append(requests, r.Method+" "+r.URL.Path)
|
||||
if r.Method == http.MethodPatch {
|
||||
requirePayload(t, `{"description":"CLI","private":true}`, r.Body)
|
||||
}
|
||||
_, _ = w.Write([]byte(`{"full_name":"alice/project"}`))
|
||||
}))
|
||||
defer server.Close()
|
||||
deps, out, diagnostics := repoTTYDeps(t, server.URL)
|
||||
require.NoError(t, Execute(context.Background(), deps, []string{"repo", "edit", "alice/project", "-d", "CLI", "--visibility", "private", "--add-topic", "cli,go", "--remove-topic", "old"}))
|
||||
require.Equal(t, []string{"PATCH /api/v1/repos/alice/project", "PUT /api/v1/repos/alice/project/topics/cli", "PUT /api/v1/repos/alice/project/topics/go", "DELETE /api/v1/repos/alice/project/topics/old"}, requests)
|
||||
require.Empty(t, out.String())
|
||||
require.Equal(t, "✓ Edited repository alice/project (add-topic, description, remove-topic, visibility)\n", diagnostics.String())
|
||||
}
|
||||
Reference in new issue
Block a user