mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
refactor: remove features beyond the UX plan
Drop additions that the UX plan does not ask for: - the interactive label edit form; label edit now requires a flag - label clone and the skip mode of label creation it needed - repo rename rewriting the Git remote or tea.repository; it now warns that the remote still points to the old name - the extra "source" remote on clones of pull mirrors - run artifact download, which duplicates run download --zip - 256-color and 24-bit label swatches; colors stay ANSI 16 - config list --show-source (config get keeps it) - the membership and access GETs before team member/repo add and remove; Gitea's PUT and DELETE are idempotent label edit/delete keep --by-name: it is the only way to address a label whose name is a number that is also another label's ID. Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
22 files changed
+69
-560
No files matched your search
@@ -11,7 +11,6 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.dev/tea/internal/terminal"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@@ -96,15 +95,11 @@ func TestLabelsByName(t *testing.T) {
|
||||
labels := `[{"id":11,"name":"bug","color":"ee0701"},{"id":12,"name":"kind/feature","color":"84b6eb","exclusive":true},{"id":13,"name":"2026","color":"cccccc"}]`
|
||||
server := newAuthenticatedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method + " " + r.URL.Path {
|
||||
case "GET /api/v1/repos/alice/project/labels", "GET /api/v1/repos/bob/source/labels":
|
||||
case "GET /api/v1/repos/alice/project/labels":
|
||||
if r.URL.Query().Get("page") != "1" {
|
||||
_, _ = w.Write([]byte(`[]`))
|
||||
return
|
||||
}
|
||||
if r.URL.Path == "/api/v1/repos/bob/source/labels" {
|
||||
_, _ = w.Write([]byte(`[{"id":1,"name":"bug","color":"000000"},{"id":2,"name":"docs","color":"0000ff","description":"Docs"}]`))
|
||||
return
|
||||
}
|
||||
_, _ = w.Write([]byte(labels))
|
||||
default:
|
||||
changed = append(changed, r.Method+" "+r.URL.Path+" "+requestFields(t, r, "name", "color", "description"))
|
||||
@@ -131,15 +126,12 @@ func TestLabelsByName(t *testing.T) {
|
||||
require.NoError(t, run("label", "edit", "2026", "--by-name", "-d", "Year"))
|
||||
require.NoError(t, run("label", "delete", "BUG", "12", "--yes"))
|
||||
require.Equal(t, "✓ Deleted label \"bug\" from alice/project\n✓ Deleted label \"kind/feature\" from alice/project\n", diagnostics.String())
|
||||
require.NoError(t, run("label", "clone", "bob/source"))
|
||||
require.Equal(t, "! Skipped label \"bug\" in alice/project: it exists already\n✓ Created label \"docs\" in alice/project\n", diagnostics.String())
|
||||
require.Equal(t, []string{
|
||||
"POST /api/v1/repos/alice/project/labels name=docs color=0000FF description=Docs",
|
||||
"PATCH /api/v1/repos/alice/project/labels/12 name=kind/enhancement color=<nil> description=<nil>",
|
||||
"PATCH /api/v1/repos/alice/project/labels/13 name=<nil> color=<nil> description=Year",
|
||||
"DELETE /api/v1/repos/alice/project/labels/11 ",
|
||||
"DELETE /api/v1/repos/alice/project/labels/12 ",
|
||||
"POST /api/v1/repos/alice/project/labels name=docs color=0000ff description=Docs",
|
||||
}, changed)
|
||||
for _, test := range []struct {
|
||||
args []string
|
||||
@@ -194,45 +186,3 @@ func TestLabelCreatePicksAColorAndPrompts(t *testing.T) {
|
||||
require.Equal(t, "From a prompt", created[1]["description"])
|
||||
require.Equal(t, []string{"Label name", "Color (hex, e.g. d73a4a; empty = random):", "Description (optional):"}, prompt.asked)
|
||||
}
|
||||
|
||||
// labelFormPrompter answers the label form with edit applied to the current values.
|
||||
type labelFormPrompter struct {
|
||||
scriptedPrompter
|
||||
heading string
|
||||
edit func(*terminal.LabelFormValues)
|
||||
}
|
||||
|
||||
func (p *labelFormPrompter) EditLabel(_ context.Context, heading string, current terminal.LabelFormValues) (terminal.LabelFormValues, error) {
|
||||
p.heading = heading
|
||||
p.edit(¤t)
|
||||
return current, nil
|
||||
}
|
||||
|
||||
func TestLabelEditFormStartsFromTheLabel(t *testing.T) {
|
||||
var edited string
|
||||
server := newAuthenticatedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method + " " + r.URL.Path {
|
||||
case "GET /api/v1/repos/alice/project/labels":
|
||||
if r.URL.Query().Get("page") != "1" {
|
||||
_, _ = w.Write([]byte(`[]`))
|
||||
return
|
||||
}
|
||||
_, _ = w.Write([]byte(`[{"id":11,"name":"bug","color":"ee0701","description":"Broken"}]`))
|
||||
case "PATCH /api/v1/repos/alice/project/labels/11":
|
||||
edited = requestFields(t, r, "name", "color", "description", "exclusive")
|
||||
_, _ = w.Write([]byte(`{"id":11,"name":"defect"}`))
|
||||
default:
|
||||
t.Errorf("unexpected %s %s", r.Method, r.URL.Path)
|
||||
}
|
||||
}))
|
||||
defer server.Close()
|
||||
deps, _, _ := serverDeps(t, server.URL)
|
||||
deps.Streams.InTTY, deps.Streams.ErrTTY = true, true
|
||||
prompt := &labelFormPrompter{edit: func(v *terminal.LabelFormValues) { v.Name, v.Exclusive = "defect", true }}
|
||||
deps.Prompter = prompt
|
||||
require.NoError(t, Execute(context.Background(), deps, []string{"label", "edit", "bug", "-R", "alice/project"}))
|
||||
require.Equal(t, `Editing label "bug" in alice/project`, prompt.heading)
|
||||
require.Equal(t, "name=defect color=ee0701 description=Broken exclusive=true", edited)
|
||||
deps.Streams.InTTY, deps.Streams.ErrTTY = false, false
|
||||
require.ErrorIs(t, Execute(context.Background(), deps, []string{"label", "edit", "bug", "-R", "alice/project"}), errNothingToEdit)
|
||||
}
|
||||
Reference in new issue
Block a user