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 <bircni@icloud.com>
This commit is contained in:
bircni committed 2026-10-12 00:17:08 +02:00
1 parent 01ced23a4a
commit 511252e2a5
3 files changed
+10 -12

No files matched your search

+6 -8
View File
@@ -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)
+2 -2
View File
@@ -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)
+2 -2
View File
@@ -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