chore(gitlab/github/util): fix golangci-lint issues

This commit is contained in:
fwiedmann
2019-08-08 21:01:40 +02:00
parent ff82ec7acd
commit c9d9420037
3 changed files with 19 additions and 16 deletions

View File

@@ -135,7 +135,9 @@ func initHTTPServer(respCode int, body string) *httptest.Server {
rw.WriteHeader(respCode)
rw.Header().Set("Content-Type", "application/json")
rw.Write([]byte(body))
if _, err := rw.Write([]byte(body)); err != nil {
log.Info(err)
}
}))
}
@@ -158,14 +160,14 @@ func TestGetCommitURL(t *testing.T) {
os.Setenv("GITHUB_ACCESS_TOKEN", "XX")
for _, testOject := range testNewClient {
client, _ := github.New(&testOject.config)
actualUrl := client.GetCommitURL()
actualURL := client.GetCommitURL()
if testOject.config.CustomURL != "" {
expectedUrl := fmt.Sprintf("%s/%s/%s/commit/{{hash}}", testOject.config.CustomURL, testOject.config.User, testOject.config.Repo)
assert.EqualValues(t, expectedUrl, actualUrl)
expectedURL := fmt.Sprintf("%s/%s/%s/commit/{{hash}}", testOject.config.CustomURL, testOject.config.User, testOject.config.Repo)
assert.EqualValues(t, expectedURL, actualURL)
} else {
expectedUrl := fmt.Sprintf("%s/%s/%s/commit/{{hash}}", "https://github.com", testOject.config.User, testOject.config.Repo)
assert.EqualValues(t, expectedUrl, actualUrl)
expectedURL := fmt.Sprintf("%s/%s/%s/commit/{{hash}}", "https://github.com", testOject.config.User, testOject.config.Repo)
assert.EqualValues(t, expectedURL, actualURL)
}
}
os.Unsetenv("GITHUB_ACCESS_TOKEN")
@@ -176,14 +178,14 @@ func TestGetCompareURL(t *testing.T) {
os.Setenv("GITHUB_ACCESS_TOKEN", "XX")
for _, testOject := range testNewClient {
client, _ := github.New(&testOject.config)
actualUrl := client.GetCompareURL("1", "2")
actualURL := client.GetCompareURL("1", "2")
if testOject.config.CustomURL != "" {
expectedUrl := fmt.Sprintf("%s/%s/%s/compare/%s...%s", testOject.config.CustomURL, testOject.config.User, testOject.config.Repo, "1", "2")
assert.EqualValues(t, expectedUrl, actualUrl)
expectedURL := fmt.Sprintf("%s/%s/%s/compare/%s...%s", testOject.config.CustomURL, testOject.config.User, testOject.config.Repo, "1", "2")
assert.EqualValues(t, expectedURL, actualURL)
} else {
expectedUrl := fmt.Sprintf("%s/%s/%s/compare/%s...%s", "https://github.com", testOject.config.User, testOject.config.Repo, "1", "2")
assert.EqualValues(t, expectedUrl, actualUrl)
expectedURL := fmt.Sprintf("%s/%s/%s/compare/%s...%s", "https://github.com", testOject.config.User, testOject.config.Repo, "1", "2")
assert.EqualValues(t, expectedURL, actualURL)
}
}
os.Unsetenv("GITHUB_ACCESS_TOKEN")

View File

@@ -149,10 +149,11 @@ func (g *Client) UploadAssets(repoDir string, assets []config.Asset) error {
for _, f := range filesToUpload {
file, err := os.Open(*f)
defer file.Close()
if err != nil {
return err
}
defer file.Close()
fileInfo, _ := file.Stat()
result, err := g.uploadFile(fileInfo.Name(), file)
@@ -216,6 +217,9 @@ func (g *Client) uploadFile(fileName string, file *os.File) (*ProjectFile, error
uf := &ProjectFile{}
resp, err := util.Do(g.client, req, uf)
if err != nil {
return nil, err
}
if err = util.IsValidResult(resp); err != nil {
return nil, err

View File

@@ -187,8 +187,5 @@ func IsValidResult(resp *http.Response) error {
// ShouldRetry request
func ShouldRetry(resp *http.Response) bool {
if resp.StatusCode == http.StatusTooManyRequests {
return true
}
return false
return resp.StatusCode == http.StatusTooManyRequests
}