mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 02:46:04 +01:00 
			
		
		
		
	- 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>
This commit is contained in:
		
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							532383d7dd
						
					
				
				
					commit
					c7151c2fb6
				
			| @@ -8,4 +8,6 @@ package structs | |||||||
| type CreateForkOption struct { | type CreateForkOption struct { | ||||||
| 	// organization name, if forking into an organization | 	// organization name, if forking into an organization | ||||||
| 	Organization *string `json:"organization"` | 	Organization *string `json:"organization"` | ||||||
|  | 	// name of the forked repository | ||||||
|  | 	Name *string `json:"name"` | ||||||
| } | } | ||||||
|   | |||||||
| @@ -97,6 +97,8 @@ func CreateFork(ctx *context.APIContext) { | |||||||
| 	//     "$ref": "#/responses/Repository" | 	//     "$ref": "#/responses/Repository" | ||||||
| 	//   "403": | 	//   "403": | ||||||
| 	//     "$ref": "#/responses/forbidden" | 	//     "$ref": "#/responses/forbidden" | ||||||
|  | 	//   "409": | ||||||
|  | 	//     description: The repository with the same name already exists. | ||||||
| 	//   "422": | 	//   "422": | ||||||
| 	//     "$ref": "#/responses/validationError" | 	//     "$ref": "#/responses/validationError" | ||||||
|  |  | ||||||
| @@ -126,13 +128,24 @@ func CreateFork(ctx *context.APIContext) { | |||||||
| 		forker = org.AsUser() | 		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{ | 	fork, err := repo_service.ForkRepository(ctx.User, forker, repo_service.ForkRepoOptions{ | ||||||
| 		BaseRepo:    repo, | 		BaseRepo:    repo, | ||||||
| 		Name:        repo.Name, | 		Name:        name, | ||||||
| 		Description: repo.Description, | 		Description: repo.Description, | ||||||
| 	}) | 	}) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
|  | 		if repo_model.IsErrRepoAlreadyExist(err) { | ||||||
|  | 			ctx.Error(http.StatusConflict, "ForkRepository", err) | ||||||
|  | 		} else { | ||||||
| 			ctx.Error(http.StatusInternalServerError, "ForkRepository", err) | 			ctx.Error(http.StatusInternalServerError, "ForkRepository", err) | ||||||
|  | 		} | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -3509,6 +3509,9 @@ | |||||||
|           "403": { |           "403": { | ||||||
|             "$ref": "#/responses/forbidden" |             "$ref": "#/responses/forbidden" | ||||||
|           }, |           }, | ||||||
|  |           "409": { | ||||||
|  |             "description": "The repository with the same name already exists." | ||||||
|  |           }, | ||||||
|           "422": { |           "422": { | ||||||
|             "$ref": "#/responses/validationError" |             "$ref": "#/responses/validationError" | ||||||
|           } |           } | ||||||
| @@ -13376,6 +13379,11 @@ | |||||||
|       "description": "CreateForkOption options for creating a fork", |       "description": "CreateForkOption options for creating a fork", | ||||||
|       "type": "object", |       "type": "object", | ||||||
|       "properties": { |       "properties": { | ||||||
|  |         "name": { | ||||||
|  |           "description": "name of the forked repository", | ||||||
|  |           "type": "string", | ||||||
|  |           "x-go-name": "Name" | ||||||
|  |         }, | ||||||
|         "organization": { |         "organization": { | ||||||
|           "description": "organization name, if forking into an organization", |           "description": "organization name, if forking into an organization", | ||||||
|           "type": "string", |           "type": "string", | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user