Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions scm/driver/github/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ func (s *RepositoryService) List(ctx context.Context, opts scm.ListOptions) ([]*
return convertRepositoryList(out), res, err
}

// ListWithAffiliation returns the user repository list filtered by affiliation.
// affiliation can be: "owner", "collaborator", "organization_member", or comma-separated combinations.
// Example: "owner,collaborator" returns repos where user is owner or collaborator.
func (s *RepositoryService) ListWithAffiliation(ctx context.Context, opts scm.ListOptions, affiliation string) ([]*scm.Repository, *scm.Response, error) {
path := fmt.Sprintf("user/repos?%s", encodeListOptionsWithAffiliation(opts, affiliation))
out := []*repository{}
res, err := s.client.do(ctx, "GET", path, nil, &out)
return convertRepositoryList(out), res, err
}

// ListV2 returns the user repository list based on the searchTerm passed.
func (s *RepositoryService) ListV2(ctx context.Context, opts scm.RepoListOptions) ([]*scm.Repository, *scm.Response, error) {
path := fmt.Sprintf("search/repositories?%s", encodeRepoListOptions(opts))
Expand Down
16 changes: 16 additions & 0 deletions scm/driver/github/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ func encodeListOptions(opts scm.ListOptions) string {
return params.Encode()
}

// encodeListOptionsWithAffiliation adds affiliation parameter for filtering user repos.
// affiliation can be: "owner", "collaborator", "organization_member", or comma-separated combinations.
func encodeListOptionsWithAffiliation(opts scm.ListOptions, affiliation string) string {
params := url.Values{}
if opts.Page != 0 {
params.Set("page", strconv.Itoa(opts.Page))
}
if opts.Size != 0 {
params.Set("per_page", strconv.Itoa(opts.Size))
}
if affiliation != "" {
params.Set("affiliation", affiliation)
}
return params.Encode()
}

func encodeRepoListOptions(opts scm.RepoListOptions) string {
var sb strings.Builder
if opts.RepoSearchTerm != (scm.RepoSearchTerm{}) {
Expand Down