Skip to content

Commit

Permalink
Add missing query parameters to GetDiff (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
CescHolly authored Aug 8, 2024
1 parent 499c3ec commit c56d071
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 13 deletions.
30 changes: 19 additions & 11 deletions bitbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,16 @@ func (b *BranchRestrictionsOptions) WithContext(ctx context.Context) *BranchRest
}

type DiffOptions struct {
Owner string `json:"owner"`
RepoSlug string `json:"repo_slug"`
Spec string `json:"spec"`
Owner string `json:"owner"`
RepoSlug string `json:"repo_slug"`
Spec string `json:"spec"`
Context int `json:"context"`
Path string `json:"path"`
FromPullRequestID int `json:"from_pullrequest_id"`
Whitespace bool `json:"ignore_whitespace"`
Binary bool `json:"binary"`
Renames bool `json:"renames"`
Topic bool `json:"topic"`
}

type DiffStatOptions struct {
Expand All @@ -437,14 +444,15 @@ type DiffStatOptions struct {
Spec string `json:"spec"`
FromPullRequestID int `json:"from_pullrequest_id"`
Whitespace bool `json:"ignore_whitespace"`
Merge bool `json:"merge"`
Path string `json:"path"`
Renames bool `json:"renames"`
Topic bool `json:"topic"`
PageNum int `json:"page"`
Pagelen int `json:"pagelen"`
MaxDepth int `json:"max_depth"`
Fields []string
// Deprecated: Merge is deprecated use Topic
Merge bool `json:"merge"`
Path string `json:"path"`
Renames bool `json:"renames"`
Topic bool `json:"topic"`
PageNum int `json:"page"`
Pagelen int `json:"pagelen"`
MaxDepth int `json:"max_depth"`
Fields []string
}

type WebhooksOptions struct {
Expand Down
34 changes: 32 additions & 2 deletions diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,38 @@ type DiffStat struct {
}

func (d *Diff) GetDiff(do *DiffOptions) (interface{}, error) {
urlStr := d.c.requestUrl("/repositories/%s/%s/diff/%s", do.Owner, do.RepoSlug, do.Spec)
return d.c.executeRaw("GET", urlStr, "diff")

params := url.Values{}
if do.FromPullRequestID > 0 {
params.Add("from_pullrequest_id", strconv.Itoa(do.FromPullRequestID))
}

if do.Whitespace {
params.Add("ignore_whitespace", strconv.FormatBool(do.Whitespace))
}

if do.Context > 0 {
params.Add("context", strconv.Itoa(do.Context))
}

if do.Path != "" {
params.Add("path", do.Path)
}

if !do.Binary {
params.Add("binary", strconv.FormatBool(do.Binary))
}

if !do.Renames {
params.Add("renames", strconv.FormatBool(do.Renames))
}

if do.Topic {
params.Add("topic", strconv.FormatBool(do.Topic))
}

urlStr := d.c.requestUrl("/repositories/%s/%s/diff/%s?%s", do.Owner, do.RepoSlug, do.Spec, params.Encode())
return d.c.executeRaw("GET", urlStr, "")
}

func (d *Diff) GetPatch(do *DiffOptions) (interface{}, error) {
Expand Down

0 comments on commit c56d071

Please sign in to comment.