mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 19:11:25 +01:00
fix: address verified review findings (completion-target-ref-1)
Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
10 files changed
+166
-34
No files matched your search
@@ -116,6 +116,9 @@ func TestCompletionOffersPathsOnlyWherePathsAreExpected(t *testing.T) {
|
||||
"issue list --state ": cobra.ShellCompDirectiveNoFileComp,
|
||||
"issue create --body-file ": cobra.ShellCompDirectiveDefault,
|
||||
"issue create --attachment ": cobra.ShellCompDirectiveDefault,
|
||||
"label export --output ": cobra.ShellCompDirectiveDefault,
|
||||
"run download 5 --output ": cobra.ShellCompDirectiveDefault,
|
||||
"config set ssh_key ": cobra.ShellCompDirectiveDefault,
|
||||
"api --input ": cobra.ShellCompDirectiveDefault,
|
||||
"auth login --ssh-key ": cobra.ShellCompDirectiveDefault,
|
||||
"ssh-key create ": cobra.ShellCompDirectiveDefault,
|
||||
@@ -157,14 +160,14 @@ func TestCompletionOffersPathsOnlyWherePathsAreExpected(t *testing.T) {
|
||||
func TestOfflineCompletions(t *testing.T) {
|
||||
deps, out, _ := testDeps(t)
|
||||
deps.Git = &fakeGit{results: map[string]string{
|
||||
`config --get-regexp ^remote\..*\.url$`: "remote.origin.url https://gitea.example.com/alice/project.git\nremote.my.fork.url git@gitea.example.com:bob/project.git\n",
|
||||
`config --get-regexp ^remote\..*\.url$`: "remote.origin.url https://gitea.example.com/alice/project.git\nremote.my.fork.url git@gitea.example.com:bob/project.git\nremote.ci.url https://bot:s3cret@gitea.example.com/alice/project.git?token=x\n",
|
||||
"for-each-ref --format=%(refname:short) refs/heads": "main\nfeature/login\n",
|
||||
}}
|
||||
configureAccounts(t, deps, "https://gitea.example.com", "alice", "alice", "bob")
|
||||
for args, want := range map[string][]string{
|
||||
"--host ": {"https://gitea.example.com\talice, bob"},
|
||||
"--user ": {"alice\thttps://gitea.example.com (active)", "bob\thttps://gitea.example.com"},
|
||||
"--remote ": {"origin\thttps://gitea.example.com/alice/project.git", "my.fork\tgit@gitea.example.com:bob/project.git"},
|
||||
"--remote ": {"origin\thttps://gitea.example.com/alice/project.git", "my.fork\tgit@gitea.example.com:bob/project.git", "ci\thttps://gitea.example.com/alice/project.git"},
|
||||
} {
|
||||
values, directive := complete(t, deps, out, strings.Split(args, " ")...)
|
||||
require.Equal(t, want, values, args)
|
||||
@@ -217,6 +220,68 @@ func TestRepositoryCompletionUsesRemotesAndInstance(t *testing.T) {
|
||||
require.Contains(t, tokens, "token alice-token")
|
||||
}
|
||||
|
||||
func TestLabelCompletionDiscoversTheRepository(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.URL.Path {
|
||||
case "/api/v1/repos/alice/project/labels":
|
||||
_, _ = w.Write([]byte(`[{"name":"bug","description":"Broken"},{"name":"docs"}]`))
|
||||
case "/api/v1/users/alice":
|
||||
_, _ = w.Write([]byte(`{"id":1,"login":"alice"}`))
|
||||
default:
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
}
|
||||
}))
|
||||
defer server.Close()
|
||||
deps, out, _ := testDeps(t)
|
||||
deps.Git = &fakeGit{results: map[string]string{
|
||||
"remote": "origin", "remote get-url origin": server.URL + "/alice/project.git",
|
||||
}}
|
||||
configureAccounts(t, deps, server.URL, "alice", "alice")
|
||||
values, _ := complete(t, deps, out, "label", "delete", "")
|
||||
require.Equal(t, []string{"bug\tBroken", "docs"}, values)
|
||||
}
|
||||
|
||||
func TestJobCompletionUsesTheRepositoryOfTheRunURL(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.URL.Path {
|
||||
case "/api/v1/repos/bob/tool/actions/runs/44/jobs":
|
||||
if r.URL.Query().Get("page") == "1" {
|
||||
_, _ = w.Write([]byte(`{"jobs":[{"id":9,"name":"Build","status":"success"}]}`))
|
||||
} else {
|
||||
_, _ = w.Write([]byte(`{"jobs":[]}`))
|
||||
}
|
||||
case "/api/v1/users/alice":
|
||||
_, _ = w.Write([]byte(`{"id":1,"login":"alice"}`))
|
||||
default:
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
}
|
||||
}))
|
||||
defer server.Close()
|
||||
deps, out, _ := testDeps(t)
|
||||
deps.Git = &fakeGit{results: map[string]string{"remote": "origin", "remote get-url origin": server.URL + "/alice/project.git"}}
|
||||
configureAccounts(t, deps, server.URL, "alice", "alice")
|
||||
values, _ := complete(t, deps, out, "run", "logs", server.URL+"/bob/tool/actions/runs/44", "--job", "")
|
||||
require.Equal(t, []string{"9\tBuild · success"}, values)
|
||||
}
|
||||
|
||||
func TestActionValueCompletionNeedsNoRepositoryForAnOrganization(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.URL.Path {
|
||||
case "/api/v1/orgs/acme/actions/variables":
|
||||
_, _ = w.Write([]byte(`[{"name":"MODE","description":"Build mode"}]`))
|
||||
case "/api/v1/users/alice":
|
||||
_, _ = w.Write([]byte(`{"id":1,"login":"alice"}`))
|
||||
default:
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
}
|
||||
}))
|
||||
defer server.Close()
|
||||
deps, out, _ := testDeps(t)
|
||||
configureAccounts(t, deps, server.URL, "alice", "alice")
|
||||
values, _ := complete(t, deps, out, "variable", "delete", "--org", "acme", "")
|
||||
require.Equal(t, []string{"MODE\tBuild mode"}, values)
|
||||
}
|
||||
|
||||
func TestAPICompletionNeverRefreshesOrFails(t *testing.T) {
|
||||
requests := 0
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||
@@ -297,7 +362,8 @@ func TestInstanceCompletions(t *testing.T) {
|
||||
directive cobra.ShellCompDirective
|
||||
}{
|
||||
{"pulls by prefix", a.completePulls("open"), nil, "1", []string{"13\tAdd login support", "17\tImprove greeting"}, cobra.ShellCompDirectiveNoFileComp},
|
||||
{"pulls skip given arguments and sanitize titles", a.completePulls("open"), []string{"13", "17"}, "", []string{"2\tFix]0;pwned docs"}, cobra.ShellCompDirectiveNoFileComp},
|
||||
{"pulls skip given arguments and sanitize titles", withoutGiven(a.completePulls("open")), []string{"13", "17"}, "", []string{"2\tFix]0;pwned docs"}, cobra.ShellCompDirectiveNoFileComp},
|
||||
{"flag values may equal a positional argument", a.completePulls("open"), []string{"13"}, "13", []string{"13\tAdd login support"}, cobra.ShellCompDirectiveNoFileComp},
|
||||
{"labels are comma-separated", a.completeLabels(), nil, "bug,", []string{"bug,docs"}, cobra.ShellCompDirectiveNoSpace | cobra.ShellCompDirectiveNoFileComp},
|
||||
{"labels with descriptions", a.completeLabels(), nil, "b", []string{"bug\tSomething is broken"}, cobra.ShellCompDirectiveNoSpace | cobra.ShellCompDirectiveNoFileComp},
|
||||
{"users", a.completeUsers(), nil, "", []string{"alice\tAlice", "bob"}, cobra.ShellCompDirectiveNoSpace | cobra.ShellCompDirectiveNoFileComp},
|
||||
@@ -331,7 +397,7 @@ func TestCompletionTargetAcceptsABareTokenHost(t *testing.T) {
|
||||
require.NoError(t, testManager(t, deps).Register(instance, "alice", "file", "token", auth.HostOptions{}, auth.Credential{AccessToken: "stored-token"}))
|
||||
deps.Getenv = envFunc(map[string]string{"TEA_HOST": "127.0.0.1:3999", "GITEA_TOKEN": "environment-token"})
|
||||
a := &application{deps: deps}
|
||||
resolved, err := a.completionTarget(context.Background(), false)
|
||||
resolved, err := a.completionTarget(context.Background(), "", false)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, instance, resolved.Host)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user