mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-14 10:57:54 +02:00
Add validation constraints for repository creation fields (#36671)
Adds validation constraints to repository creation inputs, enforcing max-length limits for labels/license/readme and enum validation for trust model and object format. Updates both the API option struct and the web form struct to keep validation consistent.
This commit is contained in:
parent
577ed107dd
commit
569c49debe
@ -135,7 +135,7 @@ type CreateRepoOption struct {
|
|||||||
// Whether the repository is private
|
// Whether the repository is private
|
||||||
Private bool `json:"private"`
|
Private bool `json:"private"`
|
||||||
// Label-Set to use
|
// Label-Set to use
|
||||||
IssueLabels string `json:"issue_labels"`
|
IssueLabels string `json:"issue_labels" binding:"MaxSize(255)"`
|
||||||
// Whether the repository should be auto-initialized?
|
// Whether the repository should be auto-initialized?
|
||||||
AutoInit bool `json:"auto_init"`
|
AutoInit bool `json:"auto_init"`
|
||||||
// Whether the repository is template
|
// Whether the repository is template
|
||||||
@ -143,15 +143,15 @@ type CreateRepoOption struct {
|
|||||||
// Gitignores to use
|
// Gitignores to use
|
||||||
Gitignores string `json:"gitignores"`
|
Gitignores string `json:"gitignores"`
|
||||||
// License to use
|
// License to use
|
||||||
License string `json:"license"`
|
License string `json:"license" binding:"MaxSize(100)"`
|
||||||
// Readme of the repository to create
|
// Readme of the repository to create
|
||||||
Readme string `json:"readme"`
|
Readme string `json:"readme" binding:"MaxSize(255)"`
|
||||||
// DefaultBranch of the repository (used when initializes and in template)
|
// DefaultBranch of the repository (used when initializes and in template)
|
||||||
DefaultBranch string `json:"default_branch" binding:"GitRefName;MaxSize(100)"`
|
DefaultBranch string `json:"default_branch" binding:"GitRefName;MaxSize(100)"`
|
||||||
// TrustModel of the repository
|
// TrustModel of the repository
|
||||||
// enum: default,collaborator,committer,collaboratorcommitter
|
// enum: default,collaborator,committer,collaboratorcommitter
|
||||||
TrustModel string `json:"trust_model"`
|
TrustModel string `json:"trust_model"`
|
||||||
// ObjectFormatName of the underlying git repository
|
// ObjectFormatName of the underlying git repository, empty string for default (sha1)
|
||||||
// enum: sha1,sha256
|
// enum: sha1,sha256
|
||||||
ObjectFormatName string `json:"object_format_name" binding:"MaxSize(6)"`
|
ObjectFormatName string `json:"object_format_name" binding:"MaxSize(6)"`
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,9 +27,9 @@ type CreateRepoForm struct {
|
|||||||
DefaultBranch string `binding:"GitRefName;MaxSize(100)"`
|
DefaultBranch string `binding:"GitRefName;MaxSize(100)"`
|
||||||
AutoInit bool
|
AutoInit bool
|
||||||
Gitignores string
|
Gitignores string
|
||||||
IssueLabels string
|
IssueLabels string `binding:"MaxSize(255)"`
|
||||||
License string
|
License string `binding:"MaxSize(100)"`
|
||||||
Readme string
|
Readme string `binding:"MaxSize(255)"`
|
||||||
Template bool
|
Template bool
|
||||||
|
|
||||||
RepoTemplate int64
|
RepoTemplate int64
|
||||||
@ -41,7 +41,7 @@ type CreateRepoForm struct {
|
|||||||
Labels bool
|
Labels bool
|
||||||
ProtectedBranch bool
|
ProtectedBranch bool
|
||||||
|
|
||||||
ForkSingleBranch string
|
ForkSingleBranch string `binding:"MaxSize(255)"`
|
||||||
ObjectFormatName string
|
ObjectFormatName string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -230,6 +230,9 @@ func CreateRepositoryDirectly(ctx context.Context, doer, owner *user_model.User,
|
|||||||
if opts.ObjectFormatName == "" {
|
if opts.ObjectFormatName == "" {
|
||||||
opts.ObjectFormatName = git.Sha1ObjectFormat.Name()
|
opts.ObjectFormatName = git.Sha1ObjectFormat.Name()
|
||||||
}
|
}
|
||||||
|
if opts.ObjectFormatName != git.Sha1ObjectFormat.Name() && opts.ObjectFormatName != git.Sha256ObjectFormat.Name() {
|
||||||
|
return nil, fmt.Errorf("unsupported object format: %s", opts.ObjectFormatName)
|
||||||
|
}
|
||||||
|
|
||||||
repo := &repo_model.Repository{
|
repo := &repo_model.Repository{
|
||||||
OwnerID: owner.ID,
|
OwnerID: owner.ID,
|
||||||
|
|||||||
2
templates/swagger/v1_json.tmpl
generated
2
templates/swagger/v1_json.tmpl
generated
@ -23780,7 +23780,7 @@
|
|||||||
"x-go-name": "Name"
|
"x-go-name": "Name"
|
||||||
},
|
},
|
||||||
"object_format_name": {
|
"object_format_name": {
|
||||||
"description": "ObjectFormatName of the underlying git repository",
|
"description": "ObjectFormatName of the underlying git repository, empty string for default (sha1)",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": [
|
"enum": [
|
||||||
"sha1",
|
"sha1",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user