Skip to content

Commit 591580a

Browse files
committed
Move old branch name to request body
1 parent d8dbf6a commit 591580a

File tree

5 files changed

+56
-55
lines changed

5 files changed

+56
-55
lines changed

modules/structs/repo.go

Lines changed: 5 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ func ListBranches(ctx *context.APIContext) {
388388

389389
// RenameBranch renames a repository's branch.
390390
func RenameBranch(ctx *context.APIContext) {
391-
// swagger:operation POST /repos/{owner}/{repo}/branches/{name}/rename repository repoRenameBranch
391+
// swagger:operation POST /repos/{owner}/{repo}/branches/rename repository repoRenameBranch
392392
// ---
393393
// summary: Rename a branch
394394
// consumes:
@@ -406,11 +406,6 @@ func RenameBranch(ctx *context.APIContext) {
406406
// description: name of the repo
407407
// type: string
408408
// required: true
409-
// - name: name
410-
// in: path
411-
// description: original name of the branch
412-
// type: string
413-
// required: true
414409
// - name: body
415410
// in: body
416411
// schema:
@@ -438,7 +433,7 @@ func RenameBranch(ctx *context.APIContext) {
438433
return
439434
}
440435

441-
msg, err := repo_service.RenameBranch(ctx, repo, ctx.Doer, ctx.Repo.GitRepo, ctx.PathParam("name"), opt.NewName)
436+
msg, err := repo_service.RenameBranch(ctx, repo, ctx.Doer, ctx.Repo.GitRepo, opt.OldName, opt.NewName)
442437
if err != nil {
443438
ctx.Error(http.StatusInternalServerError, "RenameBranch", err)
444439
return

templates/swagger/v1_json.tmpl

Lines changed: 46 additions & 46 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integration/api_branch_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ func TestAPIRenameBranch(t *testing.T) {
208208

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

0 commit comments

Comments
 (0)