mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 19:11:25 +01:00
milestone view printed the list row, and milestone list hid the due date and progress. milestone list now shows ID TITLE [STATE] DUE PROGRESS, open milestones first and by due date; milestone view shows the state, due date, progress, description and the milestone's web page (also --web). Every milestone command addresses milestones by title or ID. Mutations report ✓ lines: milestone create also prints the new milestone's URL and takes the title as an argument; close and reopen skip milestones already in that state; delete names the milestone in its confirmation; milestone issue add and remove report one line such as "✓ Added #1, #2 to milestone "v1.0" in alice/x". milestone issue list uses the issue table. milestone edit without flags on a terminal opens the milestone form with the current values, and every milestone command completes milestone titles and has help text with examples. Signed-off-by: bircni <bircni@icloud.com>
63 lines
2.4 KiB
Go
63 lines
2.4 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package app
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"slices"
|
|
"strings"
|
|
|
|
"gitea.dev/tea/internal/clierr"
|
|
"gitea.dev/tea/internal/services"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// milestoneStateCommand closes or reopens milestones, reporting those already in that state instead
|
|
// of changing them.
|
|
func (a *application) milestoneStateCommand(verb string, service milestoneService) *cobra.Command {
|
|
var byName bool
|
|
state, past := "closed", "Closed"
|
|
if verb == "reopen" {
|
|
state, past = "open", "Reopened"
|
|
}
|
|
cmd := &cobra.Command{Use: verb + " <milestone>...", Short: titleCase(verb) + " milestones", Example: fmt.Sprintf(`$ tea milestone %[1]s v1.0
|
|
$ tea milestone %[1]s v1.0 v1.1`, verb), Annotations: map[string]string{"tea.arguments": milestoneArguments}, Args: usageArgs(cobra.MinimumNArgs(1)), RunE: func(cmd *cobra.Command, args []string) error {
|
|
if slices.ContainsFunc(args, func(arg string) bool { return strings.TrimSpace(arg) == "" }) {
|
|
return clierr.Wrap(clierr.Usage, errors.New("milestone title or ID cannot be empty"))
|
|
}
|
|
milestones, t, err := service(cmd)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
selected, err := milestones.Find(cmd.Context(), args, byName)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for i, milestone := range selected {
|
|
if slices.ContainsFunc(selected[:i], func(other services.Milestone) bool { return other.ID == milestone.ID }) {
|
|
return clierr.Wrap(clierr.Usage, errors.New("milestone "+args[i]+" is selected more than once"))
|
|
}
|
|
}
|
|
results, failures := applyBatch(cmd, selected, func(milestone services.Milestone) string { return "milestone " + milestone.Title }, func(milestone services.Milestone) (services.Milestone, error) {
|
|
if milestone.State == state {
|
|
a.warn(cmd, "%s is already %s", titleCase(milestoneName(t, milestone)), state)
|
|
return milestone, nil
|
|
}
|
|
item, err := milestones.Edit(cmd.Context(), milestone.ID, services.MilestoneOptions{State: &state})
|
|
if err == nil {
|
|
a.done(cmd, "%s %s", past, milestoneName(t, item))
|
|
}
|
|
return item, err
|
|
}, func(services.Milestone) {})
|
|
if a.options.json != "" {
|
|
failures = append(failures, writeBatchJSON(a, cmd, len(selected), results))
|
|
}
|
|
return errors.Join(failures...)
|
|
}}
|
|
cmd.Flags().BoolVar(&byName, "by-name", false, "Match numeric arguments as milestone titles rather than IDs")
|
|
cmd.ValidArgsFunction = a.completeMilestoneArgs(true)
|
|
return cmd
|
|
}
|