Skip to content

Commit 929e9ab

Browse files
authored
Revert "gh-57: added support for paginating ListForAccount and ListForTeam (#58)" (#61)
This reverts commit 02078dc.
1 parent 02078dc commit 929e9ab

24 files changed

+266
-729
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
vendor
2-
.idea

Gopkg.lock

Lines changed: 4 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# go-bitbucket
22

3-
<a class="repo-badge" href="https://godoc.org/github.com/davidji99/go-bitbucket"><img src="https://godoc.org/github.com/davidji99/go-bitbucket?status.svg" alt="go-bitbucket?status"></a>
4-
<a href="https://goreportcard.com/report/github.com/davidji99/go-bitbucket"><img class="badge" tag="github.com/davidji99/go-bitbucket" src="https://goreportcard.com/badge/github.com/davidji99/go-bitbucket"></a>
3+
<a class="repo-badge" href="https://godoc.org/github.com/ktrysmt/go-bitbucket"><img src="https://godoc.org/github.com/ktrysmt/go-bitbucket?status.svg" alt="go-bitbucket?status"></a>
4+
<a href="https://goreportcard.com/report/github.com/ktrysmt/go-bitbucket"><img class="badge" tag="github.com/ktrysmt/go-bitbucket" src="https://goreportcard.com/badge/github.com/ktrysmt/go-bitbucket"></a>
55

66
> Bitbucket-API library for golang.
77
@@ -15,7 +15,7 @@ And the response type is json format defined Bitbucket API.
1515
## Install
1616

1717
```sh
18-
go get github.com/davidji99/go-bitbucket
18+
go get github.com/ktrysmt/go-bitbucket
1919
```
2020

2121
## Usage
@@ -26,7 +26,7 @@ package main
2626
import (
2727
"fmt"
2828

29-
"github.com/davidji99/go-bitbucket"
29+
"github.com/ktrysmt/go-bitbucket"
3030
)
3131

3232
func main() {
@@ -71,7 +71,7 @@ It's using dep.
7171

7272
```sh
7373
go get github.com/golang/dep/...
74-
git clone https://github.com/davidji99/go-bitbucket
74+
git clone https://github.com/ktrysmt/go-bitbucket
7575
cd ./go-bitbucket
7676
dep ensure
7777
```

bitbucket.go

Lines changed: 39 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
package bitbucket
22

3-
import (
4-
"encoding/json"
5-
"fmt"
6-
"io/ioutil"
7-
"net/http"
8-
"net/url"
9-
"sort"
10-
"strings"
11-
)
12-
133
var apiBaseURL = "https://api.bitbucket.org/2.0"
144

155
func GetApiBaseURL() string {
@@ -33,17 +23,17 @@ type user interface {
3323
}
3424

3525
type pullrequests interface {
36-
Create(opt CreatePullRequestOpts) (interface{}, error)
37-
Update(opt CreatePullRequestOpts) (interface{}, error)
38-
List(opt CreatePullRequestOpts) (interface{}, error)
39-
Get(opt CreatePullRequestOpts) (interface{}, error)
40-
Activities(opt CreatePullRequestOpts) (interface{}, error)
41-
Activity(opt CreatePullRequestOpts) (interface{}, error)
42-
Commits(opt CreatePullRequestOpts) (interface{}, error)
43-
Patch(opt CreatePullRequestOpts) (interface{}, error)
44-
Diff(opt CreatePullRequestOpts) (interface{}, error)
45-
Merge(opt CreatePullRequestOpts) (interface{}, error)
46-
Decline(opt CreatePullRequestOpts) (interface{}, error)
26+
Create(opt PullRequestsOptions) (interface{}, error)
27+
Update(opt PullRequestsOptions) (interface{}, error)
28+
List(opt PullRequestsOptions) (interface{}, error)
29+
Get(opt PullRequestsOptions) (interface{}, error)
30+
Activities(opt PullRequestsOptions) (interface{}, error)
31+
Activity(opt PullRequestsOptions) (interface{}, error)
32+
Commits(opt PullRequestsOptions) (interface{}, error)
33+
Patch(opt PullRequestsOptions) (interface{}, error)
34+
Diff(opt PullRequestsOptions) (interface{}, error)
35+
Merge(opt PullRequestsOptions) (interface{}, error)
36+
Decline(opt PullRequestsOptions) (interface{}, error)
4737
}
4838

4939
type repository interface {
@@ -105,15 +95,9 @@ type teams interface {
10595
Projects(teamname string) (interface{}, error)
10696
}
10797

108-
type ListOptions struct {
109-
Page uint64 `json:"page"`
110-
PageLen uint64 `json:"pagelen"`
111-
}
112-
11398
type RepositoriesOptions struct {
114-
ListOptions *ListOptions `json:"list_options"`
115-
Owner string `json:"owner"`
116-
Role string `json:"role"` // role=[owner|admin|contributor|member]
99+
Owner string `json:"owner"`
100+
Role string `json:"role"` // role=[owner|admin|contributor|member]
117101
}
118102

119103
type RepositoryOptions struct {
@@ -130,6 +114,22 @@ type RepositoryOptions struct {
130114
Project string `json:"project"`
131115
}
132116

117+
type PullRequestsOptions struct {
118+
ID string `json:"id"`
119+
CommentID string `json:"comment_id"`
120+
Owner string `json:"owner"`
121+
RepoSlug string `json:"repo_slug"`
122+
Title string `json:"title"`
123+
Description string `json:"description"`
124+
CloseSourceBranch bool `json:"close_source_branch"`
125+
SourceBranch string `json:"source_branch"`
126+
SourceRepository string `json:"source_repository"`
127+
DestinationBranch string `json:"destination_branch"`
128+
DestinationCommit string `json:"destination_repository"`
129+
Message string `json:"message"`
130+
Reviewers []string `json:"reviewers"`
131+
}
132+
133133
type CommitsOptions struct {
134134
Owner string `json:"owner"`
135135
RepoSlug string `json:"repo_slug"`
@@ -141,11 +141,12 @@ type CommitsOptions struct {
141141
}
142142

143143
type CommitStatusOptions struct {
144-
Key string `json:"key"`
145-
Url string `json:"url"`
146-
State string `json:"state"`
147-
Name string `json:"name"`
144+
Key string `json:"key"`
145+
Url string `json:"url"`
146+
State string `json:"state"`
147+
Name string `json:"name"`
148148
Description string `json:"description"`
149+
149150
}
150151

151152
type BranchRestrictionsOptions struct {
@@ -200,78 +201,8 @@ type RepositoryPipelineKeyPairOptions struct {
200201
}
201202

202203
type DownloadsOptions struct {
203-
Owner string `json:"owner"`
204-
RepoSlug string `json:"repo_slug"`
205-
FilePath string `json:"filepath"`
206-
FileName string `json:"filename"`
207-
}
208-
209-
type Response struct {
210-
*http.Response
211-
}
212-
213-
// newResponse creates a new Response for the provided http.Response.
214-
func newResponse(r *http.Response) *Response {
215-
response := &Response{Response: r}
216-
return response
217-
}
218-
219-
type ErrorResponse struct {
220-
Body []byte
221-
Response *http.Response
222-
Message string
223-
}
224-
225-
func (e *ErrorResponse) Error() string {
226-
path, _ := url.QueryUnescape(e.Response.Request.URL.Path)
227-
u := fmt.Sprintf("%s://%s%s", e.Response.Request.URL.Scheme, e.Response.Request.URL.Host, path)
228-
return fmt.Sprintf("%s %s: %d %s", e.Response.Request.Method, u, e.Response.StatusCode, e.Message)
229-
}
230-
231-
// CheckResponse checks the API response for errors, and returns them if present.
232-
func CheckResponse(r *http.Response) error {
233-
switch r.StatusCode {
234-
case 200, 201, 202, 204, 304:
235-
return nil
236-
}
237-
238-
errorResponse := &ErrorResponse{Response: r}
239-
data, err := ioutil.ReadAll(r.Body)
240-
if err == nil && data != nil {
241-
errorResponse.Body = data
242-
243-
var raw interface{}
244-
if err := json.Unmarshal(data, &raw); err != nil {
245-
errorResponse.Message = "failed to parse unknown error format"
246-
} else {
247-
errorResponse.Message = parseError(raw)
248-
}
249-
}
250-
251-
return errorResponse
252-
}
253-
254-
func parseError(raw interface{}) string {
255-
switch raw := raw.(type) {
256-
case string:
257-
return raw
258-
259-
case []interface{}:
260-
var errs []string
261-
for _, v := range raw {
262-
errs = append(errs, parseError(v))
263-
}
264-
return fmt.Sprintf("[%s]", strings.Join(errs, ", "))
265-
266-
case map[string]interface{}:
267-
var errs []string
268-
for k, v := range raw {
269-
errs = append(errs, fmt.Sprintf("{%s: %s}", k, parseError(v)))
270-
}
271-
sort.Strings(errs)
272-
return strings.Join(errs, ", ")
273-
274-
default:
275-
return fmt.Sprintf("failed to parse unexpected error type: %T", raw)
276-
}
277-
}
204+
Owner string `json:"owner"`
205+
RepoSlug string `json:"repo_slug"`
206+
FilePath string `json:"filepath"`
207+
FileName string `json:"filename"`
208+
}

branchrestrictions.go

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

33
import (
44
"encoding/json"
5-
"fmt"
65
"os"
6+
7+
"github.com/k0kubun/pp"
78
)
89

910
type BranchRestrictions struct {
@@ -12,29 +13,29 @@ type BranchRestrictions struct {
1213

1314
func (b *BranchRestrictions) Gets(bo *BranchRestrictionsOptions) (interface{}, error) {
1415
urlStr := b.c.requestUrl("/repositories/%s/%s/branch-restrictions", bo.Owner, bo.RepoSlug)
15-
return b.c.execute("GET", urlStr, "", "")
16+
return b.c.execute("GET", urlStr, "")
1617
}
1718

1819
func (b *BranchRestrictions) Create(bo *BranchRestrictionsOptions) (interface{}, error) {
1920
data := b.buildBranchRestrictionsBody(bo)
2021
urlStr := b.c.requestUrl("/repositories/%s/%s/branch-restrictions", bo.Owner, bo.RepoSlug)
21-
return b.c.execute("POST", urlStr, data, "")
22+
return b.c.execute("POST", urlStr, data)
2223
}
2324

2425
func (b *BranchRestrictions) Get(bo *BranchRestrictionsOptions) (interface{}, error) {
2526
urlStr := b.c.requestUrl("/repositories/%s/%s/branch-restrictions/%s", bo.Owner, bo.RepoSlug, bo.ID)
26-
return b.c.execute("GET", urlStr, "", "")
27+
return b.c.execute("GET", urlStr, "")
2728
}
2829

2930
func (b *BranchRestrictions) Update(bo *BranchRestrictionsOptions) (interface{}, error) {
3031
data := b.buildBranchRestrictionsBody(bo)
3132
urlStr := b.c.requestUrl("/repositories/%s/%s/branch-restrictions/%s", bo.Owner, bo.RepoSlug, bo.ID)
32-
return b.c.execute("PUT", urlStr, data, "")
33+
return b.c.execute("PUT", urlStr, data)
3334
}
3435

3536
func (b *BranchRestrictions) Delete(bo *BranchRestrictionsOptions) (interface{}, error) {
3637
urlStr := b.c.requestUrl("/repositories/%s/%s/branch-restrictions/%s", bo.Owner, bo.RepoSlug, bo.ID)
37-
return b.c.execute("DELETE", urlStr, "", "")
38+
return b.c.execute("DELETE", urlStr, "")
3839
}
3940

4041
type branchRestrictionsBody struct {
@@ -121,7 +122,7 @@ func (b *BranchRestrictions) buildBranchRestrictionsBody(bo *BranchRestrictionsO
121122

122123
data, err := json.Marshal(body)
123124
if err != nil {
124-
fmt.Println(err)
125+
pp.Println(err)
125126
os.Exit(9)
126127
}
127128

0 commit comments

Comments
 (0)