@@ -7,10 +7,8 @@ package harness
7
7
import (
8
8
"context"
9
9
"fmt"
10
- "strings"
11
10
"time"
12
11
13
- "github.com/bluekeyes/go-gitdiff/gitdiff"
14
12
"github.com/drone/go-scm/scm"
15
13
)
16
14
@@ -81,9 +79,9 @@ func (s *gitService) ListChanges(ctx context.Context, repo, ref string, _ scm.Li
81
79
func (s * gitService ) CompareChanges (ctx context.Context , repo , source , target string , _ scm.ListOptions ) ([]* scm.Change , * scm.Response , error ) {
82
80
harnessURI := buildHarnessURI (s .client .account , s .client .organization , s .client .project , repo )
83
81
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
87
85
}
88
86
89
87
// native data structures
@@ -134,6 +132,20 @@ type (
134
132
Name string `json:"name"`
135
133
Sha string `json:"sha"`
136
134
}
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
+ }
137
149
)
138
150
139
151
//
@@ -164,24 +176,12 @@ func convertCommitList(src []*commitInfo) []*scm.Commit {
164
176
return dst
165
177
}
166
178
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 ))
182
183
}
183
-
184
- return changes
184
+ return dst
185
185
}
186
186
187
187
func convertCommitInfo (src * commitInfo ) * scm.Commit {
@@ -200,3 +200,13 @@ func convertCommitInfo(src *commitInfo) *scm.Commit {
200
200
},
201
201
}
202
202
}
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