Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle missing README in create repos API #23387

Merged
merged 4 commits into from Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions routers/api/v1/admin/repo.go
Expand Up @@ -32,6 +32,8 @@ func CreateRepo(ctx *context.APIContext) {
// responses:
// "201":
// "$ref": "#/responses/Repository"
// "400":
// "$ref": "#/responses/error"
// "403":
// "$ref": "#/responses/forbidden"
// "404":
Expand Down
11 changes: 11 additions & 0 deletions routers/api/v1/repo/repo.go
Expand Up @@ -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,
Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -464,6 +473,8 @@ func CreateOrgRepo(ctx *context.APIContext) {
// responses:
// "201":
// "$ref": "#/responses/Repository"
// "400":
// "$ref": "#/responses/error"
// "404":
// "$ref": "#/responses/notFound"
// "403":
Expand Down
9 changes: 9 additions & 0 deletions templates/swagger/v1_json.tmpl
Expand Up @@ -707,6 +707,9 @@
"201": {
"$ref": "#/responses/Repository"
},
"400": {
"$ref": "#/responses/error"
},
"403": {
"$ref": "#/responses/forbidden"
},
Expand Down Expand Up @@ -1920,6 +1923,9 @@
"201": {
"$ref": "#/responses/Repository"
},
"400": {
"$ref": "#/responses/error"
},
"403": {
"$ref": "#/responses/forbidden"
},
Expand Down Expand Up @@ -13229,6 +13235,9 @@
"201": {
"$ref": "#/responses/Repository"
},
"400": {
"$ref": "#/responses/error"
},
"409": {
"description": "The repository with the same name already exists."
},
Expand Down