feat(repo): add assignee helpers
All checks were successful
Security Scan / security (push) Successful in 10s
Test / test (push) Successful in 58s

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-01 22:22:57 +00:00
parent 3b1ed341e2
commit 3a00e9febf
2 changed files with 64 additions and 0 deletions

View file

@ -83,6 +83,18 @@ func (s *RepoService) IterSubscribers(ctx context.Context, owner, repo string) i
return ListIter[types.User](ctx, s.client, path, nil)
}
// ListAssignees returns all users that can be assigned to issues in a repository.
func (s *RepoService) ListAssignees(ctx context.Context, owner, repo string) ([]types.User, error) {
path := ResolvePath("/api/v1/repos/{owner}/{repo}/assignees", pathParams("owner", owner, "repo", repo))
return ListAll[types.User](ctx, s.client, path, nil)
}
// IterAssignees returns an iterator over all users that can be assigned to issues in a repository.
func (s *RepoService) IterAssignees(ctx context.Context, owner, repo string) iter.Seq2[types.User, error] {
path := ResolvePath("/api/v1/repos/{owner}/{repo}/assignees", pathParams("owner", owner, "repo", repo))
return ListIter[types.User](ctx, s.client, path, nil)
}
// ListCollaborators returns all collaborators on a repository.
func (s *RepoService) ListCollaborators(ctx context.Context, owner, repo string) ([]types.User, error) {
path := ResolvePath("/api/v1/repos/{owner}/{repo}/collaborators", pathParams("owner", owner, "repo", repo))

View file

@ -206,6 +206,58 @@ func TestRepoService_ListSubscribers_Good(t *testing.T) {
}
}
func TestRepoService_ListAssignees_Good(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
t.Errorf("expected GET, got %s", r.Method)
}
if r.URL.Path != "/api/v1/repos/core/go-forge/assignees" {
t.Errorf("wrong path: %s", r.URL.Path)
http.NotFound(w, r)
return
}
json.NewEncoder(w).Encode([]types.User{{UserName: "alice"}, {UserName: "bob"}})
}))
defer srv.Close()
f := NewForge(srv.URL, "tok")
users, err := f.Repos.ListAssignees(context.Background(), "core", "go-forge")
if err != nil {
t.Fatal(err)
}
if len(users) != 2 || users[0].UserName != "alice" || users[1].UserName != "bob" {
t.Fatalf("got %#v", users)
}
}
func TestRepoService_IterAssignees_Good(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
t.Errorf("expected GET, got %s", r.Method)
}
if r.URL.Path != "/api/v1/repos/core/go-forge/assignees" {
t.Errorf("wrong path: %s", r.URL.Path)
http.NotFound(w, r)
return
}
w.Header().Set("X-Total-Count", "2")
json.NewEncoder(w).Encode([]types.User{{UserName: "alice"}, {UserName: "bob"}})
}))
defer srv.Close()
f := NewForge(srv.URL, "tok")
var names []string
for user, err := range f.Repos.IterAssignees(context.Background(), "core", "go-forge") {
if err != nil {
t.Fatal(err)
}
names = append(names, user.UserName)
}
if len(names) != 2 || names[0] != "alice" || names[1] != "bob" {
t.Fatalf("got %#v", names)
}
}
func TestRepoService_ListCollaborators_Good(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {