mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-23 09:30:50 +00:00
Add option to update pull request by rebase
(#16125)
* add option to update pull request by `rebase` Signed-off-by: a1012112796 <1012112796@qq.com>
This commit is contained in:
parent
2bb32006fd
commit
cbf05c3f79
10 changed files with 184 additions and 26 deletions
|
@ -1065,6 +1065,11 @@ func UpdatePullRequest(ctx *context.APIContext) {
|
|||
// type: integer
|
||||
// format: int64
|
||||
// required: true
|
||||
// - name: style
|
||||
// in: query
|
||||
// description: how to update pull request
|
||||
// type: string
|
||||
// enum: [merge, rebase]
|
||||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/empty"
|
||||
|
@ -1111,13 +1116,15 @@ func UpdatePullRequest(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
allowedUpdate, err := pull_service.IsUserAllowedToUpdate(pr, ctx.User)
|
||||
rebase := ctx.FormString("style") == "rebase"
|
||||
|
||||
allowedUpdateByMerge, allowedUpdateByRebase, err := pull_service.IsUserAllowedToUpdate(pr, ctx.User)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "IsUserAllowedToMerge", err)
|
||||
return
|
||||
}
|
||||
|
||||
if !allowedUpdate {
|
||||
if (!allowedUpdateByMerge && !rebase) || (rebase && !allowedUpdateByRebase) {
|
||||
ctx.Status(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
@ -1125,7 +1132,7 @@ func UpdatePullRequest(ctx *context.APIContext) {
|
|||
// default merge commit message
|
||||
message := fmt.Sprintf("Merge branch '%s' into %s", pr.BaseBranch, pr.HeadBranch)
|
||||
|
||||
if err = pull_service.Update(pr, ctx.User, message); err != nil {
|
||||
if err = pull_service.Update(pr, ctx.User, message, rebase); err != nil {
|
||||
if models.IsErrMergeConflicts(err) {
|
||||
ctx.Error(http.StatusConflict, "Update", "merge failed because of conflict")
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue