From 511252e2a54aec2c4e77a1100b42ca19547003a6 Mon Sep 17 00:00:00 2001 From: bircni Date: Mon, 12 Oct 2026 00:13:11 +0200 Subject: [PATCH] refactor(issue): share the prompt policy check of issue forms issue create, issue edit and comment prompts ask canPrompt, like the milestone and label forms, instead of loading the settings themselves. Signed-off-by: bircni --- internal/app/comments.go | 14 ++++++-------- internal/app/issue_edit.go | 4 ++-- internal/app/issues.go | 4 ++-- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/internal/app/comments.go b/internal/app/comments.go index 3732288b..6df0786d 100644 --- a/internal/app/comments.go +++ b/internal/app/comments.go @@ -4,6 +4,7 @@ package app import ( + "cmp" "errors" "fmt" "strconv" @@ -88,8 +89,9 @@ func (f commentFlags) validate(cmd *cobra.Command) error { return nil } -// readComment returns the comment text: from --body or --body-file, else from the editor with --editor or -// when one is configured, else from a multi-line prompt. initial seeds the editor and the prompt. +// readComment returns the comment text: from --body or --body-file, else from the editor with +// --editor or when one is configured, else from a multi-line prompt. initial seeds the editor and +// the prompt. func (a *application) readComment(cmd *cobra.Command, f commentFlags, initial string) (string, terminal.Draft, error) { var draft terminal.Draft var body string @@ -111,12 +113,8 @@ func (a *application) readComment(cmd *cobra.Command, f commentFlags, initial st // promptComment asks for a comment in the configured editor, or in a multi-line field without one. func (a *application) promptComment(cmd *cobra.Command, initial string) (string, terminal.Draft, error) { - snapshot, err := a.deps.Settings.Load() - if err != nil { - return "", terminal.Draft{}, err - } - if !a.policy(snapshot).CanPrompt(a.deps.Streams) { - return "", terminal.Draft{}, clierr.Wrap(clierr.Usage, errors.New("missing required input: supply --body, --body-file or --editor")) + if prompt, err := a.canPrompt(); err != nil || !prompt { + return "", terminal.Draft{}, cmp.Or(err, clierr.Wrap(clierr.Usage, errors.New("missing required input: supply --body, --body-file or --editor"))) } if preferences, err := a.preferences(); err == nil && preferences.Editor != "" { draft, err := a.editDraft(cmd, initial) diff --git a/internal/app/issue_edit.go b/internal/app/issue_edit.go index 34eff637..5b11b19e 100644 --- a/internal/app/issue_edit.go +++ b/internal/app/issue_edit.go @@ -32,12 +32,12 @@ $ tea issue edit 12 --body-file notes.md`, Annotations: map[string]string{"tea.a if err := validateBodySources(cmd); err != nil { return err } - snapshot, err := a.deps.Settings.Load() + prompt, err := a.canPrompt() if err != nil { return err } if !localFlagsChanged(cmd) { - if !a.policy(snapshot).CanPrompt(a.deps.Streams) || a.deps.IssueEditForm == nil { + if !prompt || a.deps.IssueEditForm == nil { return errNothingToEdit } target, numbers, err := a.resolveRefs(cmd, args, issueRef) diff --git a/internal/app/issues.go b/internal/app/issues.go index 0a6d6567..9ff10b56 100644 --- a/internal/app/issues.go +++ b/internal/app/issues.go @@ -244,11 +244,11 @@ $ tea issue create --title "Idea" --web`, Args: argsExact(0), RunE: func(cmd *co return err } } - snapshot, err := a.deps.Settings.Load() + prompt, err := a.canPrompt() if err != nil { return err } - if !localFlagsChanged(cmd) && a.policy(snapshot).CanPrompt(a.deps.Streams) && a.deps.IssueForm != nil { + if !localFlagsChanged(cmd) && prompt && a.deps.IssueForm != nil { return a.createIssueInteractively(cmd) } var target target