0
0
Fork 0
mirror of https://github.com/go-gitea/gitea synced 2024-11-28 12:52:47 +01:00

Move old branch name to request body

This commit is contained in:
Kemal Zebari 2024-11-16 17:20:09 -08:00
parent a2c26d01c6
commit 36829ec14b
5 changed files with 69 additions and 68 deletions

View file

@ -281,6 +281,11 @@ type CreateBranchRepoOption struct {
// RenameBranchOption options when rename a branch in a repository // RenameBranchOption options when rename a branch in a repository
// swagger:model // swagger:model
type RenameBranchRepoOption struct { type RenameBranchRepoOption struct {
// Old branch name
//
// required: true
// unique: true
OldName string `json:"old_name" binding:"Required;GitRefName;MaxSize(100)"`
// New branch name // New branch name
// //
// required: true // required: true

View file

@ -1195,7 +1195,7 @@ func Routes() *web.Router {
m.Get("/*", repo.GetBranch) m.Get("/*", repo.GetBranch)
m.Delete("/*", reqToken(), reqRepoWriter(unit.TypeCode), mustNotBeArchived, repo.DeleteBranch) m.Delete("/*", reqToken(), reqRepoWriter(unit.TypeCode), mustNotBeArchived, repo.DeleteBranch)
m.Post("", reqToken(), reqRepoWriter(unit.TypeCode), mustNotBeArchived, bind(api.CreateBranchRepoOption{}), repo.CreateBranch) m.Post("", reqToken(), reqRepoWriter(unit.TypeCode), mustNotBeArchived, bind(api.CreateBranchRepoOption{}), repo.CreateBranch)
m.Post("/{name}/rename", tokenRequiresScopes(auth_model.AccessTokenScopeCategoryRepository), reqRepoWriter(unit.TypeCode), bind(api.RenameBranchRepoOption{}), repo.RenameBranch) m.Post("/rename", tokenRequiresScopes(auth_model.AccessTokenScopeCategoryRepository), reqRepoWriter(unit.TypeCode), bind(api.RenameBranchRepoOption{}), repo.RenameBranch)
}, context.ReferencesGitRepo(), reqRepoReader(unit.TypeCode)) }, context.ReferencesGitRepo(), reqRepoReader(unit.TypeCode))
m.Group("/branch_protections", func() { m.Group("/branch_protections", func() {
m.Get("", repo.ListBranchProtections) m.Get("", repo.ListBranchProtections)

View file

@ -398,7 +398,7 @@ func ListBranches(ctx *context.APIContext) {
// RenameBranch renames a repository's branch. // RenameBranch renames a repository's branch.
func RenameBranch(ctx *context.APIContext) { func RenameBranch(ctx *context.APIContext) {
// swagger:operation POST /repos/{owner}/{repo}/branches/{name}/rename repository repoRenameBranch // swagger:operation POST /repos/{owner}/{repo}/branches/rename repository repoRenameBranch
// --- // ---
// summary: Rename a branch // summary: Rename a branch
// consumes: // consumes:
@ -416,11 +416,6 @@ func RenameBranch(ctx *context.APIContext) {
// description: name of the repo // description: name of the repo
// type: string // type: string
// required: true // required: true
// - name: name
// in: path
// description: original name of the branch
// type: string
// required: true
// - name: body // - name: body
// in: body // in: body
// schema: // schema:
@ -448,7 +443,7 @@ func RenameBranch(ctx *context.APIContext) {
return return
} }
msg, err := repo_service.RenameBranch(ctx, repo, ctx.Doer, ctx.Repo.GitRepo, ctx.PathParam("name"), opt.NewName) msg, err := repo_service.RenameBranch(ctx, repo, ctx.Doer, ctx.Repo.GitRepo, opt.OldName, opt.NewName)
if err != nil { if err != nil {
ctx.Error(http.StatusInternalServerError, "RenameBranch", err) ctx.Error(http.StatusInternalServerError, "RenameBranch", err)
return return

View file

@ -4905,6 +4905,58 @@
} }
} }
}, },
"/repos/{owner}/{repo}/branches/rename": {
"post": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"repository"
],
"summary": "Rename a branch",
"operationId": "repoRenameBranch",
"parameters": [
{
"type": "string",
"description": "owner of the repo",
"name": "owner",
"in": "path",
"required": true
},
{
"type": "string",
"description": "name of the repo",
"name": "repo",
"in": "path",
"required": true
},
{
"name": "body",
"in": "body",
"schema": {
"$ref": "#/definitions/RenameBranchRepoOption"
}
}
],
"responses": {
"201": {
"$ref": "#/responses/Branch"
},
"403": {
"$ref": "#/responses/forbidden"
},
"404": {
"$ref": "#/responses/notFound"
},
"422": {
"$ref": "#/responses/validationError"
}
}
}
},
"/repos/{owner}/{repo}/branches/{branch}": { "/repos/{owner}/{repo}/branches/{branch}": {
"get": { "get": {
"produces": [ "produces": [
@ -4995,65 +5047,6 @@
} }
} }
}, },
"/repos/{owner}/{repo}/branches/{name}/rename": {
"post": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"repository"
],
"summary": "Rename a branch",
"operationId": "repoRenameBranch",
"parameters": [
{
"type": "string",
"description": "owner of the repo",
"name": "owner",
"in": "path",
"required": true
},
{
"type": "string",
"description": "name of the repo",
"name": "repo",
"in": "path",
"required": true
},
{
"type": "string",
"description": "original name of the branch",
"name": "name",
"in": "path",
"required": true
},
{
"name": "body",
"in": "body",
"schema": {
"$ref": "#/definitions/RenameBranchRepoOption"
}
}
],
"responses": {
"201": {
"$ref": "#/responses/Branch"
},
"403": {
"$ref": "#/responses/forbidden"
},
"404": {
"$ref": "#/responses/notFound"
},
"422": {
"$ref": "#/responses/validationError"
}
}
}
},
"/repos/{owner}/{repo}/collaborators": { "/repos/{owner}/{repo}/collaborators": {
"get": { "get": {
"produces": [ "produces": [
@ -24068,6 +24061,7 @@
"description": "RenameBranchOption options when rename a branch in a repository", "description": "RenameBranchOption options when rename a branch in a repository",
"type": "object", "type": "object",
"required": [ "required": [
"old_name",
"new_name" "new_name"
], ],
"properties": { "properties": {
@ -24076,6 +24070,12 @@
"type": "string", "type": "string",
"uniqueItems": true, "uniqueItems": true,
"x-go-name": "NewName" "x-go-name": "NewName"
},
"old_name": {
"description": "Old branch name",
"type": "string",
"uniqueItems": true,
"x-go-name": "OldName"
} }
}, },
"x-go-package": "code.gitea.io/gitea/modules/structs" "x-go-package": "code.gitea.io/gitea/modules/structs"

View file

@ -207,7 +207,8 @@ func TestAPIRenameBranch(t *testing.T) {
func testAPIRenameBranch(t *testing.T, ownerName, repoName, from, to string, expectedHTTPStatus int) { func testAPIRenameBranch(t *testing.T, ownerName, repoName, from, to string, expectedHTTPStatus int) {
token := getUserToken(t, ownerName, auth_model.AccessTokenScopeWriteRepository) token := getUserToken(t, ownerName, auth_model.AccessTokenScopeWriteRepository)
req := NewRequestWithJSON(t, "POST", "api/v1/repos/"+ownerName+"/"+repoName+"/branches/"+from+"/rename", &api.RenameBranchRepoOption{ req := NewRequestWithJSON(t, "POST", "api/v1/repos/"+ownerName+"/"+repoName+"/branches/rename", &api.RenameBranchRepoOption{
OldName: from,
NewName: to, NewName: to,
}).AddTokenAuth(token) }).AddTokenAuth(token)
MakeRequest(t, req, expectedHTTPStatus) MakeRequest(t, req, expectedHTTPStatus)