Skip to content

Commit e578c65

Browse files
author
TP Honey
authored
Merge pull request #286 from drone/abhinav/list-commit-harness
fix: use opts for harness list commits
2 parents 868dd43 + 05fe67f commit e578c65

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

scm/driver/harness/git.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ func (s *gitService) ListBranchesV2(ctx context.Context, repo string, opts scm.B
6060
return s.ListBranches(ctx, repo, opts.PageListOptions)
6161
}
6262

63-
func (s *gitService) ListCommits(ctx context.Context, repo string, _ scm.CommitListOptions) ([]*scm.Commit, *scm.Response, error) {
63+
func (s *gitService) ListCommits(ctx context.Context, repo string, opts scm.CommitListOptions) ([]*scm.Commit, *scm.Response, error) {
6464
harnessURI := buildHarnessURI(s.client.account, s.client.organization, s.client.project, repo)
65-
path := fmt.Sprintf("api/v1/repos/%s/commits", harnessURI)
65+
path := fmt.Sprintf("api/v1/repos/%s/commits?%s", harnessURI, encodeCommitListOptions(opts))
6666
out := new(commits)
6767
res, err := s.client.do(ctx, "GET", path, nil, &out)
6868
return convertCommitList(out), res, err

scm/driver/harness/util.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,20 @@ func encodeReleaseListOptions(o ListOptions) string {
114114
query.Add("limit", fmt.Sprintf("%d", o.PageSize))
115115
return query.Encode()
116116
}
117+
118+
func encodeCommitListOptions(opts scm.CommitListOptions) string {
119+
params := url.Values{}
120+
if opts.Page != 0 {
121+
params.Set("page", strconv.Itoa(opts.Page))
122+
}
123+
if opts.Size != 0 {
124+
params.Set("limit", strconv.Itoa(opts.Size))
125+
}
126+
if opts.Ref != "" {
127+
params.Set("git_ref", opts.Ref)
128+
}
129+
if opts.Path != "" {
130+
params.Set("path", opts.Path)
131+
}
132+
return params.Encode()
133+
}

0 commit comments

Comments
 (0)