-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement rename branch API #32433
base: main
Are you sure you want to change the base?
Implement rename branch API #32433
Conversation
Co-authored-by: sillyguodong <[email protected]>
@@ -396,6 +396,95 @@ func ListBranches(ctx *context.APIContext) { | |||
ctx.JSON(http.StatusOK, apiBranches) | |||
} | |||
|
|||
// RenameBranch renames a repository's branch. | |||
func RenameBranch(ctx *context.APIContext) { | |||
// swagger:operation POST /repos/{owner}/{repo}/branches/{name}/rename repository repoRenameBranch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous PR did have unresolved feedback here.
If I understand correctly, the question is if having a branch "test/branch/rename" would cause our http routing to instead look for "test/branch"? If this was the question, this shouldn't be the case. The endpoint would like the following (but URL-encoded):
/api/v1/:owner/:repo/branches/test/branch/rename/rename
So this should be fine. From manually testing with our swagger client, this appears to be case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -1195,6 +1195,7 @@ func Routes() *web.Router { | |||
m.Get("/*", repo.GetBranch) | |||
m.Delete("/*", reqToken(), reqRepoWriter(unit.TypeCode), mustNotBeArchived, repo.DeleteBranch) | |||
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe /*/rename
can work? branch name maybe include /
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I am missing something here, but wouldn't we expect {name}
to be URL-encoded? This makes sense to me as it should avoid the http router from misinterpreting the path segments. The swagger client does URL-encode test/branch/rename when I make a request. Is this not something we expect clients to do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if {name}
is URl-encoded, why not put them into the post key/value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolves #22526.
Builds upon #23061.