mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 19:11:25 +01:00
feat: explain refusals to delete or rerun an unfinished run
Gitea refuses to delete or rerun a run that has not finished with "this workflow run is not done". Report "run 37 has not finished; cancel it first: tea run cancel 37", and cover the next steps added to refusals in tests. Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
4 files changed
+32
No files matched your search
@@ -186,6 +186,10 @@ func conflictHint(ctx context.Context, apiErr *transport.APIError, conflict *ser
|
||||
if conflict.Key != "" {
|
||||
return "enable it with: tea workflow enable " + conflict.Key
|
||||
}
|
||||
case services.ReasonNotDone:
|
||||
if conflict.Kind == "run" && conflict.Key != "" {
|
||||
return "cancel it first: tea run cancel " + conflict.Key
|
||||
}
|
||||
case services.ReasonOwnsRepos:
|
||||
return "transfer or delete them first"
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"time"
|
||||
|
||||
"gitea.dev/tea/internal/clierr"
|
||||
"gitea.dev/tea/internal/transport"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@@ -76,6 +77,28 @@ func TestExplainNamesResourcesAndTellsWhyRepositoriesFail(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestExplainAddsTheNextStepToRefusals(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
method, endpoint, message string
|
||||
status int
|
||||
want string
|
||||
}{
|
||||
{"PATCH", "/api/v1/repos/alice/x/pulls/3", "cannot change state of this pull request, it was already merged", 412, "pull request #3 is already merged; its state can no longer change"},
|
||||
{"POST", "/api/v1/repos/alice/x/pulls/3/merge", "The PR is already merged", 405, "pull request #3 is already merged"},
|
||||
{"POST", "/api/v1/repos/alice/x/pulls/5/merge", "Work in progress PRs cannot be merged", 405, "pull request #5 is a draft; mark it ready with: tea pr edit 5 --ready"},
|
||||
{"POST", "/api/v1/repos/alice/x/pulls/1/reviews", "approve your own pull is not allowed", 422, "you can't approve or request changes on your own pull request; leave a comment instead"},
|
||||
{"POST", "/api/v1/repos/alice/x/pulls", "Invalid PullRequest: There are no changes between the head and the base", 422, "no commits between the base and head branches; check out your feature branch or pass --head"},
|
||||
{"POST", "/api/v1/repos/alice/x/actions/workflows/nightly.yaml/dispatches", "workflow is disabled", 403, "workflow nightly.yaml is disabled; enable it with: tea workflow enable nightly.yaml"},
|
||||
{"DELETE", "/api/v1/repos/alice/x/actions/runs/37", "this workflow run is not done", 400, "run 37 has not finished; cancel it first: tea run cancel 37"},
|
||||
{"POST", "/api/v1/repos/alice/x/wiki/new", "wiki page already exists [title: Home.md]", 400, `wiki page "Home" already exists in alice/x; edit it with: tea wiki edit "Home"`},
|
||||
{"DELETE", "/api/v1/admin/users/uxadm1", "user still has ownership of repositories [uid: 7]", 422, `user "uxadm1" still owns repositories; transfer or delete them first`},
|
||||
{"POST", "/api/v1/user/keys", "Key content has been used as non-deploy key", 422, "this SSH key is already registered"},
|
||||
} {
|
||||
apiErr := &transport.APIError{Status: tc.status, Method: tc.method, Endpoint: tc.endpoint, Message: tc.message, Instance: "http://localhost:3001"}
|
||||
require.EqualError(t, Explain(context.Background(), Dependencies{}, apiErr), tc.want, tc.endpoint)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExplainWordsCredentialAndConnectionFailures(t *testing.T) {
|
||||
rejecting := fakeGitea(t, map[string][2]string{"GET /api/v1/user": {"401", `{"message":"token is invalid"}`}})
|
||||
deps, _, _ := serverDeps(t, rejecting.URL)
|
||||
|
||||
Reference in new issue
Block a user