@@ -13,6 +13,11 @@ import (
13
13
"github.com/drone/go-scm/scm"
14
14
)
15
15
16
+ type cloneLink struct {
17
+ link
18
+ Name string `json:"name"`
19
+ }
20
+
16
21
type repository struct {
17
22
UUID string `json:"uuid"`
18
23
SCM string `json:"scm"`
@@ -24,6 +29,10 @@ type repository struct {
24
29
Type string `json:"type"`
25
30
Name string `json:"name"`
26
31
} `json:"mainbranch"`
32
+ Links struct {
33
+ HTML link `json:"html"`
34
+ Clone []cloneLink `json:"clone"`
35
+ } `json:"links"`
27
36
}
28
37
29
38
type perms struct {
@@ -176,16 +185,36 @@ func convertRepository(from *repository) *scm.Repository {
176
185
ID : from .UUID ,
177
186
Name : name ,
178
187
Namespace : namespace ,
179
- Link : fmt . Sprintf ( "https://bitbucket.org/%s" , from . FullName ) ,
188
+ Link : from . Links . HTML . Href ,
180
189
Branch : from .Mainbranch .Name ,
181
190
Private : from .IsPrivate ,
182
- Clone : fmt . Sprintf ( "https://bitbucket.org/%s.git" , from . FullName ),
183
- CloneSSH :
fmt . Sprintf ( "[email protected] :%s.git" , from . FullName ),
191
+ CloneSSH : extractCloneLink ( from . Links . Clone , "ssh" ),
192
+ Clone : anonymizeLink ( extractCloneLink ( from . Links . Clone , "https" , "http" ) ),
184
193
Created : from .CreatedOn ,
185
194
Updated : from .UpdatedOn ,
186
195
}
187
196
}
188
197
198
+ func extractCloneLink (links []cloneLink , names ... string ) (href string ) {
199
+ for _ , name := range names {
200
+ for _ , link := range links {
201
+ if link .Name == name && link .Href != "" {
202
+ return link .Href
203
+ }
204
+ }
205
+ }
206
+ return
207
+ }
208
+
209
+ func anonymizeLink (link string ) (href string ) {
210
+ parsed , err := url .Parse (link )
211
+ if err != nil {
212
+ return link
213
+ }
214
+ parsed .User = nil
215
+ return parsed .String ()
216
+ }
217
+
189
218
func convertPerms (from * perms ) * scm.Perm {
190
219
to := new (scm.Perm )
191
220
if len (from .Values ) != 1 {
0 commit comments