Browse Source

fix bug:error happens when create repo by api

pull/1489/head
Gitea 3 years ago
parent
commit
29a77cdcf8
4 changed files with 11 additions and 0 deletions
  1. +3
    -0
      models/repo.go
  2. +4
    -0
      modules/structs/repo.go
  3. +3
    -0
      modules/validation/binding.go
  4. +1
    -0
      routers/api/v1/repo/repo.go

+ 3
- 0
models/repo.go View File

@@ -1133,6 +1133,9 @@ func IsUsableRepoAlias(name string) error {

// CreateRepository creates a repository for the user/organization.
func CreateRepository(ctx DBContext, doer, u *User, repo *Repository, opts ...CreateRepoOptions) (err error) {
if repo.Alias == "" {
repo.Alias = repo.Name
}
repo.LowerAlias = strings.ToLower(repo.Alias)
if err = IsUsableRepoName(repo.Name); err != nil {
return err


+ 4
- 0
modules/structs/repo.go View File

@@ -100,6 +100,10 @@ type CreateRepoOption struct {
// required: true
// unique: true
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(100)"`
// Alias of the repository to create
// required: false
// unique: true
Alias string `json:"alias" binding:"AlphaDashDotChinese;MaxSize(100)"`
// Description of the repository to create
Description string `json:"description" binding:"MaxSize(255)"`
// Whether the repository is private


+ 3
- 0
modules/validation/binding.go View File

@@ -128,6 +128,9 @@ func addAlphaDashDotChineseRule() {
return strings.HasPrefix(rule, "AlphaDashDotChinese")
},
IsValid: func(errs binding.Errors, name string, val interface{}) (bool, binding.Errors) {
if val == "" {
return true, errs
}
if !ValidAlphaDashDotChinese(fmt.Sprintf("%v", val)) {
errs.Add([]string{name}, ErrAlphaDashDotChinese, "ErrAlphaDashDotChinese")
return false, errs


+ 1
- 0
routers/api/v1/repo/repo.go View File

@@ -232,6 +232,7 @@ func CreateUserRepo(ctx *context.APIContext, owner *models.User, opt api.CreateR
}
repo, err := repo_service.CreateRepository(ctx.User, owner, models.CreateRepoOptions{
Name: opt.Name,
Alias: opt.Alias,
Description: opt.Description,
IssueLabels: opt.IssueLabels,
Gitignores: opt.Gitignores,


Loading…
Cancel
Save