Skip to content

Commit 4b9ccaa

Browse files
Merge pull request #346 from drone/CI-19242
feat: [CI-19242]: Adding go-scm fix for fetching user repos in getting started.
2 parents 0efcc14 + 5e9655f commit 4b9ccaa

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

scm/driver/github/repo.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,16 @@ func (s *RepositoryService) List(ctx context.Context, opts scm.ListOptions) ([]*
114114
return convertRepositoryList(out), res, err
115115
}
116116

117+
// ListWithAffiliation returns the user repository list filtered by affiliation.
118+
// affiliation can be: "owner", "collaborator", "organization_member", or comma-separated combinations.
119+
// Example: "owner,collaborator" returns repos where user is owner or collaborator.
120+
func (s *RepositoryService) ListWithAffiliation(ctx context.Context, opts scm.ListOptions, affiliation string) ([]*scm.Repository, *scm.Response, error) {
121+
path := fmt.Sprintf("user/repos?%s", encodeListOptionsWithAffiliation(opts, affiliation))
122+
out := []*repository{}
123+
res, err := s.client.do(ctx, "GET", path, nil, &out)
124+
return convertRepositoryList(out), res, err
125+
}
126+
117127
// ListV2 returns the user repository list based on the searchTerm passed.
118128
func (s *RepositoryService) ListV2(ctx context.Context, opts scm.RepoListOptions) ([]*scm.Repository, *scm.Response, error) {
119129
path := fmt.Sprintf("search/repositories?%s", encodeRepoListOptions(opts))

scm/driver/github/util.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,22 @@ func encodeListOptions(opts scm.ListOptions) string {
2323
return params.Encode()
2424
}
2525

26+
// encodeListOptionsWithAffiliation adds affiliation parameter for filtering user repos.
27+
// affiliation can be: "owner", "collaborator", "organization_member", or comma-separated combinations.
28+
func encodeListOptionsWithAffiliation(opts scm.ListOptions, affiliation string) string {
29+
params := url.Values{}
30+
if opts.Page != 0 {
31+
params.Set("page", strconv.Itoa(opts.Page))
32+
}
33+
if opts.Size != 0 {
34+
params.Set("per_page", strconv.Itoa(opts.Size))
35+
}
36+
if affiliation != "" {
37+
params.Set("affiliation", affiliation)
38+
}
39+
return params.Encode()
40+
}
41+
2642
func encodeRepoListOptions(opts scm.RepoListOptions) string {
2743
var sb strings.Builder
2844
if opts.RepoSearchTerm != (scm.RepoSearchTerm{}) {

0 commit comments

Comments
 (0)