summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorAravinth Manivannan <realaravinth@batsense.net>2021-12-24 14:43:00 +0000
committerGitHub <noreply@github.com>2021-12-24 22:43:00 +0800
commitc7151c2fb6c91d6d3263af3e8baac73fbeaecbbc (patch)
treec5eeef2e3d65c0e7db046cc28d013b9de39955b3 /routers
parent532383d7ddca2eeed37d2af20cd91f2824fc9cc7 (diff)
downloadgitea-c7151c2fb6c91d6d3263af3e8baac73fbeaecbbc.tar.gz
gitea-c7151c2fb6c91d6d3263af3e8baac73fbeaecbbc.zip
- name: new parameter in CreateForkOption to give the forked repository (#18066)
a custom name, intended to be used when there's a name conflict - When a fork request results in a name conflict, HTTP 409: Conflict is returned instead of 500 - API documentation for the above mentioned changes Signed-off-by: realaravinth <realaravinth@batsense.net> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/repo/fork.go17
1 files changed, 15 insertions, 2 deletions
diff --git a/routers/api/v1/repo/fork.go b/routers/api/v1/repo/fork.go
index 542af60741..b0ba5db253 100644
--- a/routers/api/v1/repo/fork.go
+++ b/routers/api/v1/repo/fork.go
@@ -97,6 +97,8 @@ func CreateFork(ctx *context.APIContext) {
// "$ref": "#/responses/Repository"
// "403":
// "$ref": "#/responses/forbidden"
+ // "409":
+ // description: The repository with the same name already exists.
// "422":
// "$ref": "#/responses/validationError"
@@ -126,13 +128,24 @@ func CreateFork(ctx *context.APIContext) {
forker = org.AsUser()
}
+ var name string
+ if form.Name == nil {
+ name = repo.Name
+ } else {
+ name = *form.Name
+ }
+
fork, err := repo_service.ForkRepository(ctx.User, forker, repo_service.ForkRepoOptions{
BaseRepo: repo,
- Name: repo.Name,
+ Name: name,
Description: repo.Description,
})
if err != nil {
- ctx.Error(http.StatusInternalServerError, "ForkRepository", err)
+ if repo_model.IsErrRepoAlreadyExist(err) {
+ ctx.Error(http.StatusConflict, "ForkRepository", err)
+ } else {
+ ctx.Error(http.StatusInternalServerError, "ForkRepository", err)
+ }
return
}