Skip to content

Commit beec4da

Browse files
Merge pull request #261 from adivishy1/master
[feat]: [CDS-73572]: Support List Repo Live Search for all git providers
2 parents 3947016 + 70cccf8 commit beec4da

39 files changed

+757
-30
lines changed

scm/client.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,19 @@ type (
7575
PageListOptions ListOptions
7676
}
7777

78+
// RepoListOptions specifies optional repo search term and pagination
79+
// parameters.
80+
RepoListOptions struct {
81+
ListOptions
82+
RepoSearchTerm
83+
}
84+
85+
// RepoSearchTerm specifies searchable parameters.
86+
RepoSearchTerm struct {
87+
RepoName string
88+
User string
89+
}
90+
7891
// ListOptions specifies optional pagination
7992
// parameters.
8093
ListOptions struct {

scm/driver/azure/git_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func TestGitListBranchesV2(t *testing.T) {
130130
Get("/ORG/PROJ/_apis/git/repositories/REPOID/").
131131
Reply(200).
132132
Type("application/json").
133-
File("testdata/branchesFilter.json")
133+
File("testdata/branches_filter.json")
134134

135135
client := NewDefault("ORG", "PROJ")
136136
got, _, err := client.Git.ListBranchesV2(context.Background(), "REPOID", scm.BranchListOptions{SearchTerm: "main"})
@@ -140,7 +140,7 @@ func TestGitListBranchesV2(t *testing.T) {
140140
}
141141

142142
want := []*scm.Reference{}
143-
raw, _ := ioutil.ReadFile("testdata/branchesFilter.json.golden")
143+
raw, _ := ioutil.ReadFile("testdata/branches_filter.json.golden")
144144
_ = json.Unmarshal(raw, &want)
145145

146146
if diff := cmp.Diff(got, want); diff != "" {

scm/driver/azure/repo.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ func (s *RepositoryService) List(ctx context.Context, opts scm.ListOptions) ([]*
5656
return convertRepositoryList(out), res, err
5757
}
5858

59+
// ListV2 returns the user repository list.
60+
func (s *RepositoryService) ListV2(ctx context.Context, opts scm.RepoListOptions) ([]*scm.Repository, *scm.Response, error) {
61+
// Azure does not support search filters, hence calling List api without search filtering
62+
return s.List(ctx, opts.ListOptions)
63+
}
64+
5965
// ListHooks returns a list or repository hooks.
6066
func (s *RepositoryService) ListHooks(ctx context.Context, repo string, opts scm.ListOptions) ([]*scm.Hook, *scm.Response, error) {
6167
// https://docs.microsoft.com/en-us/rest/api/azure/devops/hooks/subscriptions/list?view=azure-devops-rest-6.0
File renamed without changes.
File renamed without changes.

scm/driver/bitbucket/git_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,20 +216,19 @@ func TestGitListBranchesV2(t *testing.T) {
216216
MatchParam("pagelen", "30").
217217
Reply(200).
218218
Type("application/json").
219-
File("testdata/branchesFilter.json")
219+
File("testdata/branches_filter.json")
220220

221221
client, _ := New("https://api.bitbucket.org")
222-
got, res, err := client.Git.ListBranchesV2(context.Background(), "atlassian/stash-example-plugin", scm.BranchListOptions{SearchTerm: "mast", PageListOptions: struct {
223-
URL string
224-
Page int
225-
Size int
226-
}{Page: 1, Size: 30}})
222+
got, res, err := client.Git.ListBranchesV2(context.Background(), "atlassian/stash-example-plugin", scm.BranchListOptions{
223+
SearchTerm: "mast",
224+
PageListOptions: scm.ListOptions{Page: 1, Size: 30},
225+
})
227226
if err != nil {
228227
t.Error(err)
229228
}
230229

231230
want := []*scm.Reference{}
232-
raw, _ := ioutil.ReadFile("testdata/branchesFilter.json.golden")
231+
raw, _ := ioutil.ReadFile("testdata/branches_filter.json.golden")
233232
json.Unmarshal(raw, &want)
234233

235234
if diff := cmp.Diff(got, want); diff != "" {

scm/driver/bitbucket/repo.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,18 @@ func (s *repositoryService) List(ctx context.Context, opts scm.ListOptions) ([]*
105105
return convertRepositoryList(out), res, err
106106
}
107107

108+
// ListV2 returns the user repository list based on the searchTerm passed.
109+
func (s *repositoryService) ListV2(ctx context.Context, opts scm.RepoListOptions) ([]*scm.Repository, *scm.Response, error) {
110+
path := fmt.Sprintf("2.0/repositories?%s", encodeRepoListOptions(opts))
111+
if opts.ListOptions.URL != "" {
112+
path = opts.ListOptions.URL
113+
}
114+
out := new(repositories)
115+
res, err := s.client.do(ctx, "GET", path, nil, &out)
116+
copyPagination(out.pagination, res)
117+
return convertRepositoryList(out), res, err
118+
}
119+
108120
// ListHooks returns a list or repository hooks.
109121
func (s *repositoryService) ListHooks(ctx context.Context, repo string, opts scm.ListOptions) ([]*scm.Hook, *scm.Response, error) {
110122
path := fmt.Sprintf("2.0/repositories/%s/hooks?%s", repo, encodeListOptions(opts))

scm/driver/bitbucket/repo_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,37 @@ func TestRepositoryList(t *testing.T) {
136136
}
137137
}
138138

139+
func TestRepositoryListV2(t *testing.T) {
140+
defer gock.Off()
141+
142+
gock.New("https://api.bitbucket.org").
143+
Get("/2.0/repositories").
144+
MatchParam("q", "name~\\\"plugin1\\\"").
145+
MatchParam("role", "member").
146+
Reply(200).
147+
Type("application/json").
148+
File("testdata/repos_filter.json")
149+
150+
got := []*scm.Repository{}
151+
opts := scm.RepoListOptions{RepoSearchTerm: scm.RepoSearchTerm{RepoName: "plugin1"}}
152+
client, _ := New("https://api.bitbucket.org")
153+
154+
repos, _, err := client.Repositories.ListV2(context.Background(), opts)
155+
if err != nil {
156+
t.Error(err)
157+
}
158+
got = append(got, repos...)
159+
160+
want := []*scm.Repository{}
161+
raw, _ := ioutil.ReadFile("testdata/repos_filter.json.golden")
162+
json.Unmarshal(raw, &want)
163+
164+
if diff := cmp.Diff(got, want); diff != "" {
165+
t.Errorf("Unexpected Results")
166+
t.Log(diff)
167+
}
168+
}
169+
139170
func TestStatusList(t *testing.T) {
140171
defer gock.Off()
141172

File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)