2026-02-21 16:03:46 +00:00
|
|
|
package forge
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
feat: modernise to Go 1.26 iterators and stdlib helpers
Add ListIter in pagination + generic Resource.Iter for streaming
paginated results as iter.Seq2[T, error]. Add Iter* methods across
all service files (actions, admin, branches, issues, labels, notifs,
orgs, packages, pulls, releases, repos, teams, users, webhooks).
Modernise cmd/forgegen with slices.Sort, maps.Keys, strings.FieldsFuncSeq.
Co-Authored-By: Gemini <noreply@google.com>
Co-Authored-By: Virgil <virgil@lethean.io>
2026-02-23 05:39:07 +00:00
|
|
|
"iter"
|
2026-02-21 16:03:46 +00:00
|
|
|
|
2026-03-22 01:51:29 +00:00
|
|
|
"dappco.re/go/core/forge/types"
|
2026-02-21 16:03:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// LabelService handles repository labels, organisation labels, and issue labels.
|
|
|
|
|
// No Resource embedding — paths are heterogeneous.
|
2026-03-26 18:00:20 +00:00
|
|
|
//
|
|
|
|
|
// Usage:
|
|
|
|
|
//
|
|
|
|
|
// f := forge.NewForge("https://forge.lthn.ai", "token")
|
|
|
|
|
// _, err := f.Labels.ListRepoLabels(ctx, "core", "go-forge")
|
2026-02-21 16:03:46 +00:00
|
|
|
type LabelService struct {
|
|
|
|
|
client *Client
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func newLabelService(c *Client) *LabelService {
|
|
|
|
|
return &LabelService{client: c}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ListRepoLabels returns all labels for a repository.
|
|
|
|
|
func (s *LabelService) ListRepoLabels(ctx context.Context, owner, repo string) ([]types.Label, error) {
|
2026-03-26 18:00:20 +00:00
|
|
|
path := ResolvePath("/api/v1/repos/{owner}/{repo}/labels", pathParams("owner", owner, "repo", repo))
|
2026-02-21 16:03:46 +00:00
|
|
|
return ListAll[types.Label](ctx, s.client, path, nil)
|
|
|
|
|
}
|
|
|
|
|
|
feat: modernise to Go 1.26 iterators and stdlib helpers
Add ListIter in pagination + generic Resource.Iter for streaming
paginated results as iter.Seq2[T, error]. Add Iter* methods across
all service files (actions, admin, branches, issues, labels, notifs,
orgs, packages, pulls, releases, repos, teams, users, webhooks).
Modernise cmd/forgegen with slices.Sort, maps.Keys, strings.FieldsFuncSeq.
Co-Authored-By: Gemini <noreply@google.com>
Co-Authored-By: Virgil <virgil@lethean.io>
2026-02-23 05:39:07 +00:00
|
|
|
// IterRepoLabels returns an iterator over all labels for a repository.
|
|
|
|
|
func (s *LabelService) IterRepoLabels(ctx context.Context, owner, repo string) iter.Seq2[types.Label, error] {
|
2026-03-26 18:00:20 +00:00
|
|
|
path := ResolvePath("/api/v1/repos/{owner}/{repo}/labels", pathParams("owner", owner, "repo", repo))
|
feat: modernise to Go 1.26 iterators and stdlib helpers
Add ListIter in pagination + generic Resource.Iter for streaming
paginated results as iter.Seq2[T, error]. Add Iter* methods across
all service files (actions, admin, branches, issues, labels, notifs,
orgs, packages, pulls, releases, repos, teams, users, webhooks).
Modernise cmd/forgegen with slices.Sort, maps.Keys, strings.FieldsFuncSeq.
Co-Authored-By: Gemini <noreply@google.com>
Co-Authored-By: Virgil <virgil@lethean.io>
2026-02-23 05:39:07 +00:00
|
|
|
return ListIter[types.Label](ctx, s.client, path, nil)
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-21 16:03:46 +00:00
|
|
|
// GetRepoLabel returns a single label by ID.
|
|
|
|
|
func (s *LabelService) GetRepoLabel(ctx context.Context, owner, repo string, id int64) (*types.Label, error) {
|
2026-03-26 18:00:20 +00:00
|
|
|
path := ResolvePath("/api/v1/repos/{owner}/{repo}/labels/{id}", pathParams("owner", owner, "repo", repo, "id", int64String(id)))
|
2026-02-21 16:03:46 +00:00
|
|
|
var out types.Label
|
|
|
|
|
if err := s.client.Get(ctx, path, &out); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return &out, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CreateRepoLabel creates a new label in a repository.
|
|
|
|
|
func (s *LabelService) CreateRepoLabel(ctx context.Context, owner, repo string, opts *types.CreateLabelOption) (*types.Label, error) {
|
2026-03-26 18:00:20 +00:00
|
|
|
path := ResolvePath("/api/v1/repos/{owner}/{repo}/labels", pathParams("owner", owner, "repo", repo))
|
2026-02-21 16:03:46 +00:00
|
|
|
var out types.Label
|
|
|
|
|
if err := s.client.Post(ctx, path, opts, &out); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return &out, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// EditRepoLabel updates an existing label in a repository.
|
|
|
|
|
func (s *LabelService) EditRepoLabel(ctx context.Context, owner, repo string, id int64, opts *types.EditLabelOption) (*types.Label, error) {
|
2026-03-26 18:00:20 +00:00
|
|
|
path := ResolvePath("/api/v1/repos/{owner}/{repo}/labels/{id}", pathParams("owner", owner, "repo", repo, "id", int64String(id)))
|
2026-02-21 16:03:46 +00:00
|
|
|
var out types.Label
|
|
|
|
|
if err := s.client.Patch(ctx, path, opts, &out); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return &out, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeleteRepoLabel deletes a label from a repository.
|
|
|
|
|
func (s *LabelService) DeleteRepoLabel(ctx context.Context, owner, repo string, id int64) error {
|
2026-03-26 18:00:20 +00:00
|
|
|
path := ResolvePath("/api/v1/repos/{owner}/{repo}/labels/{id}", pathParams("owner", owner, "repo", repo, "id", int64String(id)))
|
2026-02-21 16:03:46 +00:00
|
|
|
return s.client.Delete(ctx, path)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ListOrgLabels returns all labels for an organisation.
|
|
|
|
|
func (s *LabelService) ListOrgLabels(ctx context.Context, org string) ([]types.Label, error) {
|
2026-03-26 18:00:20 +00:00
|
|
|
path := ResolvePath("/api/v1/orgs/{org}/labels", pathParams("org", org))
|
2026-02-21 16:03:46 +00:00
|
|
|
return ListAll[types.Label](ctx, s.client, path, nil)
|
|
|
|
|
}
|
|
|
|
|
|
feat: modernise to Go 1.26 iterators and stdlib helpers
Add ListIter in pagination + generic Resource.Iter for streaming
paginated results as iter.Seq2[T, error]. Add Iter* methods across
all service files (actions, admin, branches, issues, labels, notifs,
orgs, packages, pulls, releases, repos, teams, users, webhooks).
Modernise cmd/forgegen with slices.Sort, maps.Keys, strings.FieldsFuncSeq.
Co-Authored-By: Gemini <noreply@google.com>
Co-Authored-By: Virgil <virgil@lethean.io>
2026-02-23 05:39:07 +00:00
|
|
|
// IterOrgLabels returns an iterator over all labels for an organisation.
|
|
|
|
|
func (s *LabelService) IterOrgLabels(ctx context.Context, org string) iter.Seq2[types.Label, error] {
|
2026-03-26 18:00:20 +00:00
|
|
|
path := ResolvePath("/api/v1/orgs/{org}/labels", pathParams("org", org))
|
feat: modernise to Go 1.26 iterators and stdlib helpers
Add ListIter in pagination + generic Resource.Iter for streaming
paginated results as iter.Seq2[T, error]. Add Iter* methods across
all service files (actions, admin, branches, issues, labels, notifs,
orgs, packages, pulls, releases, repos, teams, users, webhooks).
Modernise cmd/forgegen with slices.Sort, maps.Keys, strings.FieldsFuncSeq.
Co-Authored-By: Gemini <noreply@google.com>
Co-Authored-By: Virgil <virgil@lethean.io>
2026-02-23 05:39:07 +00:00
|
|
|
return ListIter[types.Label](ctx, s.client, path, nil)
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-21 16:03:46 +00:00
|
|
|
// CreateOrgLabel creates a new label in an organisation.
|
|
|
|
|
func (s *LabelService) CreateOrgLabel(ctx context.Context, org string, opts *types.CreateLabelOption) (*types.Label, error) {
|
2026-03-26 18:00:20 +00:00
|
|
|
path := ResolvePath("/api/v1/orgs/{org}/labels", pathParams("org", org))
|
2026-02-21 16:03:46 +00:00
|
|
|
var out types.Label
|
|
|
|
|
if err := s.client.Post(ctx, path, opts, &out); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return &out, nil
|
|
|
|
|
}
|
2026-04-02 06:20:27 +00:00
|
|
|
|
|
|
|
|
// GetOrgLabel returns a single label for an organisation.
|
|
|
|
|
func (s *LabelService) GetOrgLabel(ctx context.Context, org string, id int64) (*types.Label, error) {
|
|
|
|
|
path := ResolvePath("/api/v1/orgs/{org}/labels/{id}", pathParams("org", org, "id", int64String(id)))
|
|
|
|
|
var out types.Label
|
|
|
|
|
if err := s.client.Get(ctx, path, &out); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return &out, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// EditOrgLabel updates an existing label in an organisation.
|
|
|
|
|
func (s *LabelService) EditOrgLabel(ctx context.Context, org string, id int64, opts *types.EditLabelOption) (*types.Label, error) {
|
|
|
|
|
path := ResolvePath("/api/v1/orgs/{org}/labels/{id}", pathParams("org", org, "id", int64String(id)))
|
|
|
|
|
var out types.Label
|
|
|
|
|
if err := s.client.Patch(ctx, path, opts, &out); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return &out, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeleteOrgLabel deletes a label from an organisation.
|
|
|
|
|
func (s *LabelService) DeleteOrgLabel(ctx context.Context, org string, id int64) error {
|
|
|
|
|
path := ResolvePath("/api/v1/orgs/{org}/labels/{id}", pathParams("org", org, "id", int64String(id)))
|
|
|
|
|
return s.client.Delete(ctx, path)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ListLabelTemplates returns all available label template names.
|
|
|
|
|
func (s *LabelService) ListLabelTemplates(ctx context.Context) ([]string, error) {
|
|
|
|
|
var out []string
|
|
|
|
|
if err := s.client.Get(ctx, "/api/v1/label/templates", &out); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return out, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IterLabelTemplates returns an iterator over all available label template names.
|
|
|
|
|
func (s *LabelService) IterLabelTemplates(ctx context.Context) iter.Seq2[string, error] {
|
|
|
|
|
return func(yield func(string, error) bool) {
|
|
|
|
|
items, err := s.ListLabelTemplates(ctx)
|
|
|
|
|
if err != nil {
|
|
|
|
|
yield("", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
for _, item := range items {
|
|
|
|
|
if !yield(item, nil) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetLabelTemplate returns all labels for a label template.
|
|
|
|
|
func (s *LabelService) GetLabelTemplate(ctx context.Context, name string) ([]types.LabelTemplate, error) {
|
|
|
|
|
path := ResolvePath("/api/v1/label/templates/{name}", pathParams("name", name))
|
|
|
|
|
var out []types.LabelTemplate
|
|
|
|
|
if err := s.client.Get(ctx, path, &out); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return out, nil
|
|
|
|
|
}
|