Skip to content

Commit

Permalink
Go fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
icambridge committed Apr 3, 2014
1 parent b96ab3a commit 989f77f
Show file tree
Hide file tree
Showing 14 changed files with 178 additions and 205 deletions.
22 changes: 11 additions & 11 deletions branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ package gobucket
type BranchList map[string]*Branch

type Branch struct {
Node string `json:"node"`
Files []File `json:"files"`
RawAuthor string `json:"raw_author"`
UtcTimestamp string `json:"utctimestamp"`
Author string `json:"author"`
Timestamp string `json:"timestamp"`
RawNode string `json:"raw_node"`
Parents []string `json:"parents"`
Branch string `json:"branch"`
Message string `json:"message"`
Size int `json:"size"`
Node string `json:"node"`
Files []File `json:"files"`
RawAuthor string `json:"raw_author"`
UtcTimestamp string `json:"utctimestamp"`
Author string `json:"author"`
Timestamp string `json:"timestamp"`
RawNode string `json:"raw_node"`
Parents []string `json:"parents"`
Branch string `json:"branch"`
Message string `json:"message"`
Size int `json:"size"`
}

type BranchName struct {
Expand Down
22 changes: 11 additions & 11 deletions commit.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package gobucket

type Commit struct {
Node string `json:"node"`
Files []File `json:"files"`
RawAuthor string `json:"raw_author"`
UtcTimestamp string `json:"utctimestamp"`
Author string `json:"author"`
Timestamp string `json:"timestamp"`
RawNode string `json:"raw_node"`
Parents []string `json:"parents"`
Branch string `json:"branch"`
Message string `json:"message"`
Size int `json:"size"`
Node string `json:"node"`
Files []File `json:"files"`
RawAuthor string `json:"raw_author"`
UtcTimestamp string `json:"utctimestamp"`
Author string `json:"author"`
Timestamp string `json:"timestamp"`
RawNode string `json:"raw_node"`
Parents []string `json:"parents"`
Branch string `json:"branch"`
Message string `json:"message"`
Size int `json:"size"`
}
25 changes: 9 additions & 16 deletions gobucket.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package gobucket

import (
"bytes"
"encoding/json"
"net/http"
"net/url"
"encoding/json"
"bytes"
"strings"
// "reflect"
// "reflect"
)

const (
Expand All @@ -19,15 +19,14 @@ func NewClient(usernameStr string, passwordStr string) *Client {

httpClient := http.DefaultClient


baseURL, _ := url.Parse(defaultBaseURL)

c := &Client{
client: httpClient,
client: httpClient,
UserAgent: userAgent,
BaseURL: baseURL,
username: usernameStr,
password: passwordStr,
BaseURL: baseURL,
username: usernameStr,
password: passwordStr,
}

c.Repositories = &RepositoriesService{client: c}
Expand All @@ -36,8 +35,7 @@ func NewClient(usernameStr string, passwordStr string) *Client {
}

type Client struct {

BaseURL *url.URL
BaseURL *url.URL

client *http.Client

Expand All @@ -48,11 +46,8 @@ type Client struct {

Repositories *RepositoriesService
PullRequests *PullRequestsService

}



func (c *Client) NewRequest(method string, urlString string, body interface{}) (*http.Request, error) {

rel, err := url.Parse(urlString)
Expand All @@ -74,7 +69,6 @@ func (c *Client) NewRequest(method string, urlString string, body interface{}) (

}


req, err := http.NewRequest(method, u, buf)

if err != nil {
Expand All @@ -90,8 +84,7 @@ func (c *Client) NewRequest(method string, urlString string, body interface{}) (
return req, nil
}

func (c *Client) Do(req *http.Request, output interface {}) error {

func (c *Client) Do(req *http.Request, output interface{}) error {

resp, err := c.client.Do(req)

Expand Down
27 changes: 13 additions & 14 deletions gobucket_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package gobucket

import (
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
"io/ioutil"
"testing"
"fmt"
"reflect"
"testing"
)

var (
Expand Down Expand Up @@ -110,7 +110,6 @@ func TestClientNewRequest_String(t *testing.T) {
}
}


func TestDo_GET(t *testing.T) {
setUp()
defer tearDown()
Expand All @@ -120,11 +119,11 @@ func TestDo_GET(t *testing.T) {
}

mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if m := "GET"; m != r.Method {
t.Errorf("Request method = %v, expected %v", r.Method, m)
}
fmt.Fprint(w, `{"Bar":"drink"}`)
})
if m := "GET"; m != r.Method {
t.Errorf("Request method = %v, expected %v", r.Method, m)
}
fmt.Fprint(w, `{"Bar":"drink"}`)
})

req, _ := client.NewRequest("GET", "/", nil)
body := new(Foo)
Expand All @@ -147,11 +146,11 @@ func TestDo_POST(t *testing.T) {
}

mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if m := "POST"; m != r.Method {
t.Errorf("Request method = %v, expected %v", r.Method, m)
}
fmt.Fprint(w, `{"Bar":"drink"}`)
})
if m := "POST"; m != r.Method {
t.Errorf("Request method = %v, expected %v", r.Method, m)
}
fmt.Fprint(w, `{"Bar":"drink"}`)
})

req, _ := client.NewRequest("POST", "/", nil)
body := new(Foo)
Expand Down
10 changes: 4 additions & 6 deletions hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ func GetHookData(payload []byte) (*Hook, error) {
return &h, nil
}


type Hook struct {
Repository HookRepository `json:"repository"`
Truncated bool `json:"truncated"`
Commits []Commit `json:"commits"`
ConnonUrl string `json:"canon_url"`
User string `json:"user"`
Truncated bool `json:"truncated"`
Commits []Commit `json:"commits"`
ConnonUrl string `json:"canon_url"`
User string `json:"user"`
}

type Callback interface {
Expand All @@ -43,4 +42,3 @@ func (o *HookObserver) Process(h *Hook) {
c.Exec(h)
}
}

2 changes: 0 additions & 2 deletions hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import (
"testing"
)


func TestGetHookData(t *testing.T) {

json := `{"repository": {"website": "", "fork": false, "name": "Recognition / Client Admin Application", "scm": "git", "owner": "workstars", "absolute_url": "/workstars/recognition-client-admin-application/", "slug": "recognition-client-admin-application", "is_private": true}, "truncated": false, "commits": [{"node": "82342c16fb54", "files": [{"type": "modified", "file": "README.md"}], "raw_author": "Iain Cambridge <iain.cambridge@workstars.com>", "utctimestamp": "2014-03-16 17:01:56+00:00", "author": "icambridge", "timestamp": "2014-03-16 18:01:56", "raw_node": "82342c16fb54cde537a0dc5b2a4773268bfd025b", "parents": ["f61e20d74f55"], "branch": "icambridge/readmemd-edited-online-with-bitbucket-1394989053935", "message": "README.md edited online with Bitbucket", "revision": null, "size": -1}], "canon_url": "https://bitbucket.org", "user": "icambridge"}`

payload := []byte(json)


h, err := GetHookData(payload)

if err != nil {
Expand Down
6 changes: 2 additions & 4 deletions info.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package gobucket


type PlaceInfo struct {
Commit CommitInfo `json:"commit"`
Repository Repository `json:"repository"`
Branch BranchName `json:"branch"`
Branch BranchName `json:"branch"`
}

type CommitInfo struct {
Hash string `json:"hash"`
Links SelfLinks `json:"links"`
Repository Repository `json:"repository"`
Branch BranchName `json:"branch"`
Branch BranchName `json:"branch"`
}

4 changes: 1 addition & 3 deletions links.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ type NamedLink struct {
}

type SelfLinks struct {
Self Link `json:"self"`
Self Link `json:"self"`
Avatar Link `json:"avatar"`
}


4 changes: 2 additions & 2 deletions owner.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package gobucket

type Owner struct {
Username string `json:"usernane"`
DisplayName string `json:"display_name"`
Username string `json:"usernane"`
DisplayName string `json:"display_name"`
Links SelfLinks `json:"links"`
}
23 changes: 11 additions & 12 deletions pull_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ func (s *PullRequestsService) GetAll(owner string, repo string) ([]*PullRequest,
repoValues := len(pullRequests.Values)

if repoValues <= 0 {
break;
break
}

output = append(output, pullRequests.Values...)
count += repoValues

if count >= pullRequests.Size {
break;
break
}

page++
Expand Down Expand Up @@ -159,11 +159,10 @@ type PullRequest struct {
CreatedOn string `json:"created_on"`
UpdatedOn string `json:"updated_on"`
Reviewers []User `json:"reviewers"`
Participants []Participant `json:"participants"`
Participants []Participant `json:"participants"`
Id int `json:"id"`
}


type PullRequestLinks struct {
Decline Link `json:"decline"`
Commits Link `json:"commits"`
Expand All @@ -177,9 +176,9 @@ type PullRequestLinks struct {
}

type Participant struct {
Role string `json:"role"`
User User `json:"user"`
Approved bool `json:"approved"`
Role string `json:"role"`
User User `json:"user"`
Approved bool `json:"approved"`
}

func (pr *PullRequest) GetApprovals() []User {
Expand All @@ -194,7 +193,7 @@ func (pr *PullRequest) GetApprovals() []User {

func (pr *PullRequest) GetOwner() string {

parts := strings.Split(pr.Destination.Repository.FullName ,"/")
parts := strings.Split(pr.Destination.Repository.FullName, "/")

if len(parts) < 1 || parts[0] == "" {
return "unknown owner"
Expand All @@ -205,7 +204,7 @@ func (pr *PullRequest) GetOwner() string {

func (pr *PullRequest) GetRepoName() string {

parts := strings.Split(pr.Destination.Repository.FullName ,"/")
parts := strings.Split(pr.Destination.Repository.FullName, "/")

if len(parts) < 2 {
return "unknown repo"
Expand All @@ -215,8 +214,8 @@ func (pr *PullRequest) GetRepoName() string {
}

type PullRequestMerge struct {
Title string `json:"title"`
Description string `json:"title"`
Source PlaceInfo `json:"source"`
Title string `json:"title"`
Description string `json:"title"`
Source PlaceInfo `json:"source"`
Destination PlaceInfo `json:"destination"`
}
Loading

0 comments on commit 989f77f

Please sign in to comment.