mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01: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
|
||||
|
||||
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)
|
||||
|
||||
Reference in new issue
Block a user