mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 19:11:25 +01:00
refactor: reuse the existing service and rendering helpers
services.IsNotFound replaces the hand-rolled 404 checks, convertPage the copied page conversions and lastPathNumber the comment's own number parser. The List wrappers around ListPage of releases, branches, wiki pages, secrets and variables go, pull request filters resolve milestones through Milestones.FindOne like issues, and localFlagsChanged, boolOrder, Cell.Render, stateBadge and dueText replace their copies. Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
33 files changed
+85
-212
No files matched your search
@@ -5,36 +5,9 @@ package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ResolveName selects an exact title across open and closed milestones.
|
||||
func (s Milestones) ResolveName(ctx context.Context, name string) (int64, error) {
|
||||
if strings.TrimSpace(name) == "" {
|
||||
return 0, fmt.Errorf("milestone name cannot be empty")
|
||||
}
|
||||
items, err := s.All(ctx)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
var id int64
|
||||
for _, item := range items {
|
||||
if item.Title != name {
|
||||
continue
|
||||
}
|
||||
if id != 0 {
|
||||
return 0, fmt.Errorf("milestone name %q is ambiguous; select its numeric ID", name)
|
||||
}
|
||||
id = item.ID
|
||||
}
|
||||
if id == 0 {
|
||||
return 0, fmt.Errorf("milestone %q does not exist; use tea milestone list --state all", name)
|
||||
}
|
||||
return id, nil
|
||||
}
|
||||
|
||||
// All returns the open and closed milestones of the repository.
|
||||
func (s Milestones) All(ctx context.Context) ([]Milestone, error) {
|
||||
return listAll(func(page int) ([]Milestone, error) { return s.List(ctx, "all", 100, page) })
|
||||
|
||||
Reference in new issue
Block a user