Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions modules/structs/fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ package structs
type CreateForkOption struct {
// organization name, if forking into an organization
Organization *string `json:"organization"`
// name of the forked repository
Name *string `json:"name"`
}
17 changes: 15 additions & 2 deletions routers/api/v1/repo/fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
}

Expand Down
8 changes: 8 additions & 0 deletions templates/swagger/v1_json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3503,6 +3503,9 @@
"403": {
"$ref": "#/responses/forbidden"
},
"409": {
"description": "The repository with the same name already exists."
},
"422": {
"$ref": "#/responses/validationError"
}
Expand Down Expand Up @@ -13292,6 +13295,11 @@
"description": "CreateForkOption options for creating a fork",
"type": "object",
"properties": {
"name": {
"description": "name of the forked repository",
"type": "string",
"x-go-name": "Name"
},
"organization": {
"description": "organization name, if forking into an organization",
"type": "string",
Expand Down