Skip to content

Commit c56d071

Browse files
authored
Add missing query parameters to GetDiff (#291)
1 parent 499c3ec commit c56d071

File tree

2 files changed

+51
-13
lines changed

2 files changed

+51
-13
lines changed

bitbucket.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,16 @@ func (b *BranchRestrictionsOptions) WithContext(ctx context.Context) *BranchRest
426426
}
427427

428428
type DiffOptions struct {
429-
Owner string `json:"owner"`
430-
RepoSlug string `json:"repo_slug"`
431-
Spec string `json:"spec"`
429+
Owner string `json:"owner"`
430+
RepoSlug string `json:"repo_slug"`
431+
Spec string `json:"spec"`
432+
Context int `json:"context"`
433+
Path string `json:"path"`
434+
FromPullRequestID int `json:"from_pullrequest_id"`
435+
Whitespace bool `json:"ignore_whitespace"`
436+
Binary bool `json:"binary"`
437+
Renames bool `json:"renames"`
438+
Topic bool `json:"topic"`
432439
}
433440

434441
type DiffStatOptions struct {
@@ -437,14 +444,15 @@ type DiffStatOptions struct {
437444
Spec string `json:"spec"`
438445
FromPullRequestID int `json:"from_pullrequest_id"`
439446
Whitespace bool `json:"ignore_whitespace"`
440-
Merge bool `json:"merge"`
441-
Path string `json:"path"`
442-
Renames bool `json:"renames"`
443-
Topic bool `json:"topic"`
444-
PageNum int `json:"page"`
445-
Pagelen int `json:"pagelen"`
446-
MaxDepth int `json:"max_depth"`
447-
Fields []string
447+
// Deprecated: Merge is deprecated use Topic
448+
Merge bool `json:"merge"`
449+
Path string `json:"path"`
450+
Renames bool `json:"renames"`
451+
Topic bool `json:"topic"`
452+
PageNum int `json:"page"`
453+
Pagelen int `json:"pagelen"`
454+
MaxDepth int `json:"max_depth"`
455+
Fields []string
448456
}
449457

450458
type WebhooksOptions struct {

diff.go

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,38 @@ type DiffStat struct {
3232
}
3333

3434
func (d *Diff) GetDiff(do *DiffOptions) (interface{}, error) {
35-
urlStr := d.c.requestUrl("/repositories/%s/%s/diff/%s", do.Owner, do.RepoSlug, do.Spec)
36-
return d.c.executeRaw("GET", urlStr, "diff")
35+
36+
params := url.Values{}
37+
if do.FromPullRequestID > 0 {
38+
params.Add("from_pullrequest_id", strconv.Itoa(do.FromPullRequestID))
39+
}
40+
41+
if do.Whitespace {
42+
params.Add("ignore_whitespace", strconv.FormatBool(do.Whitespace))
43+
}
44+
45+
if do.Context > 0 {
46+
params.Add("context", strconv.Itoa(do.Context))
47+
}
48+
49+
if do.Path != "" {
50+
params.Add("path", do.Path)
51+
}
52+
53+
if !do.Binary {
54+
params.Add("binary", strconv.FormatBool(do.Binary))
55+
}
56+
57+
if !do.Renames {
58+
params.Add("renames", strconv.FormatBool(do.Renames))
59+
}
60+
61+
if do.Topic {
62+
params.Add("topic", strconv.FormatBool(do.Topic))
63+
}
64+
65+
urlStr := d.c.requestUrl("/repositories/%s/%s/diff/%s?%s", do.Owner, do.RepoSlug, do.Spec, params.Encode())
66+
return d.c.executeRaw("GET", urlStr, "")
3767
}
3868

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

0 commit comments

Comments
 (0)