diff --git a/scm/driver/harness/git.go b/scm/driver/harness/git.go index 309a125f7..85b17bff1 100644 --- a/scm/driver/harness/git.go +++ b/scm/driver/harness/git.go @@ -63,7 +63,7 @@ func (s *gitService) ListBranchesV2(ctx context.Context, repo string, opts scm.B func (s *gitService) ListCommits(ctx context.Context, repo string, _ scm.CommitListOptions) ([]*scm.Commit, *scm.Response, error) { harnessURI := buildHarnessURI(s.client.account, s.client.organization, s.client.project, repo) path := fmt.Sprintf("api/v1/repos/%s/commits", harnessURI) - out := []*commitInfo{} + out := new(commits) res, err := s.client.do(ctx, "GET", path, nil, &out) return convertCommitList(out), res, err } @@ -86,6 +86,10 @@ func (s *gitService) CompareChanges(ctx context.Context, repo, source, target st // native data structures type ( + commits struct { + Commits []commitInfo `json:"commits"` + } + commitInfo struct { Author struct { Identity struct { @@ -168,10 +172,10 @@ func convertBranch(src *branch) *scm.Reference { } } -func convertCommitList(src []*commitInfo) []*scm.Commit { - dst := []*scm.Commit{} - for _, v := range src { - dst = append(dst, convertCommitInfo(v)) +func convertCommitList(src *commits) []*scm.Commit { + var dst []*scm.Commit + for _, v := range src.Commits { + dst = append(dst, convertCommitInfo(&v)) } return dst } diff --git a/scm/driver/harness/testdata/commits.json b/scm/driver/harness/testdata/commits.json index 96576e18f..4045985d6 100644 --- a/scm/driver/harness/testdata/commits.json +++ b/scm/driver/harness/testdata/commits.json @@ -1,21 +1,23 @@ -[ - { - "sha": "1d640265d8bdd818175fa736f0fcbad2c9b716c9", - "title": "delete README.2", - "message": "delete README.2\n\ndelete README.2", - "author": { - "identity": { - "name": "thomas.honey", - "email": "thomas.honey@harness.io" +{ + "commits": [ + { + "sha": "1d640265d8bdd818175fa736f0fcbad2c9b716c9", + "title": "delete README.2", + "message": "delete README.2\n\ndelete README.2", + "author": { + "identity": { + "name": "thomas.honey", + "email": "thomas.honey@harness.io" + }, + "when": "2023-02-08T16:17:50Z" }, - "when": "2023-02-08T16:17:50Z" - }, - "committer": { - "identity": { - "name": "Harness", - "email": "noreply@harness.io" - }, - "when": "2023-02-08T16:17:50Z" + "committer": { + "identity": { + "name": "Harness", + "email": "noreply@harness.io" + }, + "when": "2023-02-08T16:17:50Z" + } } - } -] \ No newline at end of file + ] +} \ No newline at end of file