mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-01-09 09:05:26 +00:00
ensure stash responses closed
This commit is contained in:
parent
eb96456909
commit
3d6bd58be8
1 changed files with 14 additions and 4 deletions
|
@ -23,10 +23,11 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"strings"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/drone/drone/model"
|
"github.com/drone/drone/model"
|
||||||
"github.com/mrjones/oauth"
|
"github.com/mrjones/oauth"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -95,6 +96,9 @@ func (c *Client) FindCurrentUser() (*User, error) {
|
||||||
func (c *Client) FindRepo(owner string, name string) (*Repo, error) {
|
func (c *Client) FindRepo(owner string, name string) (*Repo, error) {
|
||||||
urlString := fmt.Sprintf(pathRepo, c.base, owner, name)
|
urlString := fmt.Sprintf(pathRepo, c.base, owner, name)
|
||||||
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 {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
@ -115,13 +119,19 @@ 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
|
||||||
_, err := c.FindRepo(owner, repo)
|
resp, 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
|
||||||
_, err = c.client.Get(fmt.Sprintf(pathHook, c.base, owner, repo, hookName))
|
resp2, err2 := c.client.Get(fmt.Sprintf(pathHook, c.base, owner, repo, hookName))
|
||||||
if err == nil {
|
if resp2 != nil {
|
||||||
|
defer resp2.Body.Close()
|
||||||
|
}
|
||||||
|
if err2 == nil {
|
||||||
perms.Push = true
|
perms.Push = true
|
||||||
perms.Admin = true
|
perms.Admin = true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue