77 "os"
88 "path"
99 "strconv"
10+ "strings"
1011
1112 "github.com/k0kubun/pp"
1213 "github.com/mitchellh/mapstructure"
@@ -135,6 +136,17 @@ func (r *Repository) Create(ro *RepositoryOptions) (*Repository, error) {
135136 return decodeRepository (response )
136137}
137138
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+
138150func (r * Repository ) Get (ro * RepositoryOptions ) (* Repository , error ) {
139151 urlStr := r .c .requestUrl ("/repositories/%s/%s" , ro .Owner , ro .RepoSlug )
140152 response , err := r .c .execute ("GET" , urlStr , "" )
@@ -331,7 +343,7 @@ func (r *Repository) buildRepositoryBody(ro *RepositoryOptions) string {
331343 // body["name"] = ro.Name
332344 //}
333345 if ro .IsPrivate != "" {
334- body ["is_private" ] = ro .IsPrivate
346+ body ["is_private" ] = strings . ToLower ( strings . TrimSpace ( ro .IsPrivate )) != "false"
335347 }
336348 if ro .Description != "" {
337349 body ["description" ] = ro .Description
@@ -357,6 +369,45 @@ func (r *Repository) buildRepositoryBody(ro *RepositoryOptions) string {
357369 return r .buildJsonBody (body )
358370}
359371
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+
360411func (r * Repository ) buildPipelineBody (rpo * RepositoryPipelineOptions ) string {
361412
362413 body := map [string ]interface {}{}
0 commit comments