Skip to content

Commit 85aa0d8

Browse files
charlktrysmt
authored andcommitted
Possible solution for #38 (#62)
* Added states query params to the pullrequests API call as per https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/pullrequests#get. * Fixed atypo and removed some debug. * Added a gaurd to ensure we have states to process. * Added API querying support as per https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering. * Fixed the mangling of the query string. * Added sort symantics.
1 parent 929e9ab commit 85aa0d8

File tree

2 files changed

+49
-10
lines changed

2 files changed

+49
-10
lines changed

bitbucket.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ type PullRequestsOptions struct {
128128
DestinationCommit string `json:"destination_repository"`
129129
Message string `json:"message"`
130130
Reviewers []string `json:"reviewers"`
131+
States []string `json:"states"`
132+
Query string `json:"query"`
133+
Sort string `json:"sort"`
131134
}
132135

133136
type CommitsOptions struct {
@@ -141,12 +144,11 @@ type CommitsOptions struct {
141144
}
142145

143146
type CommitStatusOptions struct {
144-
Key string `json:"key"`
145-
Url string `json:"url"`
146-
State string `json:"state"`
147-
Name string `json:"name"`
147+
Key string `json:"key"`
148+
Url string `json:"url"`
149+
State string `json:"state"`
150+
Name string `json:"name"`
148151
Description string `json:"description"`
149-
150152
}
151153

152154
type BranchRestrictionsOptions struct {
@@ -201,8 +203,8 @@ type RepositoryPipelineKeyPairOptions struct {
201203
}
202204

203205
type DownloadsOptions struct {
204-
Owner string `json:"owner"`
205-
RepoSlug string `json:"repo_slug"`
206-
FilePath string `json:"filepath"`
207-
FileName string `json:"filename"`
208-
}
206+
Owner string `json:"owner"`
207+
RepoSlug string `json:"repo_slug"`
208+
FilePath string `json:"filepath"`
209+
FileName string `json:"filename"`
210+
}

pullrequests.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package bitbucket
22

33
import (
44
"encoding/json"
5+
"net/url"
56
"os"
67

78
"github.com/k0kubun/pp"
@@ -25,6 +26,42 @@ func (p *PullRequests) Update(po *PullRequestsOptions) (interface{}, error) {
2526

2627
func (p *PullRequests) Gets(po *PullRequestsOptions) (interface{}, error) {
2728
urlStr := GetApiBaseURL() + "/repositories/" + po.Owner + "/" + po.RepoSlug + "/pullrequests/"
29+
30+
if po.States != nil && len(po.States) != 0 {
31+
parsed, err := url.Parse(urlStr)
32+
if err != nil {
33+
return nil, err
34+
}
35+
query := parsed.Query()
36+
for _, state := range po.States {
37+
query.Set("state", state)
38+
}
39+
parsed.RawQuery = query.Encode()
40+
urlStr = parsed.String()
41+
}
42+
43+
if po.Query != "" {
44+
parsed, err := url.Parse(urlStr)
45+
if err != nil {
46+
return nil, err
47+
}
48+
query := parsed.Query()
49+
query.Set("q", po.Query)
50+
parsed.RawQuery = query.Encode()
51+
urlStr = parsed.String()
52+
}
53+
54+
if po.Sort != "" {
55+
parsed, err := url.Parse(urlStr)
56+
if err != nil {
57+
return nil, err
58+
}
59+
query := parsed.Query()
60+
query.Set("sort", po.Sort)
61+
parsed.RawQuery = query.Encode()
62+
urlStr = parsed.String()
63+
}
64+
2865
return p.c.execute("GET", urlStr, "")
2966
}
3067

0 commit comments

Comments
 (0)