Skip to content

Commit df520a9

Browse files
committed
- name: new parameter in CreateForkOption to give the forked repository
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>
1 parent 7821370 commit df520a9

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

modules/structs/fork.go

+2
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ package structs
88
type CreateForkOption struct {
99
// organization name, if forking into an organization
1010
Organization *string `json:"organization"`
11+
// name of the forked repository
12+
Name *string `json:"name"`
1113
}

routers/api/v1/repo/fork.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ func CreateFork(ctx *context.APIContext) {
9797
// "$ref": "#/responses/Repository"
9898
// "403":
9999
// "$ref": "#/responses/forbidden"
100+
// "409":
101+
// description: The repository with the same name already exists.
100102
// "422":
101103
// "$ref": "#/responses/validationError"
102104

@@ -126,13 +128,24 @@ func CreateFork(ctx *context.APIContext) {
126128
forker = org.AsUser()
127129
}
128130

131+
var name string
132+
if form.Name == nil {
133+
name = repo.Name
134+
} else {
135+
name = *form.Name
136+
}
137+
129138
fork, err := repo_service.ForkRepository(ctx.User, forker, repo_service.ForkRepoOptions{
130139
BaseRepo: repo,
131-
Name: repo.Name,
140+
Name: name,
132141
Description: repo.Description,
133142
})
134143
if err != nil {
135-
ctx.Error(http.StatusInternalServerError, "ForkRepository", err)
144+
if repo_model.IsErrRepoAlreadyExist(err) {
145+
ctx.Error(http.StatusConflict, "ForkRepository", err)
146+
} else {
147+
ctx.Error(http.StatusInternalServerError, "ForkRepository", err)
148+
}
136149
return
137150
}
138151

templates/swagger/v1_json.tmpl

+8
Original file line numberDiff line numberDiff line change
@@ -3503,6 +3503,9 @@
35033503
"403": {
35043504
"$ref": "#/responses/forbidden"
35053505
},
3506+
"409": {
3507+
"description": "The repository with the same name already exists."
3508+
},
35063509
"422": {
35073510
"$ref": "#/responses/validationError"
35083511
}
@@ -13292,6 +13295,11 @@
1329213295
"description": "CreateForkOption options for creating a fork",
1329313296
"type": "object",
1329413297
"properties": {
13298+
"name": {
13299+
"description": "name of the forked repository",
13300+
"type": "string",
13301+
"x-go-name": "Name"
13302+
},
1329513303
"organization": {
1329613304
"description": "organization name, if forking into an organization",
1329713305
"type": "string",

0 commit comments

Comments
 (0)