mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
fix(issue): reject unknown milestones in issue list and search filters
Gitea drops milestone filter values it cannot resolve and lists every issue when none is left, so tea issue list --milestone nope printed all issues and exited 0, and a pipeline closing the result would act on all of them. issue list and search issue|pr -R now resolve each --milestone value by ID or title and fail with "milestone "nope" not found in alice/project". Instance-wide search cannot check the names and says so on stderr. Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
4 files changed
+125
-12
No files matched your search
+33
-5
@@ -114,6 +114,33 @@ func labelChoices(items []services.Label) []terminal.IssueLabelChoice {
|
||||
|
||||
func issueLabel(n int64) string { return fmt.Sprintf("issue %d", n) }
|
||||
|
||||
// nameFilter splits a comma-separated filter of kind, trimming entries and rejecting blanks.
|
||||
func nameFilter(kind, raw string) ([]string, error) {
|
||||
if raw == "" {
|
||||
return nil, nil
|
||||
}
|
||||
names := strings.Split(raw, ",")
|
||||
return names, requireNames(kind, "", names)
|
||||
}
|
||||
|
||||
// issueFilters checks the label and milestone filters of an issue listing in the target repository
|
||||
// and returns them as query values. Gitea ignores labels and milestones it cannot find, and lists
|
||||
// every issue when no filter value is left, so unknown names are errors.
|
||||
func issueFilters(cmd *cobra.Command, t target, labels, milestones []string) (labelQuery, milestoneQuery string, err error) {
|
||||
if len(labels) > 0 {
|
||||
if err := (services.Labels{Client: t.client, Repository: t.Repo}).RequireFilterNames(cmd.Context(), labels); err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
}
|
||||
var ids []string
|
||||
if len(milestones) > 0 {
|
||||
if ids, err = (services.Milestones{Client: t.client, Repository: t.Repo}).FilterIDs(cmd.Context(), milestones); err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
}
|
||||
return strings.Join(labels, ","), strings.Join(ids, ","), nil
|
||||
}
|
||||
|
||||
// metadataFlags are the label and assignee flags shared by issue and pull request edits.
|
||||
type metadataFlags struct {
|
||||
setLabels, addLabels, removeLabels []string
|
||||
@@ -206,6 +233,10 @@ func (a *application) issueCommand() *cobra.Command {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
milestones, err := nameFilter("milestone", opts.Milestones)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
target, err := a.resolve(cmd.Context(), true)
|
||||
if err != nil {
|
||||
if errors.Is(err, errRepositoryRequired) {
|
||||
@@ -213,11 +244,8 @@ func (a *application) issueCommand() *cobra.Command {
|
||||
}
|
||||
return err
|
||||
}
|
||||
if len(labelNames) > 0 {
|
||||
if err := (services.Labels{Client: target.client, Repository: target.Repo}).RequireFilterNames(cmd.Context(), labelNames); err != nil {
|
||||
return err
|
||||
}
|
||||
opts.Labels = strings.Join(labelNames, ",")
|
||||
if opts.Labels, opts.Milestones, err = issueFilters(cmd, target, labelNames, milestones); err != nil {
|
||||
return err
|
||||
}
|
||||
items, more, err := (services.Issues{Client: target.client, Repository: target.Repo}).List(cmd.Context(), opts)
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user