From 1cb4c01f5a9b9442263979ba9985e5e14c87c396 Mon Sep 17 00:00:00 2001 From: Andy Grunwald Date: Sun, 9 Sep 2018 14:19:25 +0200 Subject: [PATCH 1/4] Rename struct fields according go rules gometalinter/golint raised some warnings about the naming of struct fields: gometalinter --config gometalinter.json ./... changes.go:261:2:warning: struct field RobotId should be RobotID (golint) changes.go:263:2:warning: struct field RobotRunId should be RobotRunID (golint) changes.go:265:2:warning: struct field Url should be URL (golint) changes.go:280:2:warning: struct field RobotId should be RobotID (golint) changes.go:282:2:warning: struct field RobotRunId should be RobotRunID (golint) changes.go:284:2:warning: struct field Url should be URL (golint) changes.go:297:2:warning: struct field FixId should be FixID (golint) --- changes.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/changes.go b/changes.go index 2a13b8f..8fdea37 100644 --- a/changes.go +++ b/changes.go @@ -258,11 +258,11 @@ type RobotCommentInput struct { CommentInput // The ID of the robot that generated this comment. - RobotId string `json:"robot_id"` + RobotID string `json:"robot_id"` // An ID of the run of the robot. - RobotRunId string `json:"robot_run_id"` + RobotRunID string `json:"robot_run_id"` // URL to more information. - Url string `json:"url,omitempty"` + URL string `json:"url,omitempty"` // Robot specific properties as map that maps arbitrary keys to values. Properties *map[string]*string `json:"properties,omitempty"` // Suggested fixes for this robot comment as a list of FixSuggestionInfo @@ -277,11 +277,11 @@ type RobotCommentInfo struct { CommentInfo // The ID of the robot that generated this comment. - RobotId string `json:"robot_id"` + RobotID string `json:"robot_id"` // An ID of the run of the robot. - RobotRunId string `json:"robot_run_id"` + RobotRunID string `json:"robot_run_id"` // URL to more information. - Url string `json:"url,omitempty"` + URL string `json:"url,omitempty"` // Robot specific properties as map that maps arbitrary keys to values. Properties map[string]string `json:"properties,omitempty"` // Suggested fixes for this robot comment as a list of FixSuggestionInfo @@ -294,7 +294,7 @@ type RobotCommentInfo struct { type FixSuggestionInfo struct { // The UUID of the suggested fix. It will be generated automatically and // hence will be ignored if it’s set for input objects. - FixId string `json:"fix_id"` + FixID string `json:"fix_id"` // A description of the suggested fix. Description string `json:"description"` // A list of FixReplacementInfo entities indicating how the content of one or From a3daf03653021f61b6572dfdbc953d122fddd233 Mon Sep 17 00:00:00 2001 From: Andy Grunwald Date: Sun, 9 Sep 2018 18:13:26 +0200 Subject: [PATCH 2/4] gometalinter: Renamed linter gas to gosec --- authentication.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/authentication.go b/authentication.go index 7cb3795..193f622 100644 --- a/authentication.go +++ b/authentication.go @@ -1,7 +1,7 @@ package gerrit import ( - "crypto/md5" // nolint: gas + "crypto/md5" // nolint: gosec "crypto/rand" "encoding/base64" "errors" @@ -117,7 +117,7 @@ func (s *AuthenticationService) digestAuthHeader(response *http.Response) (strin uriHeader := authenticate["uri"] // A1 - h := md5.New() // nolint: gas + h := md5.New() // nolint: gosec A1 := fmt.Sprintf("%s:%s:%s", s.name, realmHeader, s.secret) if _, err := io.WriteString(h, A1); err != nil { return "", err @@ -125,7 +125,7 @@ func (s *AuthenticationService) digestAuthHeader(response *http.Response) (strin HA1 := fmt.Sprintf("%x", h.Sum(nil)) // A2 - h = md5.New() // nolint: gas + h = md5.New() // nolint: gosec A2 := fmt.Sprintf("%s:%s", response.Request.Method, uriHeader) if _, err := io.WriteString(h, A2); err != nil { return "", err @@ -141,7 +141,7 @@ func (s *AuthenticationService) digestAuthHeader(response *http.Response) (strin bytes += n } cnonce := base64.StdEncoding.EncodeToString(k) - digest := md5.New() // nolint: gas + digest := md5.New() // nolint: gosec if _, err := digest.Write([]byte(strings.Join([]string{HA1, nonceHeader, "00000001", cnonce, qopHeader, HA2}, ":"))); err != nil { return "", err } From e10a1211bc2128ac1239ab0bbf5cfab8c6ff11d6 Mon Sep 17 00:00:00 2001 From: Andy Grunwald Date: Sun, 9 Sep 2018 18:13:48 +0200 Subject: [PATCH 3/4] Fixed handling of unhandled error --- changes.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/changes.go b/changes.go index 8fdea37..f9cbf49 100644 --- a/changes.go +++ b/changes.go @@ -780,8 +780,15 @@ func (s *ChangesService) change(tail string, changeID string, input interface{}) v := new(ChangeInfo) resp, err := s.client.Do(req, v) + if err != nil { + return v, resp, err + } if resp.StatusCode == http.StatusConflict { - body, _ := ioutil.ReadAll(resp.Body) + var body []byte + body, err = ioutil.ReadAll(resp.Body) + if err != nil { + return v, resp, err + } err = errors.New(string(body[:])) } return v, resp, err From 46fe64282e4242abbe5b85a314d93a9d71caa8cb Mon Sep 17 00:00:00 2001 From: Andy Grunwald Date: Mon, 10 Sep 2018 17:26:52 +0200 Subject: [PATCH 4/4] Make code more readable and consistent regards return values --- changes.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/changes.go b/changes.go index f9cbf49..09fd6dd 100644 --- a/changes.go +++ b/changes.go @@ -781,17 +781,16 @@ func (s *ChangesService) change(tail string, changeID string, input interface{}) v := new(ChangeInfo) resp, err := s.client.Do(req, v) if err != nil { - return v, resp, err + return nil, resp, err } if resp.StatusCode == http.StatusConflict { - var body []byte - body, err = ioutil.ReadAll(resp.Body) + body, err := ioutil.ReadAll(resp.Body) if err != nil { return v, resp, err } - err = errors.New(string(body[:])) + return v, resp, errors.New(string(body[:])) } - return v, resp, err + return v, resp, nil } // SubmitChange submits a change.