-
Notifications
You must be signed in to change notification settings - Fork 151
Adds the ability to create forks #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -7,6 +7,7 @@ import ( | |||||
| "os" | ||||||
| "path" | ||||||
| "strconv" | ||||||
| "strings" | ||||||
|
|
||||||
| "github.com/k0kubun/pp" | ||||||
| "github.com/mitchellh/mapstructure" | ||||||
|
|
@@ -135,6 +136,17 @@ func (r *Repository) Create(ro *RepositoryOptions) (*Repository, error) { | |||||
| return decodeRepository(response) | ||||||
| } | ||||||
|
|
||||||
| func (r *Repository) Fork(fo *RepositoryForkOptions) (*Repository, error) { | ||||||
| data := r.buildForkBody(fo) | ||||||
| urlStr := r.c.requestUrl("/repositories/%s/%s/forks", fo.FromOwner, fo.FromSlug) | ||||||
| response, err := r.c.execute("POST", urlStr, data) | ||||||
| if err != nil { | ||||||
| return nil, err | ||||||
| } | ||||||
|
|
||||||
| return decodeRepository(response) | ||||||
| } | ||||||
|
|
||||||
| func (r *Repository) Get(ro *RepositoryOptions) (*Repository, error) { | ||||||
| urlStr := r.c.requestUrl("/repositories/%s/%s", ro.Owner, ro.RepoSlug) | ||||||
| response, err := r.c.execute("GET", urlStr, "") | ||||||
|
|
@@ -331,7 +343,7 @@ func (r *Repository) buildRepositoryBody(ro *RepositoryOptions) string { | |||||
| // body["name"] = ro.Name | ||||||
| //} | ||||||
| if ro.IsPrivate != "" { | ||||||
| body["is_private"] = ro.IsPrivate | ||||||
| body["is_private"] = strings.ToLower(strings.TrimSpace(ro.IsPrivate)) != "false" | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought the below was the right one, and do you think?
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ktrysmt Bitbucket expects a boolean value in the payload for the The new condition of
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. |
||||||
| } | ||||||
| if ro.Description != "" { | ||||||
| body["description"] = ro.Description | ||||||
|
|
@@ -357,6 +369,45 @@ func (r *Repository) buildRepositoryBody(ro *RepositoryOptions) string { | |||||
| return r.buildJsonBody(body) | ||||||
| } | ||||||
|
|
||||||
| func (r *Repository) buildForkBody(fo *RepositoryForkOptions) string { | ||||||
|
|
||||||
| body := map[string]interface{}{} | ||||||
|
|
||||||
| if fo.Owner != "" { | ||||||
| body["workspace"] = map[string]string{ | ||||||
| "slug": fo.Owner, | ||||||
| } | ||||||
| } | ||||||
| if fo.Name != "" { | ||||||
| body["name"] = fo.Name | ||||||
| } | ||||||
| if fo.IsPrivate != "" { | ||||||
| body["is_private"] = strings.ToLower(strings.TrimSpace(fo.IsPrivate)) != "false" | ||||||
| } | ||||||
| if fo.Description != "" { | ||||||
| body["description"] = fo.Description | ||||||
| } | ||||||
| if fo.ForkPolicy != "" { | ||||||
| body["fork_policy"] = fo.ForkPolicy | ||||||
| } | ||||||
| if fo.Language != "" { | ||||||
| body["language"] = fo.Language | ||||||
| } | ||||||
| if fo.HasIssues != "" { | ||||||
| body["has_issues"] = fo.HasIssues | ||||||
| } | ||||||
| if fo.HasWiki != "" { | ||||||
| body["has_wiki"] = fo.HasWiki | ||||||
| } | ||||||
| if fo.Project != "" { | ||||||
| body["project"] = map[string]string{ | ||||||
| "key": fo.Project, | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| return r.buildJsonBody(body) | ||||||
| } | ||||||
|
|
||||||
| func (r *Repository) buildPipelineBody(rpo *RepositoryPipelineOptions) string { | ||||||
|
|
||||||
| body := map[string]interface{}{} | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you remove the line if it is not a problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it