mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 19:11:25 +01:00
- **switch tea to the Cobra command tree:** `internal/app` wires the packages from parts 1–4 into explicit noun/verb commands with `--repo`, `--json` / `--jq`, `--sudo` and `--debug`; `main.go` points at it. Build, release and docs tooling (`tools/cli-docs`, Makefile, goreleaser, snap, CI) and README / CONTRIBUTING are updated. - **remove the urfave/cli command tree:** deletes `cmd/`, `modules/`, the old integration tests, contrib completion scripts and the generated `docs/CLI.md`, and drops their dependencies. This commit only deletes. ## Breaking changes This is a breaking release. It requires Gitea 28 or newer; configuration moves to separate `config.yml` and `hosts.yml` files and requires fresh authentication, and command names, aliases, flags and output formats change. `docs/migration-1.0.md` maps every old command, flag and environment variable to its replacement. ## Issues fixes #1118 fixes #1116 fixes #1115 fixes #1094 fixes #1091 fixes #1073 fixes #1052 fixes #1032 fixes #1023 fixes #966 fixes #908 fixes #833 fixes #831 fixes #817 fixes #804 fixes #779 fixes #770 fixes #737 fixes #697 fixes #726 fixes #677 fixes #672 fixes #633 fixes #632 fixes #560 fixes #556 fixes #523 fixes #516 fixes #510 fixes #504 fixes #500 fixes #482 fixes #406 fixes #403 fixes #373 fixes #351 fixes #344 fixes #326 fixes #325 fixes #323 fixes #246 fixes #240 fixes #232 fixes #197 fixes #172 fixes #141 fixes #69 fixes #1110 fixes #569 fixes #480 fixes #666 fixes #670 fixes #457 fixes #643 fixes #498 fixes #490 fixes #1069 fixes #834 fixes #602 fixes #328 fixes #417 fixes #571 fixes #1029 fixes #489 fixes #1050 fixes #162 fixes #430 fixes #1087 fixes #683 Reviewed-on: https://gitea.com/gitea/tea/pulls/1126 Reviewed-by: TheFox0x7 <95654+thefox0x7@noreply.gitea.com>
107 lines
4.5 KiB
Go
107 lines
4.5 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package app
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"io"
|
|
"net/http"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"gitea.dev/tea/internal/clierr"
|
|
"gitea.dev/tea/internal/terminal"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestIssueCreateSeedsFromTemplate(t *testing.T) {
|
|
var created []string
|
|
server := newAuthenticatedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
switch r.URL.Path {
|
|
case "/api/v1/repos/alice/project/issue_templates":
|
|
_, _ = w.Write([]byte(`[{"name":"Bug Report","title":"[bug] ","content":"Steps:"},{"name":"Feature","about":"Describe the idea","body":[{"type":"textarea"}]}]`))
|
|
case "/api/v1/repos/alice/project/issues":
|
|
require.Equal(t, http.MethodPost, r.Method)
|
|
payload, err := io.ReadAll(r.Body)
|
|
require.NoError(t, err)
|
|
created = append(created, string(payload))
|
|
_, _ = w.Write([]byte(`{"number":1}`))
|
|
default:
|
|
t.Errorf("unexpected %s %s", r.Method, r.URL.Path)
|
|
}
|
|
}))
|
|
defer server.Close()
|
|
deps, _, _ := serverDeps(t, server.URL)
|
|
editor := &draftEditor{draft: terminal.Draft{Body: "edited idea"}}
|
|
deps.Editor = editor
|
|
deps.Getenv = serverEnv(server.URL, map[string]string{"EDITOR": "chosen-editor"})
|
|
run := func(args ...string) error {
|
|
return Execute(context.Background(), deps, append([]string{"issue", "create", "-R", "alice/project", "--no-input", "--json=number"}, args...))
|
|
}
|
|
require.NoError(t, run("--template", "bug report"))
|
|
require.NoError(t, run("--template", "Bug Report", "--title", "Explicit", "--body", "Override"))
|
|
require.NoError(t, run("--template", "feature", "--title", "Idea", "--editor"))
|
|
require.Equal(t, "Describe the idea", editor.initial)
|
|
err := run("--template", "missing", "--title", "x")
|
|
require.ErrorContains(t, err, `issue template "missing" does not exist; available: Bug Report, Feature`)
|
|
require.Equal(t, clierr.Failure, clierr.ExitCode(err))
|
|
err = run("--template", "feature")
|
|
require.ErrorContains(t, err, "missing required input: supply --title")
|
|
deps.Streams.In = strings.NewReader("From stdin")
|
|
require.NoError(t, run("--template", "bug report", "--body-file", "-"))
|
|
err = run("--template", "feature", "--body-file", "-")
|
|
require.ErrorContains(t, err, "--body-file - requires --title")
|
|
require.Len(t, created, 4)
|
|
for i, want := range []string{
|
|
`{"title":"[bug] ","body":"Steps:"}`,
|
|
`{"title":"Explicit","body":"Override"}`,
|
|
`{"title":"Idea","body":"edited idea"}`,
|
|
`{"title":"[bug] ","body":"From stdin"}`,
|
|
} {
|
|
requirePayload(t, want, strings.NewReader(created[i]))
|
|
}
|
|
}
|
|
|
|
func TestIssueCreateUploadsAttachmentsAndKeepsIssueOnFailure(t *testing.T) {
|
|
var requests, uploaded []string
|
|
server := newAuthenticatedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
requests = append(requests, r.Method+" "+r.URL.Path)
|
|
switch r.URL.Path {
|
|
case "/api/v1/repos/alice/project/issues":
|
|
_, _ = w.Write([]byte(`{"number":5,"title":"Crash"}`))
|
|
case "/api/v1/repos/alice/project/issues/5/assets":
|
|
file, header, err := r.FormFile("attachment")
|
|
require.NoError(t, err)
|
|
content, err := io.ReadAll(file)
|
|
require.NoError(t, err)
|
|
uploaded = append(uploaded, header.Filename+"="+string(content))
|
|
if header.Filename == "second.txt" {
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
return
|
|
}
|
|
_ = json.NewEncoder(w).Encode(map[string]any{"id": 1, "name": header.Filename})
|
|
default:
|
|
t.Errorf("unexpected %s %s", r.Method, r.URL.Path)
|
|
}
|
|
}))
|
|
defer server.Close()
|
|
deps, out, _ := serverDeps(t, server.URL)
|
|
dir := t.TempDir()
|
|
first, second := filepath.Join(dir, "first.txt"), filepath.Join(dir, "second.txt")
|
|
require.NoError(t, os.WriteFile(first, []byte("one"), 0o600))
|
|
args := []string{"issue", "create", "-R", "alice/project", "--title", "Crash", "--attachment", first, "--attachment", second, "--json=number,title"}
|
|
require.Error(t, Execute(context.Background(), deps, args))
|
|
require.Empty(t, requests)
|
|
require.NoError(t, os.WriteFile(second, []byte("two"), 0o600))
|
|
err := Execute(context.Background(), deps, args)
|
|
require.ErrorContains(t, err, "issue 5 created; attachment second.txt upload failed")
|
|
require.Equal(t, clierr.Failure, clierr.ExitCode(err))
|
|
require.JSONEq(t, `{"number":5,"title":"Crash"}`, out.String())
|
|
require.Equal(t, []string{"first.txt=one", "second.txt=two"}, uploaded)
|
|
require.Equal(t, []string{"POST /api/v1/repos/alice/project/issues", "POST /api/v1/repos/alice/project/issues/5/assets", "POST /api/v1/repos/alice/project/issues/5/assets"}, requests)
|
|
}
|