Skip to content

Commit 36829ec

Browse files
committed
Move old branch name to request body
1 parent a2c26d0 commit 36829ec

File tree

5 files changed

+56
-55
lines changed

5 files changed

+56
-55
lines changed

modules/structs/repo.go

+5
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,11 @@ type CreateBranchRepoOption struct {
281281
// RenameBranchOption options when rename a branch in a repository
282282
// swagger:model
283283
type RenameBranchRepoOption struct {
284+
// Old branch name
285+
//
286+
// required: true
287+
// unique: true
288+
OldName string `json:"old_name" binding:"Required;GitRefName;MaxSize(100)"`
284289
// New branch name
285290
//
286291
// required: true

routers/api/v1/api.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ func Routes() *web.Router {
11951195
m.Get("/*", repo.GetBranch)
11961196
m.Delete("/*", reqToken(), reqRepoWriter(unit.TypeCode), mustNotBeArchived, repo.DeleteBranch)
11971197
m.Post("", reqToken(), reqRepoWriter(unit.TypeCode), mustNotBeArchived, bind(api.CreateBranchRepoOption{}), repo.CreateBranch)
1198-
m.Post("/{name}/rename", tokenRequiresScopes(auth_model.AccessTokenScopeCategoryRepository), reqRepoWriter(unit.TypeCode), bind(api.RenameBranchRepoOption{}), repo.RenameBranch)
1198+
m.Post("/rename", tokenRequiresScopes(auth_model.AccessTokenScopeCategoryRepository), reqRepoWriter(unit.TypeCode), bind(api.RenameBranchRepoOption{}), repo.RenameBranch)
11991199
}, context.ReferencesGitRepo(), reqRepoReader(unit.TypeCode))
12001200
m.Group("/branch_protections", func() {
12011201
m.Get("", repo.ListBranchProtections)

routers/api/v1/repo/branch.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ func ListBranches(ctx *context.APIContext) {
398398

399399
// RenameBranch renames a repository's branch.
400400
func RenameBranch(ctx *context.APIContext) {
401-
// swagger:operation POST /repos/{owner}/{repo}/branches/{name}/rename repository repoRenameBranch
401+
// swagger:operation POST /repos/{owner}/{repo}/branches/rename repository repoRenameBranch
402402
// ---
403403
// summary: Rename a branch
404404
// consumes:
@@ -416,11 +416,6 @@ func RenameBranch(ctx *context.APIContext) {
416416
// description: name of the repo
417417
// type: string
418418
// required: true
419-
// - name: name
420-
// in: path
421-
// description: original name of the branch
422-
// type: string
423-
// required: true
424419
// - name: body
425420
// in: body
426421
// schema:
@@ -448,7 +443,7 @@ func RenameBranch(ctx *context.APIContext) {
448443
return
449444
}
450445

451-
msg, err := repo_service.RenameBranch(ctx, repo, ctx.Doer, ctx.Repo.GitRepo, ctx.PathParam("name"), opt.NewName)
446+
msg, err := repo_service.RenameBranch(ctx, repo, ctx.Doer, ctx.Repo.GitRepo, opt.OldName, opt.NewName)
452447
if err != nil {
453448
ctx.Error(http.StatusInternalServerError, "RenameBranch", err)
454449
return

templates/swagger/v1_json.tmpl

+46-46
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integration/api_branch_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ func TestAPIRenameBranch(t *testing.T) {
207207

208208
func testAPIRenameBranch(t *testing.T, ownerName, repoName, from, to string, expectedHTTPStatus int) {
209209
token := getUserToken(t, ownerName, auth_model.AccessTokenScopeWriteRepository)
210-
req := NewRequestWithJSON(t, "POST", "api/v1/repos/"+ownerName+"/"+repoName+"/branches/"+from+"/rename", &api.RenameBranchRepoOption{
210+
req := NewRequestWithJSON(t, "POST", "api/v1/repos/"+ownerName+"/"+repoName+"/branches/rename", &api.RenameBranchRepoOption{
211+
OldName: from,
211212
NewName: to,
212213
}).AddTokenAuth(token)
213214
MakeRequest(t, req, expectedHTTPStatus)

0 commit comments

Comments
 (0)