@@ -7,10 +7,8 @@ package harness
77import (
88 "context"
99 "fmt"
10- "strings"
1110 "time"
1211
13- "github.com/bluekeyes/go-gitdiff/gitdiff"
1412 "github.com/drone/go-scm/scm"
1513)
1614
@@ -81,9 +79,9 @@ func (s *gitService) ListChanges(ctx context.Context, repo, ref string, _ scm.Li
8179func (s * gitService ) CompareChanges (ctx context.Context , repo , source , target string , _ scm.ListOptions ) ([]* scm.Change , * scm.Response , error ) {
8280 harnessURI := buildHarnessURI (s .client .account , s .client .organization , s .client .project , repo )
8381 path := fmt .Sprintf ("api/v1/repos/%s/diff/%s...%s" , harnessURI , source , target )
84- buf := new (strings. Builder )
85- res , err := s .client .do (ctx , "GET" , path , nil , buf )
86- return convertCompareChanges ( buf . String () ), res , err
82+ out := [] * fileDiff {}
83+ res , err := s .client .do (ctx , "GET" , path , nil , & out )
84+ return convertChangeList ( out ), res , err
8785}
8886
8987// native data structures
@@ -134,6 +132,20 @@ type (
134132 Name string `json:"name"`
135133 Sha string `json:"sha"`
136134 }
135+ fileDiff struct {
136+ SHA string `json:"sha"`
137+ OldSHA string `json:"old_sha,omitempty"`
138+ Path string `json:"path"`
139+ OldPath string `json:"old_path,omitempty"`
140+ Status string `json:"status"`
141+ Additions int64 `json:"additions"`
142+ Deletions int64 `json:"deletions"`
143+ Changes int64 `json:"changes"`
144+ ContentURL string `json:"content_url"`
145+ Patch []byte `json:"patch,omitempty"`
146+ IsBinary bool `json:"is_binary"`
147+ IsSubmodule bool `json:"is_submodule"`
148+ }
137149)
138150
139151//
@@ -164,24 +176,12 @@ func convertCommitList(src []*commitInfo) []*scm.Commit {
164176 return dst
165177}
166178
167- func convertCompareChanges (src string ) []* scm.Change {
168- files , _ , err := gitdiff .Parse (strings .NewReader (src ))
169- if err != nil {
170- return nil
171- }
172-
173- changes := make ([]* scm.Change , 0 )
174- for _ , f := range files {
175- changes = append (changes , & scm.Change {
176- Path : f .NewName ,
177- PrevFilePath : f .OldName ,
178- Added : f .IsNew ,
179- Deleted : f .IsDelete ,
180- Renamed : f .IsRename ,
181- })
179+ func convertChangeList (src []* fileDiff ) []* scm.Change {
180+ dst := []* scm.Change {}
181+ for _ , v := range src {
182+ dst = append (dst , convertChange (v ))
182183 }
183-
184- return changes
184+ return dst
185185}
186186
187187func convertCommitInfo (src * commitInfo ) * scm.Commit {
@@ -200,3 +200,13 @@ func convertCommitInfo(src *commitInfo) *scm.Commit {
200200 },
201201 }
202202}
203+
204+ func convertChange (src * fileDiff ) * scm.Change {
205+ return & scm.Change {
206+ Path : src .Path ,
207+ PrevFilePath : src .OldPath ,
208+ Added : src .Status == "ADDED" ,
209+ Renamed : src .Status == "RENAMED" ,
210+ Deleted : src .Status == "DELETED" ,
211+ }
212+ }
0 commit comments