From f69101bf3c59ffa3a8d0e6330cfe2683c648dd7e Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 13 Apr 2024 13:18:19 +0200 Subject: [PATCH 01/10] Add `interface{}` to any replacement to `make fmt` --- Makefile | 3 ++- modules/optional/serialization.go | 2 +- routers/api/actions/artifact.pb.go | 24 ++++++++++++------------ services/actions/auth_test.go | 2 +- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index f1acfbc81e3cb..4d77ce2354c15 100644 --- a/Makefile +++ b/Makefile @@ -295,7 +295,8 @@ clean: .PHONY: fmt fmt: - GOFUMPT_PACKAGE=$(GOFUMPT_PACKAGE) $(GO) run build/code-batch-process.go gitea-fmt -w '{file-list}' + @gofmt -w -r 'interface{} -> any' $(GO_SOURCES) + @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 @# whitespace before it diff --git a/modules/optional/serialization.go b/modules/optional/serialization.go index 6688e78cd1812..b120a0edf6b94 100644 --- a/modules/optional/serialization.go +++ b/modules/optional/serialization.go @@ -35,7 +35,7 @@ func (o *Option[T]) UnmarshalYAML(value *yaml.Node) error { return nil } -func (o Option[T]) MarshalYAML() (interface{}, error) { +func (o Option[T]) MarshalYAML() (any, error) { if !o.Has() { return nil, nil } diff --git a/routers/api/actions/artifact.pb.go b/routers/api/actions/artifact.pb.go index 590eda9fb9a08..bbeaef3f10c5b 100644 --- a/routers/api/actions/artifact.pb.go +++ b/routers/api/actions/artifact.pb.go @@ -866,7 +866,7 @@ func file_artifact_proto_rawDescGZIP() []byte { var ( file_artifact_proto_msgTypes = make([]protoimpl.MessageInfo, 11) - file_artifact_proto_goTypes = []interface{}{ + file_artifact_proto_goTypes = []any{ (*CreateArtifactRequest)(nil), // 0: github.actions.results.api.v1.CreateArtifactRequest (*CreateArtifactResponse)(nil), // 1: github.actions.results.api.v1.CreateArtifactResponse (*FinalizeArtifactRequest)(nil), // 2: github.actions.results.api.v1.FinalizeArtifactRequest @@ -904,7 +904,7 @@ func file_artifact_proto_init() { return } if !protoimpl.UnsafeEnabled { - file_artifact_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + file_artifact_proto_msgTypes[0].Exporter = func(v any, i int) any { switch v := v.(*CreateArtifactRequest); i { case 0: return &v.state @@ -916,7 +916,7 @@ func file_artifact_proto_init() { return nil } } - file_artifact_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + file_artifact_proto_msgTypes[1].Exporter = func(v any, i int) any { switch v := v.(*CreateArtifactResponse); i { case 0: return &v.state @@ -928,7 +928,7 @@ func file_artifact_proto_init() { return nil } } - file_artifact_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + file_artifact_proto_msgTypes[2].Exporter = func(v any, i int) any { switch v := v.(*FinalizeArtifactRequest); i { case 0: return &v.state @@ -940,7 +940,7 @@ func file_artifact_proto_init() { return nil } } - file_artifact_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + file_artifact_proto_msgTypes[3].Exporter = func(v any, i int) any { switch v := v.(*FinalizeArtifactResponse); i { case 0: return &v.state @@ -952,7 +952,7 @@ func file_artifact_proto_init() { return nil } } - file_artifact_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + file_artifact_proto_msgTypes[4].Exporter = func(v any, i int) any { switch v := v.(*ListArtifactsRequest); i { case 0: return &v.state @@ -964,7 +964,7 @@ func file_artifact_proto_init() { return nil } } - file_artifact_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + file_artifact_proto_msgTypes[5].Exporter = func(v any, i int) any { switch v := v.(*ListArtifactsResponse); i { case 0: return &v.state @@ -976,7 +976,7 @@ func file_artifact_proto_init() { return nil } } - file_artifact_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + file_artifact_proto_msgTypes[6].Exporter = func(v any, i int) any { switch v := v.(*ListArtifactsResponse_MonolithArtifact); i { case 0: return &v.state @@ -988,7 +988,7 @@ func file_artifact_proto_init() { return nil } } - file_artifact_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + file_artifact_proto_msgTypes[7].Exporter = func(v any, i int) any { switch v := v.(*GetSignedArtifactURLRequest); i { case 0: return &v.state @@ -1000,7 +1000,7 @@ func file_artifact_proto_init() { return nil } } - file_artifact_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { + file_artifact_proto_msgTypes[8].Exporter = func(v any, i int) any { switch v := v.(*GetSignedArtifactURLResponse); i { case 0: return &v.state @@ -1012,7 +1012,7 @@ func file_artifact_proto_init() { return nil } } - file_artifact_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { + file_artifact_proto_msgTypes[9].Exporter = func(v any, i int) any { switch v := v.(*DeleteArtifactRequest); i { case 0: return &v.state @@ -1024,7 +1024,7 @@ func file_artifact_proto_init() { return nil } } - file_artifact_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { + file_artifact_proto_msgTypes[10].Exporter = func(v any, i int) any { switch v := v.(*DeleteArtifactResponse); i { case 0: return &v.state diff --git a/services/actions/auth_test.go b/services/actions/auth_test.go index f73ae8ae4c36a..12db2bae565da 100644 --- a/services/actions/auth_test.go +++ b/services/actions/auth_test.go @@ -20,7 +20,7 @@ func TestCreateAuthorizationToken(t *testing.T) { assert.Nil(t, err) assert.NotEqual(t, "", token) claims := jwt.MapClaims{} - _, err = jwt.ParseWithClaims(token, claims, func(t *jwt.Token) (interface{}, error) { + _, err = jwt.ParseWithClaims(token, claims, func(t *jwt.Token) (any, error) { return setting.GetGeneralTokenSigningSecret(), nil }) assert.Nil(t, err) From 4d704c2d56e4e20d4ffc6d80700e5b7fc4a0b5b4 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 13 Apr 2024 13:34:18 +0200 Subject: [PATCH 02/10] run it in code-batch-process --- Makefile | 1 - build/code-batch-process.go | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4d77ce2354c15..594f13ead8acf 100644 --- a/Makefile +++ b/Makefile @@ -295,7 +295,6 @@ clean: .PHONY: fmt fmt: - @gofmt -w -r 'interface{} -> any' $(GO_SOURCES) @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 diff --git a/build/code-batch-process.go b/build/code-batch-process.go index b3ee3994207dc..73fa808ce7686 100644 --- a/build/code-batch-process.go +++ b/build/code-batch-process.go @@ -278,6 +278,7 @@ func main() { log.Print("the -d option is not supported by gitea-fmt") } cmdErrors = append(cmdErrors, giteaFormatGoImports(files, containsString(subArgs, "-w"))) + cmdErrors = append(cmdErrors, passThroughCmd("gofmt", append([]string{"-w", "-r", "interface{} -> any"}, substArgs...))) cmdErrors = append(cmdErrors, passThroughCmd("go", append([]string{"run", os.Getenv("GOFUMPT_PACKAGE"), "-extra", "-lang", getGoVersion()}, substArgs...))) default: log.Fatalf("unknown cmd: %s %v", subCmd, subArgs) From b421e77e29bd3e4575ba65ddeb877666c4c016a1 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 13 Apr 2024 13:55:57 +0200 Subject: [PATCH 03/10] remove unnecessary getGoVersion --- build/code-batch-process.go | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/build/code-batch-process.go b/build/code-batch-process.go index 73fa808ce7686..6a65a2707b84c 100644 --- a/build/code-batch-process.go +++ b/build/code-batch-process.go @@ -203,17 +203,6 @@ Example: `, "file-batch-exec") } -func getGoVersion() string { - goModFile, err := os.ReadFile("go.mod") - if err != nil { - log.Fatalf(`Faild to read "go.mod": %v`, err) - os.Exit(1) - } - goModVersionRegex := regexp.MustCompile(`go \d+\.\d+`) - goModVersionLine := goModVersionRegex.Find(goModFile) - return string(goModVersionLine[3:]) -} - func newFileCollectorFromMainOptions(mainOptions map[string]string) (fc *fileCollector, err error) { fileFilter := mainOptions["file-filter"] if fileFilter == "" { @@ -279,7 +268,7 @@ func main() { } cmdErrors = append(cmdErrors, giteaFormatGoImports(files, containsString(subArgs, "-w"))) cmdErrors = append(cmdErrors, passThroughCmd("gofmt", append([]string{"-w", "-r", "interface{} -> any"}, substArgs...))) - cmdErrors = append(cmdErrors, passThroughCmd("go", append([]string{"run", os.Getenv("GOFUMPT_PACKAGE"), "-extra", "-lang", getGoVersion()}, substArgs...))) + cmdErrors = append(cmdErrors, passThroughCmd("go", append([]string{"run", os.Getenv("GOFUMPT_PACKAGE"), "-extra"}, substArgs...))) default: log.Fatalf("unknown cmd: %s %v", subCmd, subArgs) } From 3b5f14ef967e722907654894c4084015908baf31 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 13 Apr 2024 16:10:08 +0200 Subject: [PATCH 04/10] revert files --- modules/optional/serialization.go | 2 +- routers/api/actions/artifact.pb.go | 24 ++++++++++++------------ services/actions/auth_test.go | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/modules/optional/serialization.go b/modules/optional/serialization.go index b120a0edf6b94..6688e78cd1812 100644 --- a/modules/optional/serialization.go +++ b/modules/optional/serialization.go @@ -35,7 +35,7 @@ func (o *Option[T]) UnmarshalYAML(value *yaml.Node) error { return nil } -func (o Option[T]) MarshalYAML() (any, error) { +func (o Option[T]) MarshalYAML() (interface{}, error) { if !o.Has() { return nil, nil } diff --git a/routers/api/actions/artifact.pb.go b/routers/api/actions/artifact.pb.go index bbeaef3f10c5b..590eda9fb9a08 100644 --- a/routers/api/actions/artifact.pb.go +++ b/routers/api/actions/artifact.pb.go @@ -866,7 +866,7 @@ func file_artifact_proto_rawDescGZIP() []byte { var ( file_artifact_proto_msgTypes = make([]protoimpl.MessageInfo, 11) - file_artifact_proto_goTypes = []any{ + file_artifact_proto_goTypes = []interface{}{ (*CreateArtifactRequest)(nil), // 0: github.actions.results.api.v1.CreateArtifactRequest (*CreateArtifactResponse)(nil), // 1: github.actions.results.api.v1.CreateArtifactResponse (*FinalizeArtifactRequest)(nil), // 2: github.actions.results.api.v1.FinalizeArtifactRequest @@ -904,7 +904,7 @@ func file_artifact_proto_init() { return } if !protoimpl.UnsafeEnabled { - file_artifact_proto_msgTypes[0].Exporter = func(v any, i int) any { + file_artifact_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*CreateArtifactRequest); i { case 0: return &v.state @@ -916,7 +916,7 @@ func file_artifact_proto_init() { return nil } } - file_artifact_proto_msgTypes[1].Exporter = func(v any, i int) any { + file_artifact_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*CreateArtifactResponse); i { case 0: return &v.state @@ -928,7 +928,7 @@ func file_artifact_proto_init() { return nil } } - file_artifact_proto_msgTypes[2].Exporter = func(v any, i int) any { + file_artifact_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*FinalizeArtifactRequest); i { case 0: return &v.state @@ -940,7 +940,7 @@ func file_artifact_proto_init() { return nil } } - file_artifact_proto_msgTypes[3].Exporter = func(v any, i int) any { + file_artifact_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*FinalizeArtifactResponse); i { case 0: return &v.state @@ -952,7 +952,7 @@ func file_artifact_proto_init() { return nil } } - file_artifact_proto_msgTypes[4].Exporter = func(v any, i int) any { + file_artifact_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ListArtifactsRequest); i { case 0: return &v.state @@ -964,7 +964,7 @@ func file_artifact_proto_init() { return nil } } - file_artifact_proto_msgTypes[5].Exporter = func(v any, i int) any { + file_artifact_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ListArtifactsResponse); i { case 0: return &v.state @@ -976,7 +976,7 @@ func file_artifact_proto_init() { return nil } } - file_artifact_proto_msgTypes[6].Exporter = func(v any, i int) any { + file_artifact_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ListArtifactsResponse_MonolithArtifact); i { case 0: return &v.state @@ -988,7 +988,7 @@ func file_artifact_proto_init() { return nil } } - file_artifact_proto_msgTypes[7].Exporter = func(v any, i int) any { + file_artifact_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*GetSignedArtifactURLRequest); i { case 0: return &v.state @@ -1000,7 +1000,7 @@ func file_artifact_proto_init() { return nil } } - file_artifact_proto_msgTypes[8].Exporter = func(v any, i int) any { + file_artifact_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*GetSignedArtifactURLResponse); i { case 0: return &v.state @@ -1012,7 +1012,7 @@ func file_artifact_proto_init() { return nil } } - file_artifact_proto_msgTypes[9].Exporter = func(v any, i int) any { + file_artifact_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*DeleteArtifactRequest); i { case 0: return &v.state @@ -1024,7 +1024,7 @@ func file_artifact_proto_init() { return nil } } - file_artifact_proto_msgTypes[10].Exporter = func(v any, i int) any { + file_artifact_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*DeleteArtifactResponse); i { case 0: return &v.state diff --git a/services/actions/auth_test.go b/services/actions/auth_test.go index 12db2bae565da..f73ae8ae4c36a 100644 --- a/services/actions/auth_test.go +++ b/services/actions/auth_test.go @@ -20,7 +20,7 @@ func TestCreateAuthorizationToken(t *testing.T) { assert.Nil(t, err) assert.NotEqual(t, "", token) claims := jwt.MapClaims{} - _, err = jwt.ParseWithClaims(token, claims, func(t *jwt.Token) (any, error) { + _, err = jwt.ParseWithClaims(token, claims, func(t *jwt.Token) (interface{}, error) { return setting.GetGeneralTokenSigningSecret(), nil }) assert.Nil(t, err) From 22a11a04a85340b96f1b640e8ea094fe47e93e7b Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 13 Apr 2024 16:11:59 +0200 Subject: [PATCH 05/10] exclude .pb.go --- build/code-batch-process.go | 1 + modules/optional/serialization.go | 2 +- services/actions/auth_test.go | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/build/code-batch-process.go b/build/code-batch-process.go index 6a65a2707b84c..cc2ab680268c9 100644 --- a/build/code-batch-process.go +++ b/build/code-batch-process.go @@ -69,6 +69,7 @@ func newFileCollector(fileFilter string, batchSize int) (*fileCollector, error) co.includePatterns = append(co.includePatterns, regexp.MustCompile(`.*\.go$`)) co.excludePatterns = append(co.excludePatterns, regexp.MustCompile(`.*\bbindata\.go$`)) + co.excludePatterns = append(co.excludePatterns, regexp.MustCompile(`\.pb\.go$`)) co.excludePatterns = append(co.excludePatterns, regexp.MustCompile(`tests/gitea-repositories-meta`)) co.excludePatterns = append(co.excludePatterns, regexp.MustCompile(`tests/integration/migration-test`)) co.excludePatterns = append(co.excludePatterns, regexp.MustCompile(`modules/git/tests`)) diff --git a/modules/optional/serialization.go b/modules/optional/serialization.go index 6688e78cd1812..b120a0edf6b94 100644 --- a/modules/optional/serialization.go +++ b/modules/optional/serialization.go @@ -35,7 +35,7 @@ func (o *Option[T]) UnmarshalYAML(value *yaml.Node) error { return nil } -func (o Option[T]) MarshalYAML() (interface{}, error) { +func (o Option[T]) MarshalYAML() (any, error) { if !o.Has() { return nil, nil } diff --git a/services/actions/auth_test.go b/services/actions/auth_test.go index f73ae8ae4c36a..12db2bae565da 100644 --- a/services/actions/auth_test.go +++ b/services/actions/auth_test.go @@ -20,7 +20,7 @@ func TestCreateAuthorizationToken(t *testing.T) { assert.Nil(t, err) assert.NotEqual(t, "", token) claims := jwt.MapClaims{} - _, err = jwt.ParseWithClaims(token, claims, func(t *jwt.Token) (interface{}, error) { + _, err = jwt.ParseWithClaims(token, claims, func(t *jwt.Token) (any, error) { return setting.GetGeneralTokenSigningSecret(), nil }) assert.Nil(t, err) From bb80e24d1b7de0e707561c66aee7c1115d97909e Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 13 Apr 2024 16:12:40 +0200 Subject: [PATCH 06/10] mark .pb.go as generated --- .gitattributes | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitattributes b/.gitattributes index 467b8a47b5d6d..9fb4a4e83dd71 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,5 +1,6 @@ * text=auto eol=lf *.tmpl linguist-language=Handlebars +*.pb.go linguist-generated /assets/*.json linguist-generated /public/assets/img/svg/*.svg linguist-generated /templates/swagger/v1_json.tmpl linguist-generated From 7f7193db58a2f2afb80728491f7ca05170616118 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 13 Apr 2024 16:15:34 +0200 Subject: [PATCH 07/10] exclude from golangci --- .golangci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.golangci.yml b/.golangci.yml index 27fee20f75ae6..48dda10747862 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -93,6 +93,7 @@ issues: max-issues-per-linter: 0 max-same-issues: 0 exclude-dirs: [node_modules, public, web_src] + exclude-files: ["\\.pb\\.go$"] exclude-rules: # Exclude some linters from running on tests files. - path: _test\.go From e7a8bc469c0c4c922b32e3865464c5ed3aab12cd Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 13 Apr 2024 17:59:31 +0200 Subject: [PATCH 08/10] Update .golangci.yml --- .golangci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 48dda10747862..92b7f54302fe5 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -93,7 +93,7 @@ issues: max-issues-per-linter: 0 max-same-issues: 0 exclude-dirs: [node_modules, public, web_src] - exclude-files: ["\\.pb\\.go$"] + exclude-files: [".*\\.my\\.go$"] exclude-rules: # Exclude some linters from running on tests files. - path: _test\.go From 3df22cc77c5863734f6617967cfd1c824631543d Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 13 Apr 2024 17:59:43 +0200 Subject: [PATCH 09/10] Update .golangci.yml --- .golangci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 92b7f54302fe5..db29fc145e3aa 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -93,7 +93,7 @@ issues: max-issues-per-linter: 0 max-same-issues: 0 exclude-dirs: [node_modules, public, web_src] - exclude-files: [".*\\.my\\.go$"] + exclude-files: [".*\\.pb\\.go$"] exclude-rules: # Exclude some linters from running on tests files. - path: _test\.go From e4cd792dc0e4ce2c34c4a2d357dbfa12c48601e9 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 13 Apr 2024 19:04:19 +0200 Subject: [PATCH 10/10] Update .golangci.yml --- .golangci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index db29fc145e3aa..27fee20f75ae6 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -93,7 +93,6 @@ issues: max-issues-per-linter: 0 max-same-issues: 0 exclude-dirs: [node_modules, public, web_src] - exclude-files: [".*\\.pb\\.go$"] exclude-rules: # Exclude some linters from running on tests files. - path: _test\.go