diff --git a/internal/app/issues.go b/internal/app/issues.go index 870351c8..069fbb15 100644 --- a/internal/app/issues.go +++ b/internal/app/issues.go @@ -414,11 +414,11 @@ func issueTemplate(ctx context.Context, service services.Issues, name string) (s // changing them. func (a *application) issueStateCommand(verb string) *cobra.Command { var comment string - state, past, completeState := "closed", "Closed", "open" + state, past, completeState, short := "closed", "Closed", "open", "Close issues" if verb == "reopen" { - state, past, completeState = "open", "Reopened", "closed" + state, past, completeState, short = "open", "Reopened", "closed", "Reopen issues" } - cmd := &cobra.Command{Use: verb + " { | }...", Short: titleCase(verb) + " issues", Example: fmt.Sprintf(`$ tea issue %[1]s 12 + cmd := &cobra.Command{Use: verb + " { | }...", Short: short, Example: fmt.Sprintf(`$ tea issue %[1]s 12 $ tea issue %[1]s 12 13 --comment "Done in #14"`, verb), Annotations: map[string]string{"tea.arguments": issueArguments}, Args: usageArgs(cobra.MinimumNArgs(1)), RunE: func(cmd *cobra.Command, args []string) error { target, numbers, err := a.resolveRefs(cmd, args, issueRef) if err != nil { diff --git a/internal/app/label_options_test.go b/internal/app/label_options_test.go index 7b20070b..92a2c3dd 100644 --- a/internal/app/label_options_test.go +++ b/internal/app/label_options_test.go @@ -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) +} diff --git a/internal/app/labels.go b/internal/app/labels.go index 93625e79..ebf3f4f0 100644 --- a/internal/app/labels.go +++ b/internal/app/labels.go @@ -240,14 +240,19 @@ func (a *application) reportLabel(cmd *cobra.Command, s services.Labels, item se func (a *application) labelEditCommand(scope labelScope, complete cobra.CompletionFunc) *cobra.Command { var fields labelFields var byName bool - cmd := &cobra.Command{Use: "edit