go-forge/teams.go
Snider 0a9564274d
All checks were successful
Security Scan / security (pull_request) Successful in 9s
Test / test (pull_request) Successful in 1m20s
refactor(module): migrate module path to dappco.re/go/core/forge
Update Go module path from forge.lthn.ai/core/go-forge to
dappco.re/go/core/forge. Migrate all import paths and dependency
references (go-io → dappco.re/go/core/io, go-log → dappco.re/go/core/log).
Update documentation (CLAUDE.md, README.md, docs/) to reflect new paths.

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 01:51:29 +00:00

82 lines
3 KiB
Go

package forge
import (
"context"
"fmt"
"iter"
"dappco.re/go/core/forge/types"
)
// TeamService handles team operations.
type TeamService struct {
Resource[types.Team, types.CreateTeamOption, types.EditTeamOption]
}
func newTeamService(c *Client) *TeamService {
return &TeamService{
Resource: *NewResource[types.Team, types.CreateTeamOption, types.EditTeamOption](
c, "/api/v1/teams/{id}",
),
}
}
// ListMembers returns all members of a team.
func (s *TeamService) ListMembers(ctx context.Context, teamID int64) ([]types.User, error) {
path := fmt.Sprintf("/api/v1/teams/%d/members", teamID)
return ListAll[types.User](ctx, s.client, path, nil)
}
// IterMembers returns an iterator over all members of a team.
func (s *TeamService) IterMembers(ctx context.Context, teamID int64) iter.Seq2[types.User, error] {
path := fmt.Sprintf("/api/v1/teams/%d/members", teamID)
return ListIter[types.User](ctx, s.client, path, nil)
}
// AddMember adds a user to a team.
func (s *TeamService) AddMember(ctx context.Context, teamID int64, username string) error {
path := fmt.Sprintf("/api/v1/teams/%d/members/%s", teamID, username)
return s.client.Put(ctx, path, nil, nil)
}
// RemoveMember removes a user from a team.
func (s *TeamService) RemoveMember(ctx context.Context, teamID int64, username string) error {
path := fmt.Sprintf("/api/v1/teams/%d/members/%s", teamID, username)
return s.client.Delete(ctx, path)
}
// ListRepos returns all repositories managed by a team.
func (s *TeamService) ListRepos(ctx context.Context, teamID int64) ([]types.Repository, error) {
path := fmt.Sprintf("/api/v1/teams/%d/repos", teamID)
return ListAll[types.Repository](ctx, s.client, path, nil)
}
// IterRepos returns an iterator over all repositories managed by a team.
func (s *TeamService) IterRepos(ctx context.Context, teamID int64) iter.Seq2[types.Repository, error] {
path := fmt.Sprintf("/api/v1/teams/%d/repos", teamID)
return ListIter[types.Repository](ctx, s.client, path, nil)
}
// AddRepo adds a repository to a team.
func (s *TeamService) AddRepo(ctx context.Context, teamID int64, org, repo string) error {
path := fmt.Sprintf("/api/v1/teams/%d/repos/%s/%s", teamID, org, repo)
return s.client.Put(ctx, path, nil, nil)
}
// RemoveRepo removes a repository from a team.
func (s *TeamService) RemoveRepo(ctx context.Context, teamID int64, org, repo string) error {
path := fmt.Sprintf("/api/v1/teams/%d/repos/%s/%s", teamID, org, repo)
return s.client.Delete(ctx, path)
}
// ListOrgTeams returns all teams in an organisation.
func (s *TeamService) ListOrgTeams(ctx context.Context, org string) ([]types.Team, error) {
path := fmt.Sprintf("/api/v1/orgs/%s/teams", org)
return ListAll[types.Team](ctx, s.client, path, nil)
}
// IterOrgTeams returns an iterator over all teams in an organisation.
func (s *TeamService) IterOrgTeams(ctx context.Context, org string) iter.Seq2[types.Team, error] {
path := fmt.Sprintf("/api/v1/orgs/%s/teams", org)
return ListIter[types.Team](ctx, s.client, path, nil)
}