Skip to content

feat: add new field of commit link for HC webhooks #333

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
63 changes: 24 additions & 39 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,25 @@ 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"`
}
)

//
Expand Down Expand Up @@ -234,7 +219,7 @@ func convertChangeList(src []*fileDiff) []*scm.Change {
func convertCommitInfo(src *commitInfo) *scm.Commit {
return &scm.Commit{
Sha: src.Sha,
Message: src.Message,
Message: src.Title,
Author: scm.Signature{
Name: src.Author.Identity.Name,
Email: src.Author.Identity.Email,
Expand Down
30 changes: 6 additions & 24 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 @@ -173,25 +174,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 @@ -272,15 +254,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