Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions scm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ type (
// ListOptions specifies optional pagination
// parameters.
ListOptions struct {
URL string
Page int
Size int
URL string
Page int
Size int
SortKey string
Order string
}

// Client manages communication with a version control
Expand Down
25 changes: 22 additions & 3 deletions scm/driver/harness/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,38 @@ func (s *repositoryService) FindPerms(ctx context.Context, repo string) (*scm.Pe
}

func (s *repositoryService) List(ctx context.Context, opts scm.ListOptions) ([]*scm.Repository, *scm.Response, error) {
return s.list(ctx, scm.RepoListOptions{
ListOptions: opts,
})
}

func (s *repositoryService) list(ctx context.Context, opts scm.RepoListOptions) ([]*scm.Repository, *scm.Response, error) {
queryParams := fmt.Sprintf("%s=%s&%s=%s&%s=%s&%s=%s",
projectIdentifier, s.client.project, orgIdentifier, s.client.organization, accountIdentifier, s.client.account,
routingId, s.client.account)

path := fmt.Sprintf("api/v1/repos?sort=path&order=asc&%s&%s", encodeListOptions(opts), queryParams)
if opts.RepoSearchTerm.RepoName != "" {
queryParams = fmt.Sprintf("%s&query=%s", queryParams, opts.RepoSearchTerm.RepoName)
}

sortKey := defaultSortKey
if opts.ListOptions.SortKey != "" {
sortKey = opts.ListOptions.SortKey
}

order := defaultOrder
if opts.ListOptions.Order != "" {
order = opts.ListOptions.Order
}

path := fmt.Sprintf("api/v1/repos?sort=%s&order=%s&%s&%s", sortKey, order, encodeListOptions(opts.ListOptions), queryParams)
out := []*repository{}
res, err := s.client.do(ctx, "GET", path, nil, &out)
return convertRepositoryList(out), res, err
}

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

func (s *repositoryService) ListNamespace(ctx context.Context, _ string, opts scm.ListOptions) ([]*scm.Repository, *scm.Response, error) {
Expand Down
2 changes: 2 additions & 0 deletions scm/driver/harness/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const (
projectIdentifier = "projectIdentifier"
orgIdentifier = "orgIdentifier"
routingId = "routingId"
defaultSortKey = "path"
defaultOrder = "asc"
)

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