2026-02-21 15:57:09 +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 15:57:09 +00:00
|
|
|
|
2026-03-22 01:51:29 +00:00
|
|
|
"dappco.re/go/core/forge/types"
|
2026-02-21 15:57:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// AdminService handles site administration operations.
|
|
|
|
|
// Unlike other services, AdminService does not embed Resource[T,C,U]
|
|
|
|
|
// because admin endpoints are heterogeneous.
|
2026-03-26 18:00:20 +00:00
|
|
|
//
|
|
|
|
|
// Usage:
|
|
|
|
|
//
|
|
|
|
|
// f := forge.NewForge("https://forge.lthn.ai", "token")
|
|
|
|
|
// _, err := f.Admin.ListUsers(ctx)
|
2026-02-21 15:57:09 +00:00
|
|
|
type AdminService struct {
|
|
|
|
|
client *Client
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func newAdminService(c *Client) *AdminService {
|
|
|
|
|
return &AdminService{client: c}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ListUsers returns all users (admin only).
|
|
|
|
|
func (s *AdminService) ListUsers(ctx context.Context) ([]types.User, error) {
|
|
|
|
|
return ListAll[types.User](ctx, s.client, "/api/v1/admin/users", 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
|
|
|
// IterUsers returns an iterator over all users (admin only).
|
|
|
|
|
func (s *AdminService) IterUsers(ctx context.Context) iter.Seq2[types.User, error] {
|
|
|
|
|
return ListIter[types.User](ctx, s.client, "/api/v1/admin/users", nil)
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-21 15:57:09 +00:00
|
|
|
// CreateUser creates a new user (admin only).
|
|
|
|
|
func (s *AdminService) CreateUser(ctx context.Context, opts *types.CreateUserOption) (*types.User, error) {
|
|
|
|
|
var out types.User
|
|
|
|
|
if err := s.client.Post(ctx, "/api/v1/admin/users", opts, &out); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return &out, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// EditUser edits an existing user (admin only).
|
|
|
|
|
func (s *AdminService) EditUser(ctx context.Context, username string, opts map[string]any) error {
|
2026-03-09 08:31:16 +00:00
|
|
|
path := ResolvePath("/api/v1/admin/users/{username}", Params{"username": username})
|
2026-02-21 15:57:09 +00:00
|
|
|
return s.client.Patch(ctx, path, opts, nil)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeleteUser deletes a user (admin only).
|
|
|
|
|
func (s *AdminService) DeleteUser(ctx context.Context, username string) error {
|
2026-03-09 08:31:16 +00:00
|
|
|
path := ResolvePath("/api/v1/admin/users/{username}", Params{"username": username})
|
2026-02-21 15:57:09 +00:00
|
|
|
return s.client.Delete(ctx, path)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// RenameUser renames a user (admin only).
|
|
|
|
|
func (s *AdminService) RenameUser(ctx context.Context, username, newName string) error {
|
2026-03-09 08:31:16 +00:00
|
|
|
path := ResolvePath("/api/v1/admin/users/{username}/rename", Params{"username": username})
|
2026-02-21 15:57:09 +00:00
|
|
|
return s.client.Post(ctx, path, &types.RenameUserOption{NewName: newName}, nil)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ListOrgs returns all organisations (admin only).
|
|
|
|
|
func (s *AdminService) ListOrgs(ctx context.Context) ([]types.Organization, error) {
|
|
|
|
|
return ListAll[types.Organization](ctx, s.client, "/api/v1/admin/orgs", 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
|
|
|
// IterOrgs returns an iterator over all organisations (admin only).
|
|
|
|
|
func (s *AdminService) IterOrgs(ctx context.Context) iter.Seq2[types.Organization, error] {
|
|
|
|
|
return ListIter[types.Organization](ctx, s.client, "/api/v1/admin/orgs", nil)
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-02 00:47:58 +00:00
|
|
|
// ListEmails returns all email addresses (admin only).
|
|
|
|
|
func (s *AdminService) ListEmails(ctx context.Context) ([]types.Email, error) {
|
|
|
|
|
return ListAll[types.Email](ctx, s.client, "/api/v1/admin/emails", nil)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IterEmails returns an iterator over all email addresses (admin only).
|
|
|
|
|
func (s *AdminService) IterEmails(ctx context.Context) iter.Seq2[types.Email, error] {
|
|
|
|
|
return ListIter[types.Email](ctx, s.client, "/api/v1/admin/emails", nil)
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-02 01:33:35 +00:00
|
|
|
// ListHooks returns all global hooks (admin only).
|
|
|
|
|
func (s *AdminService) ListHooks(ctx context.Context) ([]types.Hook, error) {
|
|
|
|
|
return ListAll[types.Hook](ctx, s.client, "/api/v1/admin/hooks", nil)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IterHooks returns an iterator over all global hooks (admin only).
|
|
|
|
|
func (s *AdminService) IterHooks(ctx context.Context) iter.Seq2[types.Hook, error] {
|
|
|
|
|
return ListIter[types.Hook](ctx, s.client, "/api/v1/admin/hooks", nil)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetHook returns a single global hook by ID (admin only).
|
|
|
|
|
func (s *AdminService) GetHook(ctx context.Context, id int64) (*types.Hook, error) {
|
|
|
|
|
path := ResolvePath("/api/v1/admin/hooks/{id}", Params{"id": int64String(id)})
|
|
|
|
|
var out types.Hook
|
|
|
|
|
if err := s.client.Get(ctx, path, &out); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return &out, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CreateHook creates a new global hook (admin only).
|
|
|
|
|
func (s *AdminService) CreateHook(ctx context.Context, opts *types.CreateHookOption) (*types.Hook, error) {
|
|
|
|
|
var out types.Hook
|
|
|
|
|
if err := s.client.Post(ctx, "/api/v1/admin/hooks", opts, &out); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return &out, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// EditHook updates an existing global hook (admin only).
|
|
|
|
|
func (s *AdminService) EditHook(ctx context.Context, id int64, opts *types.EditHookOption) (*types.Hook, error) {
|
|
|
|
|
path := ResolvePath("/api/v1/admin/hooks/{id}", Params{"id": int64String(id)})
|
|
|
|
|
var out types.Hook
|
|
|
|
|
if err := s.client.Patch(ctx, path, opts, &out); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return &out, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeleteHook deletes a global hook (admin only).
|
|
|
|
|
func (s *AdminService) DeleteHook(ctx context.Context, id int64) error {
|
|
|
|
|
path := ResolvePath("/api/v1/admin/hooks/{id}", Params{"id": int64String(id)})
|
|
|
|
|
return s.client.Delete(ctx, path)
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-02 01:29:41 +00:00
|
|
|
// ListQuotaGroups returns all available quota groups.
|
|
|
|
|
func (s *AdminService) ListQuotaGroups(ctx context.Context) ([]types.QuotaGroup, error) {
|
|
|
|
|
return ListAll[types.QuotaGroup](ctx, s.client, "/api/v1/admin/quota/groups", nil)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CreateQuotaGroup creates a new quota group.
|
|
|
|
|
func (s *AdminService) CreateQuotaGroup(ctx context.Context, opts *types.CreateQuotaGroupOptions) (*types.QuotaGroup, error) {
|
|
|
|
|
var out types.QuotaGroup
|
|
|
|
|
if err := s.client.Post(ctx, "/api/v1/admin/quota/groups", opts, &out); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return &out, nil
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-02 01:38:14 +00:00
|
|
|
// GetQuotaGroup returns information about a quota group.
|
|
|
|
|
func (s *AdminService) GetQuotaGroup(ctx context.Context, quotagroup string) (*types.QuotaGroup, error) {
|
|
|
|
|
path := ResolvePath("/api/v1/admin/quota/groups/{quotagroup}", Params{"quotagroup": quotagroup})
|
|
|
|
|
var out types.QuotaGroup
|
|
|
|
|
if err := s.client.Get(ctx, path, &out); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return &out, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeleteQuotaGroup deletes a quota group.
|
|
|
|
|
func (s *AdminService) DeleteQuotaGroup(ctx context.Context, quotagroup string) error {
|
|
|
|
|
path := ResolvePath("/api/v1/admin/quota/groups/{quotagroup}", Params{"quotagroup": quotagroup})
|
|
|
|
|
return s.client.Delete(ctx, path)
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-02 01:57:55 +00:00
|
|
|
// ListQuotaRules returns all available quota rules.
|
|
|
|
|
func (s *AdminService) ListQuotaRules(ctx context.Context) ([]types.QuotaRuleInfo, error) {
|
|
|
|
|
return ListAll[types.QuotaRuleInfo](ctx, s.client, "/api/v1/admin/quota/rules", nil)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CreateQuotaRule creates a new quota rule.
|
|
|
|
|
func (s *AdminService) CreateQuotaRule(ctx context.Context, opts *types.CreateQuotaRuleOptions) (*types.QuotaRuleInfo, error) {
|
|
|
|
|
var out types.QuotaRuleInfo
|
|
|
|
|
if err := s.client.Post(ctx, "/api/v1/admin/quota/rules", opts, &out); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return &out, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetQuotaRule returns information about a quota rule.
|
|
|
|
|
func (s *AdminService) GetQuotaRule(ctx context.Context, quotarule string) (*types.QuotaRuleInfo, error) {
|
|
|
|
|
path := ResolvePath("/api/v1/admin/quota/rules/{quotarule}", Params{"quotarule": quotarule})
|
|
|
|
|
var out types.QuotaRuleInfo
|
|
|
|
|
if err := s.client.Get(ctx, path, &out); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return &out, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// EditQuotaRule updates an existing quota rule.
|
|
|
|
|
func (s *AdminService) EditQuotaRule(ctx context.Context, quotarule string, opts *types.EditQuotaRuleOptions) (*types.QuotaRuleInfo, error) {
|
|
|
|
|
path := ResolvePath("/api/v1/admin/quota/rules/{quotarule}", Params{"quotarule": quotarule})
|
|
|
|
|
var out types.QuotaRuleInfo
|
|
|
|
|
if err := s.client.Patch(ctx, path, opts, &out); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return &out, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeleteQuotaRule deletes a quota rule.
|
|
|
|
|
func (s *AdminService) DeleteQuotaRule(ctx context.Context, quotarule string) error {
|
|
|
|
|
path := ResolvePath("/api/v1/admin/quota/rules/{quotarule}", Params{"quotarule": quotarule})
|
|
|
|
|
return s.client.Delete(ctx, path)
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-02 00:47:58 +00:00
|
|
|
// SearchEmails searches all email addresses by keyword (admin only).
|
|
|
|
|
func (s *AdminService) SearchEmails(ctx context.Context, q string) ([]types.Email, error) {
|
|
|
|
|
return ListAll[types.Email](ctx, s.client, "/api/v1/admin/emails/search", map[string]string{"q": q})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IterSearchEmails returns an iterator over all email addresses matching a keyword (admin only).
|
|
|
|
|
func (s *AdminService) IterSearchEmails(ctx context.Context, q string) iter.Seq2[types.Email, error] {
|
|
|
|
|
return ListIter[types.Email](ctx, s.client, "/api/v1/admin/emails/search", map[string]string{"q": q})
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-21 15:57:09 +00:00
|
|
|
// RunCron runs a cron task by name (admin only).
|
|
|
|
|
func (s *AdminService) RunCron(ctx context.Context, task string) error {
|
2026-03-09 08:31:16 +00:00
|
|
|
path := ResolvePath("/api/v1/admin/cron/{task}", Params{"task": task})
|
2026-02-21 15:57:09 +00:00
|
|
|
return s.client.Post(ctx, path, nil, nil)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ListCron returns all cron tasks (admin only).
|
|
|
|
|
func (s *AdminService) ListCron(ctx context.Context) ([]types.Cron, error) {
|
|
|
|
|
return ListAll[types.Cron](ctx, s.client, "/api/v1/admin/cron", 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
|
|
|
// IterCron returns an iterator over all cron tasks (admin only).
|
|
|
|
|
func (s *AdminService) IterCron(ctx context.Context) iter.Seq2[types.Cron, error] {
|
|
|
|
|
return ListIter[types.Cron](ctx, s.client, "/api/v1/admin/cron", nil)
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-21 15:57:09 +00:00
|
|
|
// AdoptRepo adopts an unadopted repository (admin only).
|
|
|
|
|
func (s *AdminService) AdoptRepo(ctx context.Context, owner, repo string) error {
|
2026-03-09 08:31:16 +00:00
|
|
|
path := ResolvePath("/api/v1/admin/unadopted/{owner}/{repo}", Params{"owner": owner, "repo": repo})
|
2026-02-21 15:57:09 +00:00
|
|
|
return s.client.Post(ctx, path, nil, nil)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GenerateRunnerToken generates an actions runner registration token.
|
|
|
|
|
func (s *AdminService) GenerateRunnerToken(ctx context.Context) (string, error) {
|
|
|
|
|
var out struct {
|
|
|
|
|
Token string `json:"token"`
|
|
|
|
|
}
|
|
|
|
|
if err := s.client.Get(ctx, "/api/v1/admin/runners/registration-token", &out); err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
return out.Token, nil
|
|
|
|
|
}
|