Enable bodyclose linter (#36168)

Enabe
[`bodyclose`](https://golangci-lint.run/docs/linters/configuration/#bodyclose).
The only issue in non-test code (`services/migrations/dump.go`) was a
false-positive and I think there are a number of undetected cases, but I
guess it's still better than not having it.

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
silverwind
2025-12-16 14:08:43 +01:00
committed by GitHub
parent 3bb0770160
commit 84b74d7c3e
10 changed files with 19 additions and 3 deletions
+2 -1
View File
@@ -306,14 +306,15 @@ func (g *RepositoryDumper) CreateReleases(_ context.Context, releases ...*base.R
if err != nil {
return err
}
defer rc.Close()
} else {
resp, err := http.Get(*asset.DownloadURL)
if err != nil {
return err
}
defer resp.Body.Close()
rc = resp.Body
}
defer rc.Close()
fw, err := os.Create(attachPath)
if err != nil {
@@ -27,6 +27,7 @@ func TestGiteaDownloadRepo(t *testing.T) {
if err != nil || resp.StatusCode != http.StatusOK {
t.Skipf("Can't reach https://gitea.com, skipping %s", t.Name())
}
defer resp.Body.Close()
ctx := t.Context()
downloader, err := NewGiteaDownloader(ctx, "https://gitea.com", "gitea/test_repo", "", "", giteaToken)
require.NoError(t, err, "NewGiteaDownloader error occur")
+1
View File
@@ -30,6 +30,7 @@ func TestGitlabDownloadRepo(t *testing.T) {
if err != nil || resp.StatusCode != http.StatusOK {
t.Skipf("Can't access test repo, skipping %s", t.Name())
}
defer resp.Body.Close()
ctx := t.Context()
downloader, err := NewGitlabDownloader(ctx, "https://gitlab.com", "gitea/test_repo", gitlabPersonalAccessToken)
if err != nil {
+1
View File
@@ -27,6 +27,7 @@ func TestGogsDownloadRepo(t *testing.T) {
t.Skipf("visit test repo failed, ignored")
return
}
defer resp.Body.Close()
ctx := t.Context()
downloader := NewGogsDownloader(ctx, "https://try.gogs.io", "", "", gogsPersonalAccessToken, "lunnytest", "TESTREPO")
repo, err := downloader.GetRepoInfo(ctx)
+1
View File
@@ -19,6 +19,7 @@ func TestOneDevDownloadRepo(t *testing.T) {
if err != nil || resp.StatusCode != http.StatusOK {
t.Skipf("Can't access test repo, skipping %s", t.Name())
}
defer resp.Body.Close()
u, _ := url.Parse("https://code.onedev.io")
ctx := t.Context()