Add golangci-lint workflow (#4999)
* fix lint workflow * add golang lint * close http response body
This commit is contained in:
@@ -63,7 +63,7 @@ func (j *Jenkins) Init() (*Jenkins, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rsp.Body.Close()
|
||||
j.Version = rsp.Header.Get("X-Jenkins")
|
||||
//if j.Raw == nil {
|
||||
// return nil, errors.New("Connection Failed, Please verify that the host and credentials are correct.")
|
||||
@@ -214,6 +214,7 @@ func (j *Jenkins) Poll() (int, error) {
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
resp.Body.Close()
|
||||
return resp.StatusCode, nil
|
||||
}
|
||||
|
||||
@@ -233,6 +234,7 @@ func (j *Jenkins) GetGlobalRole(roleName string) (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
response.Body.Close()
|
||||
if response.StatusCode != http.StatusOK {
|
||||
return "", errors.New(strconv.Itoa(response.StatusCode))
|
||||
}
|
||||
@@ -279,6 +281,7 @@ func (j *Jenkins) AssignGlobalRole(roleName string, sid string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
response.Body.Close()
|
||||
if response.StatusCode != http.StatusOK {
|
||||
return errors.New(strconv.Itoa(response.StatusCode))
|
||||
}
|
||||
@@ -301,6 +304,7 @@ func (j *Jenkins) UnAssignGlobalRole(roleName string, sid string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
response.Body.Close()
|
||||
if response.StatusCode != http.StatusOK {
|
||||
return errors.New(strconv.Itoa(response.StatusCode))
|
||||
}
|
||||
@@ -321,6 +325,7 @@ func (j *Jenkins) GetProjectRole(roleName string) (*ProjectRole, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response.Body.Close()
|
||||
if response.StatusCode != http.StatusOK {
|
||||
return nil, errors.New(strconv.Itoa(response.StatusCode))
|
||||
}
|
||||
@@ -353,6 +358,7 @@ func (j *Jenkins) AssignProjectRole(roleName string, sid string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
response.Body.Close()
|
||||
if response.StatusCode != http.StatusOK {
|
||||
return errors.New(strconv.Itoa(response.StatusCode))
|
||||
}
|
||||
@@ -375,6 +381,7 @@ func (j *Jenkins) UnAssignProjectRole(roleName string, sid string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
response.Body.Close()
|
||||
if response.StatusCode != http.StatusOK {
|
||||
return errors.New(strconv.Itoa(response.StatusCode))
|
||||
}
|
||||
@@ -402,6 +409,7 @@ func (j *Jenkins) AddGlobalRole(roleName string, ids devops.GlobalPermissionIds,
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
response.Body.Close()
|
||||
if response.StatusCode != http.StatusOK {
|
||||
return errors.New(strconv.Itoa(response.StatusCode))
|
||||
}
|
||||
@@ -419,6 +427,7 @@ func (j *Jenkins) DeleteProjectRoles(roleName ...string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
response.Body.Close()
|
||||
if response.StatusCode != http.StatusOK {
|
||||
fmt.Println(responseString)
|
||||
return errors.New(strconv.Itoa(response.StatusCode))
|
||||
@@ -448,6 +457,7 @@ func (j *Jenkins) AddProjectRole(roleName string, pattern string, ids devops.Pro
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
response.Body.Close()
|
||||
if response.StatusCode != http.StatusOK {
|
||||
return errors.New(strconv.Itoa(response.StatusCode))
|
||||
}
|
||||
@@ -464,6 +474,7 @@ func (j *Jenkins) DeleteUserInProject(username string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
response.Body.Close()
|
||||
if response.StatusCode != http.StatusOK {
|
||||
return errors.New(strconv.Itoa(response.StatusCode))
|
||||
}
|
||||
@@ -837,6 +848,7 @@ func (j *Jenkins) CheckCron(projectName string, httpParameters *devops.HttpParam
|
||||
var path string
|
||||
|
||||
reader = httpParameters.Body
|
||||
//nolint:ineffassign,staticcheck
|
||||
cronData, err := ioutil.ReadAll(reader)
|
||||
err = json.Unmarshal(cronData, cron)
|
||||
if err != nil {
|
||||
@@ -889,6 +901,7 @@ func (j *Jenkins) ToJson(httpParameters *devops.HttpParameters) (map[string]inte
|
||||
// After creating an instance call init method.
|
||||
func CreateJenkins(client *http.Client, base string, maxConnection int, auth ...interface{}) *Jenkins {
|
||||
j := &Jenkins{}
|
||||
//nolint:gosimple
|
||||
if strings.HasSuffix(base, "/") {
|
||||
base = base[:len(base)-1]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user