diff --git a/internal/releaser/github/github_test.go b/internal/releaser/github/github_test.go index 93be9dc..d9ab789 100644 --- a/internal/releaser/github/github_test.go +++ b/internal/releaser/github/github_test.go @@ -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") diff --git a/internal/releaser/gitlab/gitlab.go b/internal/releaser/gitlab/gitlab.go index b739232..d966c11 100644 --- a/internal/releaser/gitlab/gitlab.go +++ b/internal/releaser/gitlab/gitlab.go @@ -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 diff --git a/internal/releaser/util/util.go b/internal/releaser/util/util.go index a1a476a..61523fc 100644 --- a/internal/releaser/util/util.go +++ b/internal/releaser/util/util.go @@ -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 }