mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 19:11:25 +01:00
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:
3 files changed
+10
-12
No files matched your search
@@ -4,6 +4,7 @@
|
|||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"cmp"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -88,8 +89,9 @@ func (f commentFlags) validate(cmd *cobra.Command) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// readComment returns the comment text: from --body or --body-file, else from the editor with --editor or
|
// readComment returns the comment text: from --body or --body-file, else from the editor with
|
||||||
// when one is configured, else from a multi-line prompt. initial seeds the editor and the prompt.
|
// --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) {
|
func (a *application) readComment(cmd *cobra.Command, f commentFlags, initial string) (string, terminal.Draft, error) {
|
||||||
var draft terminal.Draft
|
var draft terminal.Draft
|
||||||
var body string
|
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.
|
// 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) {
|
func (a *application) promptComment(cmd *cobra.Command, initial string) (string, terminal.Draft, error) {
|
||||||
snapshot, err := a.deps.Settings.Load()
|
if prompt, err := a.canPrompt(); err != nil || !prompt {
|
||||||
if err != nil {
|
return "", terminal.Draft{}, cmp.Or(err, clierr.Wrap(clierr.Usage, errors.New("missing required input: supply --body, --body-file or --editor")))
|
||||||
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 preferences, err := a.preferences(); err == nil && preferences.Editor != "" {
|
if preferences, err := a.preferences(); err == nil && preferences.Editor != "" {
|
||||||
draft, err := a.editDraft(cmd, initial)
|
draft, err := a.editDraft(cmd, initial)
|
||||||
|
|||||||
@@ -32,12 +32,12 @@ $ tea issue edit 12 --body-file notes.md`, Annotations: map[string]string{"tea.a
|
|||||||
if err := validateBodySources(cmd); err != nil {
|
if err := validateBodySources(cmd); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
snapshot, err := a.deps.Settings.Load()
|
prompt, err := a.canPrompt()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !localFlagsChanged(cmd) {
|
if !localFlagsChanged(cmd) {
|
||||||
if !a.policy(snapshot).CanPrompt(a.deps.Streams) || a.deps.IssueEditForm == nil {
|
if !prompt || a.deps.IssueEditForm == nil {
|
||||||
return errNothingToEdit
|
return errNothingToEdit
|
||||||
}
|
}
|
||||||
target, numbers, err := a.resolveRefs(cmd, args, issueRef)
|
target, numbers, err := a.resolveRefs(cmd, args, issueRef)
|
||||||
|
|||||||
@@ -244,11 +244,11 @@ $ tea issue create --title "Idea" --web`, Args: argsExact(0), RunE: func(cmd *co
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
snapshot, err := a.deps.Settings.Load()
|
prompt, err := a.canPrompt()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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)
|
return a.createIssueInteractively(cmd)
|
||||||
}
|
}
|
||||||
var target target
|
var target target
|
||||||
|
|||||||
Reference in new issue
Block a user