Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
63 changes: 25 additions & 38 deletions scm/driver/harness/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,51 +133,17 @@ type (
}

commitInfo struct {
Author struct {
Identity struct {
Email string `json:"email"`
Name string `json:"name"`
} `json:"identity"`
When time.Time `json:"when"`
} `json:"author"`
Committer struct {
Identity struct {
Email string `json:"email"`
Name string `json:"name"`
} `json:"identity"`
When time.Time `json:"when"`
} `json:"committer"`
Message string `json:"message"`
Sha string `json:"sha"`
Title string `json:"title"`
commitInternal
}
branchInput struct {
Name string `json:"name"`
Target string `json:"target"`
BypassRules bool `json:"bypass_rules"`
}
branch struct {
Commit struct {
Author struct {
Identity struct {
Email string `json:"email"`
Name string `json:"name"`
} `json:"identity"`
When time.Time `json:"when"`
} `json:"author"`
Committer struct {
Identity struct {
Email string `json:"email"`
Name string `json:"name"`
} `json:"identity"`
When time.Time `json:"when"`
} `json:"committer"`
Message string `json:"message"`
Sha string `json:"sha"`
Title string `json:"title"`
} `json:"commit"`
Name string `json:"name"`
Sha string `json:"sha"`
Commit commitInternal `json:"commit"`
Name string `json:"name"`
Sha string `json:"sha"`
}
fileDiff struct {
SHA string `json:"sha"`
Expand All @@ -193,6 +159,26 @@ type (
IsBinary bool `json:"is_binary"`
IsSubmodule bool `json:"is_submodule"`
}
commitInternal struct {
Author struct {
Identity struct {
Email string `json:"email"`
Name string `json:"name"`
} `json:"identity"`
When time.Time `json:"when"`
} `json:"author"`
Committer struct {
Identity struct {
Email string `json:"email"`
Name string `json:"name"`
} `json:"identity"`
When time.Time `json:"when"`
} `json:"committer"`
Message string `json:"message"`
Sha string `json:"sha"`
Title string `json:"title"`
URL string `json:"url"`
}
)

//
Expand Down Expand Up @@ -235,6 +221,7 @@ func convertCommitInfo(src *commitInfo) *scm.Commit {
return &scm.Commit{
Sha: src.Sha,
Message: src.Message,
Link: src.URL,
Author: scm.Signature{
Name: src.Author.Identity.Name,
Email: src.Author.Identity.Email,
Expand Down
34 changes: 9 additions & 25 deletions scm/driver/harness/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ package harness
import (
"context"
"fmt"
"github.com/drone/go-scm/scm/driver/internal/null"
"strconv"
"strings"
"time"

"github.com/drone/go-scm/scm/driver/internal/null"

"github.com/drone/go-scm/scm"
)

Expand Down Expand Up @@ -59,9 +60,9 @@ func (s *pullService) ListCommits(ctx context.Context, repo string, index int, o
return nil, nil, err
}
path := fmt.Sprintf("api/v1/repos/%s/pullreq/%d/commits?%s&%s", repoId, index, encodeListOptions(opts), queryParams)
out := []*commit{}
out := []commitInfo{}
res, err := s.client.do(ctx, "GET", path, nil, &out)
return convertCommits(out), res, err
return convertCommitList(&commits{out}), res, err
}

func (s *pullService) ListChanges(ctx context.Context, repo string, number int, _ scm.ListOptions) ([]*scm.Change, *scm.Response, error) {
Expand Down Expand Up @@ -139,7 +140,8 @@ type (
MergeConflicts []string `json:"merge_conflicts,omitempty"`
Merger *principal `json:"merger"`

Number int64 `json:"number"`
Number int64 `json:"number"`
URL string `json:"url"`

SourceBranch string `json:"source_branch"`
SourceRepoID int64 `json:"source_repo_id"`
Expand Down Expand Up @@ -173,25 +175,6 @@ type (
Title string `json:"title"`
}

commit struct {
Author struct {
Identity struct {
Email string `json:"email"`
Name string `json:"name"`
} `json:"identity"`
When time.Time `json:"when"`
} `json:"author"`
Committer struct {
Identity struct {
Email string `json:"email"`
Name string `json:"name"`
} `json:"identity"`
When time.Time `json:"when"`
} `json:"committer"`
Message string `json:"message"`
Sha string `json:"sha"`
Title string `json:"title"`
}
prComment struct {
LineEnd int `json:"line_end"`
LineEndNew bool `json:"line_end_new"`
Expand Down Expand Up @@ -245,6 +228,7 @@ func convertPullRequest(src *pr) *scm.PullRequest {
Title: src.Title,
Body: src.Description,
Sha: src.SourceSHA,
Link: src.URL,
Source: src.SourceBranch,
Target: src.TargetBranch,
Merged: src.Merged.Valid,
Expand Down Expand Up @@ -272,15 +256,15 @@ func convertPullRequest(src *pr) *scm.PullRequest {
}
}

func convertCommits(src []*commit) []*scm.Commit {
func convertCommits(src []*commitInfo) []*scm.Commit {
dst := []*scm.Commit{}
for _, v := range src {
dst = append(dst, convertCommit(v))
}
return dst
}

func convertCommit(src *commit) *scm.Commit {
func convertCommit(src *commitInfo) *scm.Commit {
return &scm.Commit{
Message: src.Message,
Sha: src.Sha,
Expand Down
2 changes: 2 additions & 0 deletions scm/driver/harness/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ type (
hookCommit struct {
Sha string `json:"sha"`
Message string `json:"message"`
URL string `json:"url"`
Author struct {
Identity struct {
Name string `json:"name"`
Expand Down Expand Up @@ -272,6 +273,7 @@ func convertHookCommit(c hookCommit) scm.Commit {
Name: c.Committer.Identity.Name,
Email: c.Committer.Identity.Email,
},
Link: c.URL,
}
}

Expand Down