From cee4caab7869f9fb3b2d93f40b7e0a5e6c609ea9 Mon Sep 17 00:00:00 2001 From: silverwind Date: Wed, 18 Jun 2025 16:59:46 +0200 Subject: [PATCH 1/9] Upgrade gopls to v0.19.0 --- Makefile | 2 +- models/migrations/v1_22/v294_test.go | 2 +- modules/public/public.go | 1 - routers/private/hook_verification_test.go | 4 +++- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index bb70b91bb9b0c..32dbe069bab7b 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest GO_LICENSES_PACKAGE ?= github.com/google/go-licenses@v1 GOVULNCHECK_PACKAGE ?= golang.org/x/vuln/cmd/govulncheck@v1 ACTIONLINT_PACKAGE ?= github.com/rhysd/actionlint/cmd/actionlint@v1 -GOPLS_PACKAGE ?= golang.org/x/tools/gopls@v0.17.1 +GOPLS_PACKAGE ?= golang.org/x/tools/gopls@v0.19.0 DOCKER_IMAGE ?= gitea/gitea DOCKER_TAG ?= latest diff --git a/models/migrations/v1_22/v294_test.go b/models/migrations/v1_22/v294_test.go index a1d702cb77dad..49de1a3322c13 100644 --- a/models/migrations/v1_22/v294_test.go +++ b/models/migrations/v1_22/v294_test.go @@ -44,7 +44,7 @@ func Test_AddUniqueIndexForProjectIssue(t *testing.T) { for _, index := range tables[0].Indexes { if index.Type == schemas.UniqueType { found = true - slices.Equal(index.Cols, []string{"project_id", "issue_id"}) + assert.True(t, slices.Equal(index.Cols, []string{"project_id", "issue_id"})) break } } diff --git a/modules/public/public.go b/modules/public/public.go index 9bc04f3f7e0be..a7eace1538b45 100644 --- a/modules/public/public.go +++ b/modules/public/public.go @@ -110,5 +110,4 @@ func servePublicAsset(w http.ResponseWriter, req *http.Request, fi os.FileInfo, } } http.ServeContent(w, req, fi.Name(), modtime, content) - return } diff --git a/routers/private/hook_verification_test.go b/routers/private/hook_verification_test.go index f6c2e1087f72f..8653e34daa424 100644 --- a/routers/private/hook_verification_test.go +++ b/routers/private/hook_verification_test.go @@ -18,7 +18,9 @@ func TestVerifyCommits(t *testing.T) { unittest.PrepareTestEnv(t) gitRepo, err := git.OpenRepository(t.Context(), testReposDir+"repo1_hook_verification") - defer gitRepo.Close() + if err != nil { + defer gitRepo.Close() + } assert.NoError(t, err) objectFormat, err := gitRepo.GetObjectFormat() From 6119b25fc72a4475471849265c90f616b9355d56 Mon Sep 17 00:00:00 2001 From: silverwind Date: Wed, 18 Jun 2025 17:11:56 +0200 Subject: [PATCH 2/9] set severity --- tools/lint-go-gopls.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/lint-go-gopls.sh b/tools/lint-go-gopls.sh index a222ea14d7e17..2cd26ca6fe4dd 100755 --- a/tools/lint-go-gopls.sh +++ b/tools/lint-go-gopls.sh @@ -11,7 +11,7 @@ IGNORE_PATTERNS=( # current absolute path, indicating a error was found. This is necessary # because the tool does not set non-zero exit code when errors are found. # ref: https://github.com/golang/go/issues/67078 -ERROR_LINES=$("$GO" run "$GOPLS_PACKAGE" check "$@" 2>/dev/null | grep -E "^$PWD" | grep -vFf <(printf '%s\n' "${IGNORE_PATTERNS[@]}")); +ERROR_LINES=$("$GO" run "$GOPLS_PACKAGE" check -severity=warning "$@" 2>/dev/null | grep -E "^$PWD" | grep -vFf <(printf '%s\n' "${IGNORE_PATTERNS[@]}")); NUM_ERRORS=$(echo -n "$ERROR_LINES" | wc -l) if [ "$NUM_ERRORS" -eq "0" ]; then From 3824eecb5579ed7594e5e5e7115bf5a6d8b6d964 Mon Sep 17 00:00:00 2001 From: silverwind Date: Wed, 18 Jun 2025 17:20:58 +0200 Subject: [PATCH 3/9] drop line, run modernize --- models/migrations/v1_22/v294_test.go | 2 -- services/packages/arch/vercmp.go | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/models/migrations/v1_22/v294_test.go b/models/migrations/v1_22/v294_test.go index 49de1a3322c13..f5108e5a42533 100644 --- a/models/migrations/v1_22/v294_test.go +++ b/models/migrations/v1_22/v294_test.go @@ -4,7 +4,6 @@ package v1_22 //nolint import ( - "slices" "testing" "code.gitea.io/gitea/models/migrations/base" @@ -44,7 +43,6 @@ func Test_AddUniqueIndexForProjectIssue(t *testing.T) { for _, index := range tables[0].Indexes { if index.Type == schemas.UniqueType { found = true - assert.True(t, slices.Equal(index.Cols, []string{"project_id", "issue_id"})) break } } diff --git a/services/packages/arch/vercmp.go b/services/packages/arch/vercmp.go index 6dcd0df41951a..d44aa530f03dc 100644 --- a/services/packages/arch/vercmp.go +++ b/services/packages/arch/vercmp.go @@ -35,7 +35,7 @@ func parseEVR(evr string) (epoch, version, release string) { func compareSegments(a, b []string) int { lenA, lenB := len(a), len(b) l := min(lenA, lenB) - for i := 0; i < l; i++ { + for i := range l { if r := compare(a[i], b[i]); r != 0 { return r } From b0458bfcad68cc56fe4f145019c021280c7e0889 Mon Sep 17 00:00:00 2001 From: silverwind Date: Wed, 18 Jun 2025 17:25:01 +0200 Subject: [PATCH 4/9] run modernize as part of 'make fmt' --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 32dbe069bab7b..48271e0b2fdfe 100644 --- a/Makefile +++ b/Makefile @@ -37,6 +37,7 @@ GO_LICENSES_PACKAGE ?= github.com/google/go-licenses@v1 GOVULNCHECK_PACKAGE ?= golang.org/x/vuln/cmd/govulncheck@v1 ACTIONLINT_PACKAGE ?= github.com/rhysd/actionlint/cmd/actionlint@v1 GOPLS_PACKAGE ?= golang.org/x/tools/gopls@v0.19.0 +GOPLS_MODERNIZE_PACKAGE ?= golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@v0.19.0 DOCKER_IMAGE ?= gitea/gitea DOCKER_TAG ?= latest @@ -231,6 +232,7 @@ clean: ## delete backend and integration files .PHONY: fmt fmt: ## format the Go code + @$(GO) run $(GOPLS_MODERNIZE_PACKAGE) -fix ./... @GOFUMPT_PACKAGE=$(GOFUMPT_PACKAGE) $(GO) run build/code-batch-process.go gitea-fmt -w '{file-list}' $(eval TEMPLATES := $(shell find templates -type f -name '*.tmpl')) @# strip whitespace after '{{' or '(' and before '}}' or ')' unless there is only From 9991d6396c959215ceab0118059986db1417493f Mon Sep 17 00:00:00 2001 From: silverwind Date: Wed, 18 Jun 2025 17:27:16 +0200 Subject: [PATCH 5/9] update target description --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 48271e0b2fdfe..f5ecc2837fead 100644 --- a/Makefile +++ b/Makefile @@ -231,7 +231,7 @@ clean: ## delete backend and integration files tests/e2e/reports/ tests/e2e/test-artifacts/ tests/e2e/test-snapshots/ .PHONY: fmt -fmt: ## format the Go code +fmt: ## format and fix the Go code @$(GO) run $(GOPLS_MODERNIZE_PACKAGE) -fix ./... @GOFUMPT_PACKAGE=$(GOFUMPT_PACKAGE) $(GO) run build/code-batch-process.go gitea-fmt -w '{file-list}' $(eval TEMPLATES := $(shell find templates -type f -name '*.tmpl')) From 0db1de0b27169c5904b44ced49349e128691b949 Mon Sep 17 00:00:00 2001 From: silverwind Date: Wed, 18 Jun 2025 17:33:45 +0200 Subject: [PATCH 6/9] split out into `make fix` --- Makefile | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index f5ecc2837fead..8dfc786356a5b 100644 --- a/Makefile +++ b/Makefile @@ -231,8 +231,7 @@ clean: ## delete backend and integration files tests/e2e/reports/ tests/e2e/test-artifacts/ tests/e2e/test-snapshots/ .PHONY: fmt -fmt: ## format and fix the Go code - @$(GO) run $(GOPLS_MODERNIZE_PACKAGE) -fix ./... +fmt: ## format the Go and template code @GOFUMPT_PACKAGE=$(GOFUMPT_PACKAGE) $(GO) run build/code-batch-process.go gitea-fmt -w '{file-list}' $(eval TEMPLATES := $(shell find templates -type f -name '*.tmpl')) @# strip whitespace after '{{' or '(' and before '}}' or ')' unless there is only @@ -251,6 +250,19 @@ fmt-check: fmt exit 1; \ fi +.PHONY: fix +fix: ## apply code fixes to Go code + $(GO) run $(GOPLS_MODERNIZE_PACKAGE) -fix ./... + +.PHONY: fix-check +fix-check: fix + @diff=$$(git diff --color=always $(GO_SOURCES)); \ + if [ -n "$$diff" ]; then \ + echo "Please run 'make fix' and commit the result:"; \ + printf "%s" "$${diff}"; \ + exit 1; \ + fi + .PHONY: $(TAGS_EVIDENCE) $(TAGS_EVIDENCE): @mkdir -p $(MAKE_EVIDENCE_DIR) @@ -290,7 +302,7 @@ checks: checks-frontend checks-backend ## run various consistency checks checks-frontend: lockfile-check svg-check ## check frontend files .PHONY: checks-backend -checks-backend: tidy-check swagger-check fmt-check swagger-validate security-check ## check backend files +checks-backend: tidy-check swagger-check fmt-check fix-check swagger-validate security-check ## check backend files .PHONY: lint lint: lint-frontend lint-backend lint-spell ## lint everything From 183563265082c90b18221635f1a08a6be9da45eb Mon Sep 17 00:00:00 2001 From: silverwind Date: Wed, 18 Jun 2025 17:35:10 +0200 Subject: [PATCH 7/9] description --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8dfc786356a5b..ea981090c1359 100644 --- a/Makefile +++ b/Makefile @@ -251,7 +251,7 @@ fmt-check: fmt fi .PHONY: fix -fix: ## apply code fixes to Go code +fix: ## apply automated fixes to Go code $(GO) run $(GOPLS_MODERNIZE_PACKAGE) -fix ./... .PHONY: fix-check From 73cf74712f1ec0a0be86e07608bfe756eba10d7b Mon Sep 17 00:00:00 2001 From: silverwind Date: Wed, 18 Jun 2025 18:50:55 +0200 Subject: [PATCH 8/9] add to deps-tools --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index ea981090c1359..c868ef4463804 100644 --- a/Makefile +++ b/Makefile @@ -823,6 +823,7 @@ deps-tools: ## install tool dependencies $(GO) install $(GOVULNCHECK_PACKAGE) & \ $(GO) install $(ACTIONLINT_PACKAGE) & \ $(GO) install $(GOPLS_PACKAGE) & \ + $(GO) install $(GOPLS_MODERNIZE_PACKAGE) & \ wait node_modules: package-lock.json From bb90dc0a894ae380f60dc5f615ad6da63fd0842b Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 18 Jun 2025 11:00:05 -0700 Subject: [PATCH 9/9] fix test --- models/migrations/v1_22/v294_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/models/migrations/v1_22/v294_test.go b/models/migrations/v1_22/v294_test.go index f5108e5a42533..c3de332650526 100644 --- a/models/migrations/v1_22/v294_test.go +++ b/models/migrations/v1_22/v294_test.go @@ -43,6 +43,7 @@ func Test_AddUniqueIndexForProjectIssue(t *testing.T) { for _, index := range tables[0].Indexes { if index.Type == schemas.UniqueType { found = true + assert.ElementsMatch(t, index.Cols, []string{"project_id", "issue_id"}) break } }