Skip to content

feat: Harness list commits api update as per new spec #277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2023
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
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": "[email protected]"
{
"commits": [
{
"sha": "1d640265d8bdd818175fa736f0fcbad2c9b716c9",
"title": "delete README.2",
"message": "delete README.2\n\ndelete README.2",
"author": {
"identity": {
"name": "thomas.honey",
"email": "[email protected]"
},
"when": "2023-02-08T16:17:50Z"
},
"when": "2023-02-08T16:17:50Z"
},
"committer": {
"identity": {
"name": "Harness",
"email": "[email protected]"
},
"when": "2023-02-08T16:17:50Z"
"committer": {
"identity": {
"name": "Harness",
"email": "[email protected]"
},
"when": "2023-02-08T16:17:50Z"
}
}
}
]
]
}