mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 19:11:25 +01:00
feat(label): edit a label in a form without flags
label edit without flags on a terminal now opens a form with the label's name, color, description and flags, like milestone edit and issue edit, instead of failing; without a terminal it reports the shared "nothing to edit" error. The help of issue and milestone close and reopen names its commands without generating the text from the verb. Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
6 files changed
+143
-8
No files matched your search
@@ -11,6 +11,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.dev/tea/internal/terminal"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@@ -193,3 +194,45 @@ 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