feat(assignees): add set, add, and remove assignees APIs (#1045)

Implemented set, add, and remove assignees APIs.
Closes https://gitea.com/gitea/tea/issues/965 and https://gitea.com/gitea/tea/issues/966Reviewed-on: https://gitea.com/gitea/tea/pulls/1045
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Minjie Fang <wingsallen@gmail.com>
This commit is contained in:
Minjie Fang
2026-07-18 00:20:03 +00:00
committed by Lunny Xiao
parent 2d6dcd062f
commit d664c01e18
11 changed files with 434 additions and 27 deletions
+20 -4
View File
@@ -8,6 +8,7 @@ import (
"slices"
"strings"
gitea "gitea.dev/sdk"
"gitea.dev/tea/modules/config"
"gitea.dev/tea/modules/context"
"gitea.dev/tea/modules/task"
@@ -40,9 +41,10 @@ func EditIssue(requestCtx stdctx.Context, ctx context.TeaContext, index int64) (
Deadline: i.Deadline,
}
i.Assignees = cleanAssignees(i.Assignees)
if len(i.Assignees) != 0 {
for _, a := range i.Assignees {
opts.AddAssignees = append(opts.AddAssignees, a.UserName)
opts.SetAssignees = append(opts.SetAssignees, a.UserName)
}
}
@@ -109,7 +111,7 @@ func promptIssueEditProperties(requestCtx stdctx.Context, ctx *context.TeaContex
return nil
}
currAssignees := o.AddAssignees
currAssignees := o.SetAssignees
newAssignees := selectables.Assignees
for _, c := range currAssignees {
@@ -119,10 +121,14 @@ func promptIssueEditProperties(requestCtx stdctx.Context, ctx *context.TeaContex
}
// assignees
if o.AddAssignees, err = promptMultiSelect("Add Assignees:", newAssignees, "[other]"); err != nil {
if currAssignees, err = promptMultiSelectWithPreselect("Set Assignees:", currAssignees, newAssignees, "[other]"); err != nil {
return err
}
printTitleAndContent("Assignees:", strings.Join(o.AddAssignees, "\n"))
if len(currAssignees) == 0 && len(o.SetAssignees) > 0 {
o.RemoveAssignees = o.SetAssignees
}
o.SetAssignees = currAssignees
printTitleAndContent("Assignees:", strings.Join(o.SetAssignees, "\n"))
// milestone
if len(selectables.MilestoneList) != 0 {
@@ -175,3 +181,13 @@ func promptIssueEditProperties(requestCtx stdctx.Context, ctx *context.TeaContex
return nil
}
func cleanAssignees(list []*gitea.User) []*gitea.User {
out := make([]*gitea.User, 0, len(list))
for _, a := range list {
if strings.TrimSpace(a.UserName) != "" {
out = append(out, a)
}
}
return out
}
+17 -1
View File
@@ -92,10 +92,26 @@ func promptDatetime(prompt string) (val *time.Time, err error) {
// promptSelect creates a generic multiselect prompt, with processing of custom values.
func promptMultiSelect(prompt string, options []string, customVal string) ([]string, error) {
opts := huh.NewOptions(makeSelectOpts(options, customVal, "")...)
return runMultiSelect(prompt, opts, customVal)
}
// promptMultiSelectWithPreselect creates a generic multiselect prompt with preselected values and processing of custom values.
func promptMultiSelectWithPreselect(prompt string, selected []string, options []string, customVal string) ([]string, error) {
opts := make([]huh.Option[string], 0, len(selected)+len(options)+1)
for _, name := range selected {
opts = append(opts, huh.NewOption(name, name).Selected(true))
}
opts = append(opts, huh.NewOptions(makeSelectOpts(options, customVal, "")...)...)
return runMultiSelect(prompt, opts, customVal)
}
func runMultiSelect(prompt string, opts []huh.Option[string], customVal string) ([]string, error) {
var selection []string
if err := huh.NewMultiSelect[string]().
Title(prompt).
Options(huh.NewOptions(makeSelectOpts(options, customVal, "")...)...).
Options(opts...).
Value(&selection).
WithTheme(theme.GetTheme()).
Run(); err != nil {