mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 19:11:25 +01:00
- `internal/services`: typed Gitea workflows built on `gitea.dev/sdk`, independent of CLI flags and terminal I/O: issues, pull requests, reviews, comments, labels, milestones, releases and assets, repositories, branches, wiki, Actions (workflows, runs, jobs, logs, artifacts, secrets, variables), organizations, teams, webhooks, notifications, SSH keys, tracked time, admin users, search and status. - SDK types are mapped to tea's own output types, so `--json` stays a stable contract. Requests the SDK cannot express yet (e.g. pull list filters, multi-status run lists, org label archiving) go through small raw helpers, each marked `TODO(sdk)` with the missing SDK piece. - Targets Gitea 28 or newer: no version or API-schema probing. List helpers fill pages capped by `MAX_RESPONSE_ITEMS`. Nothing imports this package yet. Reviewed-on: https://gitea.com/gitea/tea/pulls/1125 Reviewed-by: TheFox0x7 <95654+thefox0x7@noreply.gitea.com>
36 lines
880 B
Go
36 lines
880 B
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package services
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"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 := listAll(func(page int) ([]Milestone, error) { return s.List(ctx, "all", 100, page) })
|
|
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
|
|
}
|