diff options
author | a1012112796 <1012112796@qq.com> | 2021-08-31 22:03:45 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-31 16:03:45 +0200 |
commit | cbf05c3f795c1eed999dafe8d0757495e07f1ee2 (patch) | |
tree | e9b227ef8dd8d836b04bd126806c8a1264b750ee /routers | |
parent | 2bb32006fd560af44426a06f63f83e3c70c3f258 (diff) | |
download | gitea-cbf05c3f795c1eed999dafe8d0757495e07f1ee2.tar.gz gitea-cbf05c3f795c1eed999dafe8d0757495e07f1ee2.zip |
Add option to update pull request by `rebase` (#16125)
* add option to update pull request by `rebase`
Signed-off-by: a1012112796 <1012112796@qq.com>
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/v1/repo/pull.go | 13 | ||||
-rw-r--r-- | routers/web/repo/pull.go | 10 |
2 files changed, 16 insertions, 7 deletions
diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 0a903101c7..e493e720fb 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -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 diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 8ff2ddf394..885ac3391a 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -450,7 +450,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare } if headBranchExist { - ctx.Data["UpdateAllowed"], err = pull_service.IsUserAllowedToUpdate(pull, ctx.User) + ctx.Data["UpdateAllowed"], ctx.Data["UpdateByRebaseAllowed"], err = pull_service.IsUserAllowedToUpdate(pull, ctx.User) if err != nil { ctx.ServerError("IsUserAllowedToUpdate", err) return nil @@ -724,6 +724,8 @@ func UpdatePullRequest(ctx *context.Context) { return } + rebase := ctx.FormString("style") == "rebase" + if err := issue.PullRequest.LoadBaseRepo(); err != nil { ctx.ServerError("LoadBaseRepo", err) return @@ -733,14 +735,14 @@ func UpdatePullRequest(ctx *context.Context) { return } - allowedUpdate, err := pull_service.IsUserAllowedToUpdate(issue.PullRequest, ctx.User) + allowedUpdateByMerge, allowedUpdateByRebase, err := pull_service.IsUserAllowedToUpdate(issue.PullRequest, ctx.User) if err != nil { ctx.ServerError("IsUserAllowedToMerge", err) return } // ToDo: add check if maintainers are allowed to change branch ... (need migration & co) - if !allowedUpdate { + if (!allowedUpdateByMerge && !rebase) || (rebase && !allowedUpdateByRebase) { ctx.Flash.Error(ctx.Tr("repo.pulls.update_not_allowed")) ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + fmt.Sprint(issue.Index)) return @@ -749,7 +751,7 @@ func UpdatePullRequest(ctx *context.Context) { // default merge commit message message := fmt.Sprintf("Merge branch '%s' into %s", issue.PullRequest.BaseBranch, issue.PullRequest.HeadBranch) - if err = pull_service.Update(issue.PullRequest, ctx.User, message); err != nil { + if err = pull_service.Update(issue.PullRequest, ctx.User, message, rebase); err != nil { if models.IsErrMergeConflicts(err) { conflictError := err.(models.ErrMergeConflicts) flashError, err := ctx.HTMLString(string(tplAlertDetails), map[string]interface{}{ |