Skip to content

Commit fc4336b

Browse files
feat: add list namespace for repos (#309)
* feat: add list namespace * feat: add list namespace * feat: add list namespace * add for remaining * add for remaining * Update repo.go * address comment * address comment * Update repo.go
1 parent 99568c3 commit fc4336b

File tree

10 files changed

+70
-0
lines changed

10 files changed

+70
-0
lines changed

scm/driver/azure/repo.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ func (s *RepositoryService) ListV2(ctx context.Context, opts scm.RepoListOptions
6363
return s.List(ctx, opts.ListOptions)
6464
}
6565

66+
// ListNamespace is of no use in azure as our client already has project information
67+
func (s *RepositoryService) ListNamespace(ctx context.Context, _ string, opts scm.ListOptions) ([]*scm.Repository, *scm.Response, error) {
68+
// Azure client already has org/proj information
69+
return s.List(ctx, opts)
70+
}
71+
6672
// ListHooks returns a list or repository hooks.
6773
func (s *RepositoryService) ListHooks(ctx context.Context, repo string, opts scm.ListOptions) ([]*scm.Hook, *scm.Response, error) {
6874
// https://docs.microsoft.com/en-us/rest/api/azure/devops/hooks/subscriptions/list?view=azure-devops-rest-6.0

scm/driver/bitbucket/repo.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,17 @@ func (s *repositoryService) ListV2(ctx context.Context, opts scm.RepoListOptions
117117
return convertRepositoryList(out), res, err
118118
}
119119

120+
func (s *repositoryService) ListNamespace(ctx context.Context, namespace string, opts scm.ListOptions) ([]*scm.Repository, *scm.Response, error) {
121+
path := fmt.Sprintf("2.0/repositories/%s?%s", namespace, encodeListRoleOptions(opts))
122+
if opts.URL != "" {
123+
path = opts.URL
124+
}
125+
out := new(repositories)
126+
res, err := s.client.do(ctx, "GET", path, nil, &out)
127+
copyPagination(out.pagination, res)
128+
return convertRepositoryList(out), res, err
129+
}
130+
120131
// ListHooks returns a list or repository hooks.
121132
func (s *repositoryService) ListHooks(ctx context.Context, repo string, opts scm.ListOptions) ([]*scm.Hook, *scm.Response, error) {
122133
path := fmt.Sprintf("2.0/repositories/%s/hooks?%s", repo, encodeListOptions(opts))

scm/driver/gitea/repo.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ func (s *repositoryService) ListV2(ctx context.Context, opts scm.RepoListOptions
5151
return s.List(ctx, opts.ListOptions)
5252
}
5353

54+
func (s *repositoryService) ListNamespace(ctx context.Context, namespace string, opts scm.ListOptions) ([]*scm.Repository, *scm.Response, error) {
55+
path := fmt.Sprintf("api/v1/orgs/%s/repos?%s", namespace, encodeListOptions(opts))
56+
out := []*repository{}
57+
res, err := s.client.do(ctx, "GET", path, nil, &out)
58+
return convertRepositoryList(out), res, err
59+
}
60+
5461
func (s *repositoryService) ListHooks(ctx context.Context, repo string, opts scm.ListOptions) ([]*scm.Hook, *scm.Response, error) {
5562
path := fmt.Sprintf("api/v1/repos/%s/hooks?%s", repo, encodeListOptions(opts))
5663
out := []*hook{}

scm/driver/gitee/repo.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ func (s *RepositoryService) ListV2(ctx context.Context, opts scm.RepoListOptions
5050
return s.List(ctx, opts.ListOptions)
5151
}
5252

53+
func (s *RepositoryService) ListNamespace(ctx context.Context, namespace string, opts scm.ListOptions) ([]*scm.Repository, *scm.Response, error) {
54+
return nil, nil, scm.ErrNotSupported
55+
}
56+
5357
func (s *RepositoryService) ListHooks(ctx context.Context, repo string, opts scm.ListOptions) ([]*scm.Hook, *scm.Response, error) {
5458
path := fmt.Sprintf("repos/%s/hooks?%s", repo, encodeListOptions(opts))
5559
out := []*hook{}

scm/driver/github/repo.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ func (s *RepositoryService) ListV2(ctx context.Context, opts scm.RepoListOptions
122122
return convertRepositoryList(out.Repositories), res, err
123123
}
124124

125+
// ListNamespace returns the user repository list based on searchterm and namespace.
126+
func (s *RepositoryService) ListNamespace(ctx context.Context, namespace string, opts scm.ListOptions) ([]*scm.Repository, *scm.Response, error) {
127+
path := fmt.Sprintf("orgs/%s/repos?%s", namespace, encodeListOptions(opts))
128+
out := new(searchRepositoryList)
129+
res, err := s.client.do(ctx, "GET", path, nil, &out)
130+
return convertRepositoryList(out.Repositories), res, err
131+
}
132+
125133
// List returns the github app installation repository list.
126134
func (s *RepositoryService) ListByInstallation(ctx context.Context, opts scm.ListOptions) ([]*scm.Repository, *scm.Response, error) {
127135
path := fmt.Sprintf("installation/repositories?%s", encodeListOptions(opts))

scm/driver/gitlab/repo.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ func (s *repositoryService) ListV2(ctx context.Context, opts scm.RepoListOptions
102102
return convertRepositoryList(out), res, err
103103
}
104104

105+
func (s *repositoryService) ListNamespace(ctx context.Context, namespace string, opts scm.ListOptions) ([]*scm.Repository, *scm.Response, error) {
106+
path := fmt.Sprintf("api/v4/groups/%s/projects?%s", namespace, encodeMemberListOptions(opts))
107+
out := []*repository{}
108+
res, err := s.client.do(ctx, "GET", path, nil, &out)
109+
return convertRepositoryList(out), res, err
110+
}
111+
105112
func (s *repositoryService) ListHooks(ctx context.Context, repo string, opts scm.ListOptions) ([]*scm.Hook, *scm.Response, error) {
106113
path := fmt.Sprintf("api/v4/projects/%s/hooks?%s", encode(repo), encodeListOptions(opts))
107114
out := []*hook{}

scm/driver/gogs/repo.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ func (s *repositoryService) ListV2(ctx context.Context, opts scm.RepoListOptions
5050
return s.List(ctx, opts.ListOptions)
5151
}
5252

53+
func (s *repositoryService) ListNamespace(ctx context.Context, namespace string, opts scm.ListOptions) ([]*scm.Repository, *scm.Response, error) {
54+
path := fmt.Sprintf("api/v1/orgs/%s/repos", namespace)
55+
out := []*repository{}
56+
res, err := s.client.do(ctx, "GET", path, nil, &out)
57+
return convertRepositoryList(out), res, err
58+
}
59+
5360
func (s *repositoryService) ListHooks(ctx context.Context, repo string, _ scm.ListOptions) ([]*scm.Hook, *scm.Response, error) {
5461
path := fmt.Sprintf("api/v1/repos/%s/hooks", repo)
5562
out := []*hook{}

scm/driver/harness/repo.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ func (s *repositoryService) ListV2(ctx context.Context, opts scm.RepoListOptions
6868
return s.List(ctx, opts.ListOptions)
6969
}
7070

71+
func (s *repositoryService) ListNamespace(ctx context.Context, _ string, opts scm.ListOptions) ([]*scm.Repository, *scm.Response, error) {
72+
// Client already has context about namespace
73+
return s.List(ctx, opts)
74+
}
75+
7176
func (s *repositoryService) ListHooks(ctx context.Context, repo string, opts scm.ListOptions) ([]*scm.Hook, *scm.Response, error) {
7277
harnessURI := buildHarnessURI(s.client.account, s.client.organization, s.client.project, repo)
7378
repoId, queryParams, err := getRepoAndQueryParams(harnessURI)

scm/driver/stash/repo.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,18 @@ func (s *repositoryService) ListV2(ctx context.Context, opts scm.RepoListOptions
192192
return convertRepositoryList(out), res, err
193193
}
194194

195+
// ListNamespace returns the user repository list based on searchterm and namespace.
196+
func (s *repositoryService) ListNamespace(ctx context.Context, namespace string, opts scm.ListOptions) ([]*scm.Repository, *scm.Response, error) {
197+
path := fmt.Sprintf("rest/api/1.0/projects/%s/repos?%s", namespace, encodeListRoleOptions(opts))
198+
out := new(repositories)
199+
res, err := s.client.do(ctx, "GET", path, nil, &out)
200+
if res != nil && !out.pagination.LastPage.Bool {
201+
res.Page.First = 1
202+
res.Page.Next = opts.Page + 1
203+
}
204+
return convertRepositoryList(out), res, err
205+
}
206+
195207
// listWrite returns the user repository list.
196208
func (s *repositoryService) listWrite(ctx context.Context, repo string) ([]*scm.Repository, *scm.Response, error) {
197209
_, name := scm.Split(repo)

scm/repo.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ type (
123123
// ListV2 returns a list of repositories based on the searchTerm passed.
124124
ListV2(context.Context, RepoListOptions) ([]*Repository, *Response, error)
125125

126+
// ListNamespace returns a list of repos in namespace
127+
ListNamespace(context.Context, string, ListOptions) ([]*Repository, *Response, error)
128+
126129
// ListHooks returns a list or repository hooks.
127130
ListHooks(context.Context, string, ListOptions) ([]*Hook, *Response, error)
128131

0 commit comments

Comments
 (0)