mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
fix(repo): reject --repo on commands that act on no repository
tea repo list -R acme/service listed the account's repositories and tea repo create foo -R alice/project created alice/foo: the flag was silently ignored. repo list, repo create, repo migrate and search repo now fail with a usage error that suggests the intended command, such as "--repo is not used by repo list; did you mean: tea repo list acme". repo list takes the owner as an argument (--owner still works), and repo create accepts OWNER/NAME, creating in the organization OWNER. Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
7 files changed
+96
-7
No files matched your search
@@ -6,6 +6,7 @@ package app
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -40,3 +41,48 @@ func TestRepositoryCommandsAcceptPositionalRepository(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestCommandsWithoutRepositoryRejectRepoFlag(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
args []string
|
||||
want string
|
||||
}{
|
||||
{[]string{"repo", "list", "-R", "acme/service"}, "--repo is not used by repo list; did you mean: tea repo list acme"},
|
||||
{[]string{"repo", "create", "foo", "-R", "alice/project", "--yes"}, "--repo is not used by repo create; did you mean: tea repo create alice/foo"},
|
||||
{[]string{"repo", "migrate", "https://example.com/x.git", "--name", "x", "--repo", "acme/x"}, "--repo is not used by repo migrate; did you mean: tea repo migrate URL --owner acme"},
|
||||
{[]string{"search", "repo", "tea", "-R", "acme/x"}, "--repo is not used by search repo; did you mean: tea search repo --owner acme"},
|
||||
} {
|
||||
t.Run(strings.Join(test.args[:2], " "), func(t *testing.T) {
|
||||
requireUsageBeforeRequests(t, test.want, test.args...)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRepositoryOwnerArguments(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)
|
||||
switch {
|
||||
case r.URL.Path == "/api/v1/orgs/acme":
|
||||
_, _ = w.Write([]byte(`{"id":3,"name":"acme"}`))
|
||||
case r.Method == http.MethodGet:
|
||||
_, _ = w.Write([]byte(`[]`))
|
||||
default:
|
||||
_, _ = w.Write([]byte(`{"full_name":"acme/tool"}`))
|
||||
}
|
||||
}))
|
||||
defer server.Close()
|
||||
for _, test := range []struct {
|
||||
args []string
|
||||
want string
|
||||
}{
|
||||
{[]string{"repo", "list", "acme"}, "GET /api/v1/orgs/acme/repos"},
|
||||
{[]string{"repo", "create", "acme/tool"}, "POST /api/v1/orgs/acme/repos"},
|
||||
{[]string{"repo", "create", "alice/tool"}, "POST /api/v1/user/repos"},
|
||||
} {
|
||||
requests = nil
|
||||
deps, _, _ := serverDeps(t, server.URL)
|
||||
require.NoError(t, Execute(context.Background(), deps, append(test.args, "--no-input", "--json")))
|
||||
require.Equal(t, test.want, requests[len(requests)-1], test.args)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user