7
7
"os"
8
8
"path"
9
9
"strconv"
10
+ "strings"
10
11
11
12
"github.com/k0kubun/pp"
12
13
"github.com/mitchellh/mapstructure"
@@ -135,6 +136,17 @@ func (r *Repository) Create(ro *RepositoryOptions) (*Repository, error) {
135
136
return decodeRepository (response )
136
137
}
137
138
139
+ func (r * Repository ) Fork (fo * RepositoryForkOptions ) (* Repository , error ) {
140
+ data := r .buildForkBody (fo )
141
+ urlStr := r .c .requestUrl ("/repositories/%s/%s/forks" , fo .FromOwner , fo .FromSlug )
142
+ response , err := r .c .execute ("POST" , urlStr , data )
143
+ if err != nil {
144
+ return nil , err
145
+ }
146
+
147
+ return decodeRepository (response )
148
+ }
149
+
138
150
func (r * Repository ) Get (ro * RepositoryOptions ) (* Repository , error ) {
139
151
urlStr := r .c .requestUrl ("/repositories/%s/%s" , ro .Owner , ro .RepoSlug )
140
152
response , err := r .c .execute ("GET" , urlStr , "" )
@@ -331,7 +343,7 @@ func (r *Repository) buildRepositoryBody(ro *RepositoryOptions) string {
331
343
// body["name"] = ro.Name
332
344
//}
333
345
if ro .IsPrivate != "" {
334
- body ["is_private" ] = ro .IsPrivate
346
+ body ["is_private" ] = strings . ToLower ( strings . TrimSpace ( ro .IsPrivate )) != "false"
335
347
}
336
348
if ro .Description != "" {
337
349
body ["description" ] = ro .Description
@@ -357,6 +369,45 @@ func (r *Repository) buildRepositoryBody(ro *RepositoryOptions) string {
357
369
return r .buildJsonBody (body )
358
370
}
359
371
372
+ func (r * Repository ) buildForkBody (fo * RepositoryForkOptions ) string {
373
+
374
+ body := map [string ]interface {}{}
375
+
376
+ if fo .Owner != "" {
377
+ body ["workspace" ] = map [string ]string {
378
+ "slug" : fo .Owner ,
379
+ }
380
+ }
381
+ if fo .Name != "" {
382
+ body ["name" ] = fo .Name
383
+ }
384
+ if fo .IsPrivate != "" {
385
+ body ["is_private" ] = strings .ToLower (strings .TrimSpace (fo .IsPrivate )) != "false"
386
+ }
387
+ if fo .Description != "" {
388
+ body ["description" ] = fo .Description
389
+ }
390
+ if fo .ForkPolicy != "" {
391
+ body ["fork_policy" ] = fo .ForkPolicy
392
+ }
393
+ if fo .Language != "" {
394
+ body ["language" ] = fo .Language
395
+ }
396
+ if fo .HasIssues != "" {
397
+ body ["has_issues" ] = fo .HasIssues
398
+ }
399
+ if fo .HasWiki != "" {
400
+ body ["has_wiki" ] = fo .HasWiki
401
+ }
402
+ if fo .Project != "" {
403
+ body ["project" ] = map [string ]string {
404
+ "key" : fo .Project ,
405
+ }
406
+ }
407
+
408
+ return r .buildJsonBody (body )
409
+ }
410
+
360
411
func (r * Repository ) buildPipelineBody (rpo * RepositoryPipelineOptions ) string {
361
412
362
413
body := map [string ]interface {}{}
0 commit comments