From 5e9655f6492ab8ac36937a13a042dbcee94a20fc Mon Sep 17 00:00:00 2001 From: Devansh Mathur Date: Fri, 31 Oct 2025 12:56:28 +0530 Subject: [PATCH] feat: [CI-19242]: Adding go-scm fix for getting started repo fix. --- scm/driver/github/repo.go | 10 ++++++++++ scm/driver/github/util.go | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/scm/driver/github/repo.go b/scm/driver/github/repo.go index cad7f917..96dee7b5 100644 --- a/scm/driver/github/repo.go +++ b/scm/driver/github/repo.go @@ -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)) diff --git a/scm/driver/github/util.go b/scm/driver/github/util.go index 24a0c858..ee093788 100644 --- a/scm/driver/github/util.go +++ b/scm/driver/github/util.go @@ -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{}) {