Skip to content

Commit

Permalink
fix: Harness list commits api update as per new spec (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinav-harness authored Oct 3, 2023
1 parent 60fa179 commit 3b21a0f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
14 changes: 9 additions & 5 deletions scm/driver/harness/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
40 changes: 21 additions & 19 deletions scm/driver/harness/testdata/commits.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
]
]
}

0 comments on commit 3b21a0f

Please sign in to comment.