diff options
Diffstat (limited to 'routers/api/v1')
-rw-r--r-- | routers/api/v1/admin/repo.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/repo.go | 11 |
2 files changed, 13 insertions, 0 deletions
diff --git a/routers/api/v1/admin/repo.go b/routers/api/v1/admin/repo.go index 83ed06e49b..a4895f260b 100644 --- a/routers/api/v1/admin/repo.go +++ b/routers/api/v1/admin/repo.go @@ -32,6 +32,8 @@ func CreateRepo(ctx *context.APIContext) { // responses: // "201": // "$ref": "#/responses/Repository" + // "400": + // "$ref": "#/responses/error" // "403": // "$ref": "#/responses/forbidden" // "404": diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index 397600dc50..16608e5bbb 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -231,6 +231,13 @@ func CreateUserRepo(ctx *context.APIContext, owner *user_model.User, opt api.Cre if opt.AutoInit && opt.Readme == "" { opt.Readme = "Default" } + + // If the readme template does not exist, a 400 will be returned. + if opt.AutoInit && len(opt.Readme) > 0 && !util.SliceContains(repo_module.Readmes, opt.Readme) { + ctx.Error(http.StatusBadRequest, "", fmt.Errorf("readme template does not exist, available templates: %v", repo_module.Readmes)) + return + } + repo, err := repo_service.CreateRepository(ctx, ctx.Doer, owner, repo_module.CreateRepoOptions{ Name: opt.Name, Description: opt.Description, @@ -283,6 +290,8 @@ func Create(ctx *context.APIContext) { // responses: // "201": // "$ref": "#/responses/Repository" + // "400": + // "$ref": "#/responses/error" // "409": // description: The repository with the same name already exists. // "422": @@ -464,6 +473,8 @@ func CreateOrgRepo(ctx *context.APIContext) { // responses: // "201": // "$ref": "#/responses/Repository" + // "400": + // "$ref": "#/responses/error" // "404": // "$ref": "#/responses/notFound" // "403": |