update bb client
This commit is contained in:
parent
3d6bd58be8
commit
08739aaed9
1 changed files with 35 additions and 24 deletions
|
@ -62,10 +62,13 @@ func NewClientWithToken(url string, consumer *oauth.Consumer, AccessToken string
|
||||||
|
|
||||||
func (c *Client) FindCurrentUser() (*User, error) {
|
func (c *Client) FindCurrentUser() (*User, error) {
|
||||||
CurrentUserIdResponse, err := c.client.Get(fmt.Sprintf(currentUserId, c.base))
|
CurrentUserIdResponse, err := c.client.Get(fmt.Sprintf(currentUserId, c.base))
|
||||||
|
if CurrentUserIdResponse != nil {
|
||||||
|
defer CurrentUserIdResponse.Body.Close()
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer CurrentUserIdResponse.Body.Close()
|
|
||||||
bits, err := ioutil.ReadAll(CurrentUserIdResponse.Body)
|
bits, err := ioutil.ReadAll(CurrentUserIdResponse.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -73,10 +76,12 @@ func (c *Client) FindCurrentUser() (*User, error) {
|
||||||
login := string(bits)
|
login := string(bits)
|
||||||
|
|
||||||
CurrentUserResponse, err := c.client.Get(fmt.Sprintf(pathUser, c.base, login))
|
CurrentUserResponse, err := c.client.Get(fmt.Sprintf(pathUser, c.base, login))
|
||||||
|
if CurrentUserResponse != nil {
|
||||||
|
defer CurrentUserResponse.Body.Close()
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer CurrentUserResponse.Body.Close()
|
|
||||||
|
|
||||||
contents, err := ioutil.ReadAll(CurrentUserResponse.Body)
|
contents, err := ioutil.ReadAll(CurrentUserResponse.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -102,7 +107,6 @@ func (c *Client) FindRepo(owner string, name string) (*Repo, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
defer response.Body.Close()
|
|
||||||
contents, err := ioutil.ReadAll(response.Body)
|
contents, err := ioutil.ReadAll(response.Body)
|
||||||
repo := Repo{}
|
repo := Repo{}
|
||||||
err = json.Unmarshal(contents, &repo)
|
err = json.Unmarshal(contents, &repo)
|
||||||
|
@ -119,19 +123,16 @@ func (c *Client) FindRepos() ([]*Repo, error) {
|
||||||
func (c *Client) FindRepoPerms(owner string, repo string) (*model.Perm, error) {
|
func (c *Client) FindRepoPerms(owner string, repo string) (*model.Perm, error) {
|
||||||
perms := new(model.Perm)
|
perms := new(model.Perm)
|
||||||
// If you don't have access return none right away
|
// If you don't have access return none right away
|
||||||
resp, err := c.FindRepo(owner, repo)
|
_, err := c.FindRepo(owner, repo)
|
||||||
if resp != nil {
|
|
||||||
defer resp.Body.Close()
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return perms, err
|
return perms, err
|
||||||
}
|
}
|
||||||
// Must have admin to be able to list hooks. If have access the enable perms
|
// Must have admin to be able to list hooks. If have access the enable perms
|
||||||
resp2, err2 := c.client.Get(fmt.Sprintf(pathHook, c.base, owner, repo, hookName))
|
resp, err := c.client.Get(fmt.Sprintf(pathHook, c.base, owner, repo, hookName))
|
||||||
if resp2 != nil {
|
if resp != nil {
|
||||||
defer resp2.Body.Close()
|
defer resp.Body.Close()
|
||||||
}
|
}
|
||||||
if err2 == nil {
|
if err == nil {
|
||||||
perms.Push = true
|
perms.Push = true
|
||||||
perms.Admin = true
|
perms.Admin = true
|
||||||
}
|
}
|
||||||
|
@ -141,13 +142,15 @@ func (c *Client) FindRepoPerms(owner string, repo string) (*model.Perm, error) {
|
||||||
|
|
||||||
func (c *Client) FindFileForRepo(owner string, repo string, fileName string, ref string) ([]byte, error) {
|
func (c *Client) FindFileForRepo(owner string, repo string, fileName string, ref string) ([]byte, error) {
|
||||||
response, err := c.client.Get(fmt.Sprintf(pathSource, c.base, owner, repo, fileName, ref))
|
response, err := c.client.Get(fmt.Sprintf(pathSource, c.base, owner, repo, fileName, ref))
|
||||||
|
if response != nil {
|
||||||
|
defer response.Body.Close()
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
if response.StatusCode == 404 {
|
if response.StatusCode == 404 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
defer response.Body.Close()
|
|
||||||
responseBytes, err := ioutil.ReadAll(response.Body)
|
responseBytes, err := ioutil.ReadAll(response.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
|
@ -201,10 +204,13 @@ func (c *Client) DeleteHook(owner string, name string, link string) error {
|
||||||
func (c *Client) GetHookDetails(owner string, name string) (*HookPluginDetails, error) {
|
func (c *Client) GetHookDetails(owner string, name string) (*HookPluginDetails, error) {
|
||||||
urlString := fmt.Sprintf(pathHookDetails, c.base, owner, name, hookName)
|
urlString := fmt.Sprintf(pathHookDetails, c.base, owner, name, hookName)
|
||||||
response, err := c.client.Get(urlString)
|
response, err := c.client.Get(urlString)
|
||||||
|
if response != nil {
|
||||||
|
defer response.Body.Close()
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer response.Body.Close()
|
|
||||||
hookDetails := HookPluginDetails{}
|
hookDetails := HookPluginDetails{}
|
||||||
err = json.NewDecoder(response.Body).Decode(&hookDetails)
|
err = json.NewDecoder(response.Body).Decode(&hookDetails)
|
||||||
return &hookDetails, err
|
return &hookDetails, err
|
||||||
|
@ -213,10 +219,13 @@ func (c *Client) GetHookDetails(owner string, name string) (*HookPluginDetails,
|
||||||
func (c *Client) GetHooks(owner string, name string) (*HookSettings, error) {
|
func (c *Client) GetHooks(owner string, name string) (*HookSettings, error) {
|
||||||
urlString := fmt.Sprintf(pathHookSettings, c.base, owner, name, hookName)
|
urlString := fmt.Sprintf(pathHookSettings, c.base, owner, name, hookName)
|
||||||
response, err := c.client.Get(urlString)
|
response, err := c.client.Get(urlString)
|
||||||
|
if response != nil {
|
||||||
|
defer response.Body.Close()
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer response.Body.Close()
|
|
||||||
hookSettings := HookSettings{}
|
hookSettings := HookSettings{}
|
||||||
err = json.NewDecoder(response.Body).Decode(&hookSettings)
|
err = json.NewDecoder(response.Body).Decode(&hookSettings)
|
||||||
return &hookSettings, err
|
return &hookSettings, err
|
||||||
|
@ -229,10 +238,12 @@ func (c *Client) doPut(url string, body []byte) error {
|
||||||
request, err := http.NewRequest("PUT", url, bytes.NewBuffer(body))
|
request, err := http.NewRequest("PUT", url, bytes.NewBuffer(body))
|
||||||
request.Header.Add("Content-Type", "application/json")
|
request.Header.Add("Content-Type", "application/json")
|
||||||
response, err := c.client.Do(request)
|
response, err := c.client.Do(request)
|
||||||
|
if response != nil {
|
||||||
|
defer response.Body.Close()
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer response.Body.Close()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,22 +261,20 @@ func (c *Client) doPost(url string, status *BuildStatus) error {
|
||||||
request, err := http.NewRequest("POST", url, buf)
|
request, err := http.NewRequest("POST", url, buf)
|
||||||
request.Header.Add("Content-Type", "application/json")
|
request.Header.Add("Content-Type", "application/json")
|
||||||
response, err := c.client.Do(request)
|
response, err := c.client.Do(request)
|
||||||
if err != nil {
|
if response != nil {
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
return nil
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
//Helper function to do delete on the hook
|
//Helper function to do delete on the hook
|
||||||
func (c *Client) doDelete(url string) error {
|
func (c *Client) doDelete(url string) error {
|
||||||
request, err := http.NewRequest("DELETE", url, nil)
|
request, err := http.NewRequest("DELETE", url, nil)
|
||||||
response, err := c.client.Do(request)
|
response, err := c.client.Do(request)
|
||||||
if err != nil {
|
if response != nil {
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
return nil
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
//Helper function to get repos paginated
|
//Helper function to get repos paginated
|
||||||
|
@ -273,10 +282,12 @@ func (c *Client) paginatedRepos(start int) ([]*Repo, error) {
|
||||||
limit := 1000
|
limit := 1000
|
||||||
requestUrl := fmt.Sprintf(pathRepos, c.base, strconv.Itoa(start), strconv.Itoa(limit))
|
requestUrl := fmt.Sprintf(pathRepos, c.base, strconv.Itoa(start), strconv.Itoa(limit))
|
||||||
response, err := c.client.Get(requestUrl)
|
response, err := c.client.Get(requestUrl)
|
||||||
|
if response != nil {
|
||||||
|
defer response.Body.Close()
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer response.Body.Close()
|
|
||||||
var repoResponse Repos
|
var repoResponse Repos
|
||||||
err = json.NewDecoder(response.Body).Decode(&repoResponse)
|
err = json.NewDecoder(response.Body).Decode(&repoResponse)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue