From ce0e2671e6ee02fb80a94aee88bb03cc662a5301 Mon Sep 17 00:00:00 2001 From: Abhinav Singh Date: Thu, 10 Apr 2025 13:09:10 -0700 Subject: [PATCH 1/6] feat: add new field of commit link for HC webhooks --- scm/driver/harness/webhook.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scm/driver/harness/webhook.go b/scm/driver/harness/webhook.go index 33be360b4..c4b7173e0 100644 --- a/scm/driver/harness/webhook.go +++ b/scm/driver/harness/webhook.go @@ -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"` @@ -272,6 +273,7 @@ func convertHookCommit(c hookCommit) scm.Commit { Name: c.Committer.Identity.Name, Email: c.Committer.Identity.Email, }, + Link: c.URL, } } From 765ce66656728f488bf1484d9891a98191f461b9 Mon Sep 17 00:00:00 2001 From: Abhinav Singh Date: Fri, 11 Apr 2025 16:54:20 -0700 Subject: [PATCH 2/6] feat: add commit links to HC apis --- scm/driver/harness/git.go | 63 ++++++++++++++++----------------------- scm/driver/harness/pr.go | 30 ++++--------------- 2 files changed, 31 insertions(+), 62 deletions(-) diff --git a/scm/driver/harness/git.go b/scm/driver/harness/git.go index f261f7756..f1b144686 100644 --- a/scm/driver/harness/git.go +++ b/scm/driver/harness/git.go @@ -133,23 +133,7 @@ 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"` @@ -157,27 +141,9 @@ type ( 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"` @@ -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"` + } ) // @@ -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, diff --git a/scm/driver/harness/pr.go b/scm/driver/harness/pr.go index 167ba9bf7..417d692bc 100644 --- a/scm/driver/harness/pr.go +++ b/scm/driver/harness/pr.go @@ -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" ) @@ -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 := &commits{} res, err := s.client.do(ctx, "GET", path, nil, &out) - return convertCommits(out), res, err + return convertCommitList(out), res, err } func (s *pullService) ListChanges(ctx context.Context, repo string, number int, _ scm.ListOptions) ([]*scm.Change, *scm.Response, error) { @@ -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"` @@ -272,7 +254,7 @@ 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)) @@ -280,7 +262,7 @@ func convertCommits(src []*commit) []*scm.Commit { return dst } -func convertCommit(src *commit) *scm.Commit { +func convertCommit(src *commitInfo) *scm.Commit { return &scm.Commit{ Message: src.Message, Sha: src.Sha, From cfa0f7011bd1d3324e8cd76fb70c3f3a19dc2243 Mon Sep 17 00:00:00 2001 From: Abhinav Singh Date: Fri, 11 Apr 2025 22:42:31 -0700 Subject: [PATCH 3/6] feat: add commit links to HC apis --- scm/driver/harness/pr.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scm/driver/harness/pr.go b/scm/driver/harness/pr.go index 417d692bc..f199991cb 100644 --- a/scm/driver/harness/pr.go +++ b/scm/driver/harness/pr.go @@ -60,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 := &commits{} + out := []commitInfo{} res, err := s.client.do(ctx, "GET", path, nil, &out) - return convertCommitList(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) { From 7bcdd85bb087f7919a50916a871d86c929852e5c Mon Sep 17 00:00:00 2001 From: Abhinav Singh Date: Fri, 11 Apr 2025 23:00:07 -0700 Subject: [PATCH 4/6] feat: add commit links to HC apis --- scm/driver/harness/pr.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scm/driver/harness/pr.go b/scm/driver/harness/pr.go index f199991cb..74415f065 100644 --- a/scm/driver/harness/pr.go +++ b/scm/driver/harness/pr.go @@ -140,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"` @@ -227,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, From 0c2edeab0cf796fb4fddd3f73ba5425e3af7caec Mon Sep 17 00:00:00 2001 From: Abhinav Singh Date: Tue, 22 Apr 2025 15:32:14 -0700 Subject: [PATCH 5/6] feat: restructure code --- scm/driver/harness/pr.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scm/driver/harness/pr.go b/scm/driver/harness/pr.go index 74415f065..f199991cb 100644 --- a/scm/driver/harness/pr.go +++ b/scm/driver/harness/pr.go @@ -140,8 +140,7 @@ type ( MergeConflicts []string `json:"merge_conflicts,omitempty"` Merger *principal `json:"merger"` - Number int64 `json:"number"` - URL string `json:"url"` + Number int64 `json:"number"` SourceBranch string `json:"source_branch"` SourceRepoID int64 `json:"source_repo_id"` @@ -228,7 +227,6 @@ 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, From 5d9dcf64ebacfe8558eeea3cc783b11babf34b68 Mon Sep 17 00:00:00 2001 From: Abhinav Singh Date: Wed, 18 Jun 2025 14:07:58 -0700 Subject: [PATCH 6/6] feat: change commit to use title --- scm/driver/harness/git.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scm/driver/harness/git.go b/scm/driver/harness/git.go index f1b144686..59fadc3dd 100644 --- a/scm/driver/harness/git.go +++ b/scm/driver/harness/git.go @@ -177,7 +177,6 @@ type ( Message string `json:"message"` Sha string `json:"sha"` Title string `json:"title"` - URL string `json:"url"` } ) @@ -220,8 +219,7 @@ func convertChangeList(src []*fileDiff) []*scm.Change { func convertCommitInfo(src *commitInfo) *scm.Commit { return &scm.Commit{ Sha: src.Sha, - Message: src.Message, - Link: src.URL, + Message: src.Title, Author: scm.Signature{ Name: src.Author.Identity.Name, Email: src.Author.Identity.Email,