Skip to content

Commit 98b7432

Browse files
Merge pull request #341 from drone/CDE-986
fix: [CDE-986]: Adding support for search in ListV2 API in harness driver.
2 parents 352d8aa + b2de1d5 commit 98b7432

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

scm/client.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,11 @@ type (
9191
// ListOptions specifies optional pagination
9292
// parameters.
9393
ListOptions struct {
94-
URL string
95-
Page int
96-
Size int
94+
URL string
95+
Page int
96+
Size int
97+
SortKey string
98+
Order string
9799
}
98100

99101
// Client manages communication with a version control

scm/driver/harness/repo.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,38 @@ func (s *repositoryService) FindPerms(ctx context.Context, repo string) (*scm.Pe
5353
}
5454

5555
func (s *repositoryService) List(ctx context.Context, opts scm.ListOptions) ([]*scm.Repository, *scm.Response, error) {
56+
return s.list(ctx, scm.RepoListOptions{
57+
ListOptions: opts,
58+
})
59+
}
60+
61+
func (s *repositoryService) list(ctx context.Context, opts scm.RepoListOptions) ([]*scm.Repository, *scm.Response, error) {
5662
queryParams := fmt.Sprintf("%s=%s&%s=%s&%s=%s&%s=%s",
5763
projectIdentifier, s.client.project, orgIdentifier, s.client.organization, accountIdentifier, s.client.account,
5864
routingId, s.client.account)
5965

60-
path := fmt.Sprintf("api/v1/repos?sort=path&order=asc&%s&%s", encodeListOptions(opts), queryParams)
66+
if opts.RepoSearchTerm.RepoName != "" {
67+
queryParams = fmt.Sprintf("%s&query=%s", queryParams, opts.RepoSearchTerm.RepoName)
68+
}
69+
70+
sortKey := defaultSortKey
71+
if opts.ListOptions.SortKey != "" {
72+
sortKey = opts.ListOptions.SortKey
73+
}
74+
75+
order := defaultOrder
76+
if opts.ListOptions.Order != "" {
77+
order = opts.ListOptions.Order
78+
}
79+
80+
path := fmt.Sprintf("api/v1/repos?sort=%s&order=%s&%s&%s", sortKey, order, encodeListOptions(opts.ListOptions), queryParams)
6181
out := []*repository{}
6282
res, err := s.client.do(ctx, "GET", path, nil, &out)
6383
return convertRepositoryList(out), res, err
6484
}
6585

6686
func (s *repositoryService) ListV2(ctx context.Context, opts scm.RepoListOptions) ([]*scm.Repository, *scm.Response, error) {
67-
// harness does not support search filters, hence calling List api without search filtering
68-
return s.List(ctx, opts.ListOptions)
87+
return s.list(ctx, opts)
6988
}
7089

7190
func (s *repositoryService) ListNamespace(ctx context.Context, _ string, opts scm.ListOptions) ([]*scm.Repository, *scm.Response, error) {

scm/driver/harness/util.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const (
1818
projectIdentifier = "projectIdentifier"
1919
orgIdentifier = "orgIdentifier"
2020
routingId = "routingId"
21+
defaultSortKey = "path"
22+
defaultOrder = "asc"
2123
)
2224

2325
func buildHarnessURI(account, organization, project, repo string) (uri string) {

0 commit comments

Comments
 (0)