refactor: clean up form binding & validation (#38873)

Clarify the "validation" and "error display" logic.

All the copied&pasted `Validate` functions are removed.
This commit is contained in:
wxiaoguang
2026-08-14 10:15:33 +08:00
committed by GitHub
parent 8b40df255b
commit 72a9debaff
30 changed files with 331 additions and 737 deletions
+5 -10
View File
@@ -4,16 +4,12 @@
package forms
import (
"net/http"
"gitea.dev/modules/optional"
"gitea.dev/modules/web/middleware"
"gitea.dev/services/context"
"gitea.com/go-chi/binding"
)
type CommitCommonForm struct {
middleware.FormDefaultValidator
TreePath string `binding:"MaxSize(500)"`
CommitSummary string `binding:"MaxSize(100)"`
CommitMessage string
@@ -24,11 +20,6 @@ type CommitCommonForm struct {
CommitEmail string
}
func (f *CommitCommonForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
ctx := context.GetValidateContext(req)
return middleware.Validate(ctx, errs, f)
}
type CommitCommonFormInterface interface {
GetCommitCommonForm() *CommitCommonForm
}
@@ -38,20 +29,24 @@ func (f *CommitCommonForm) GetCommitCommonForm() *CommitCommonForm {
}
type EditRepoFileForm struct {
middleware.FormDefaultValidator
CommitCommonForm
Content optional.Option[string]
}
type DeleteRepoFileForm struct {
middleware.FormDefaultValidator
CommitCommonForm
}
type UploadRepoFileForm struct {
middleware.FormDefaultValidator
CommitCommonForm
Files []string
}
type CherryPickForm struct {
middleware.FormDefaultValidator
CommitCommonForm
Revert bool
}