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.WriteHeader(respCode)
rw.Header().Set("Content-Type", "application/json") 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") os.Setenv("GITHUB_ACCESS_TOKEN", "XX")
for _, testOject := range testNewClient { for _, testOject := range testNewClient {
client, _ := github.New(&testOject.config) client, _ := github.New(&testOject.config)
actualUrl := client.GetCommitURL() actualURL := client.GetCommitURL()
if testOject.config.CustomURL != "" { if testOject.config.CustomURL != "" {
expectedUrl := fmt.Sprintf("%s/%s/%s/commit/{{hash}}", testOject.config.CustomURL, testOject.config.User, testOject.config.Repo) expectedURL := fmt.Sprintf("%s/%s/%s/commit/{{hash}}", testOject.config.CustomURL, testOject.config.User, testOject.config.Repo)
assert.EqualValues(t, expectedUrl, actualUrl) assert.EqualValues(t, expectedURL, actualURL)
} else { } else {
expectedUrl := fmt.Sprintf("%s/%s/%s/commit/{{hash}}", "https://github.com", testOject.config.User, testOject.config.Repo) expectedURL := fmt.Sprintf("%s/%s/%s/commit/{{hash}}", "https://github.com", testOject.config.User, testOject.config.Repo)
assert.EqualValues(t, expectedUrl, actualUrl) assert.EqualValues(t, expectedURL, actualURL)
} }
} }
os.Unsetenv("GITHUB_ACCESS_TOKEN") os.Unsetenv("GITHUB_ACCESS_TOKEN")
@@ -176,14 +178,14 @@ func TestGetCompareURL(t *testing.T) {
os.Setenv("GITHUB_ACCESS_TOKEN", "XX") os.Setenv("GITHUB_ACCESS_TOKEN", "XX")
for _, testOject := range testNewClient { for _, testOject := range testNewClient {
client, _ := github.New(&testOject.config) client, _ := github.New(&testOject.config)
actualUrl := client.GetCompareURL("1", "2") actualURL := client.GetCompareURL("1", "2")
if testOject.config.CustomURL != "" { if testOject.config.CustomURL != "" {
expectedUrl := fmt.Sprintf("%s/%s/%s/compare/%s...%s", testOject.config.CustomURL, testOject.config.User, testOject.config.Repo, "1", "2") 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) assert.EqualValues(t, expectedURL, actualURL)
} else { } else {
expectedUrl := fmt.Sprintf("%s/%s/%s/compare/%s...%s", "https://github.com", testOject.config.User, testOject.config.Repo, "1", "2") 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) assert.EqualValues(t, expectedURL, actualURL)
} }
} }
os.Unsetenv("GITHUB_ACCESS_TOKEN") 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 { for _, f := range filesToUpload {
file, err := os.Open(*f) file, err := os.Open(*f)
defer file.Close()
if err != nil { if err != nil {
return err return err
} }
defer file.Close()
fileInfo, _ := file.Stat() fileInfo, _ := file.Stat()
result, err := g.uploadFile(fileInfo.Name(), file) result, err := g.uploadFile(fileInfo.Name(), file)
@@ -216,6 +217,9 @@ func (g *Client) uploadFile(fileName string, file *os.File) (*ProjectFile, error
uf := &ProjectFile{} uf := &ProjectFile{}
resp, err := util.Do(g.client, req, uf) resp, err := util.Do(g.client, req, uf)
if err != nil {
return nil, err
}
if err = util.IsValidResult(resp); err != nil { if err = util.IsValidResult(resp); err != nil {
return nil, err return nil, err

View File

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