Skip to content
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

Auto merge pull requests when all checks succeeded via WebUI #19648

Merged
merged 42 commits into from
Jun 11, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
abfeefe
Revert "remove webUI part for another pull"
6543 May 7, 2022
daf146a
Revert "remove more WebUI only parts"
6543 May 7, 2022
f1037f3
ajust to #19649
6543 May 8, 2022
847919d
Merge branch 'main' into auto-merge_webUI
6543 May 8, 2022
efad877
Merge branch 'master' into auto-merge_webUI
6543 May 12, 2022
c810cc9
Merge branch 'main' into auto-merge_webUI
wxiaoguang May 18, 2022
1c11584
UI part for auto merge
wxiaoguang May 18, 2022
916e4bb
disable unnecessary eslint
wxiaoguang May 18, 2022
346c545
Merge branch 'main' into auto-merge_webUI
6543 May 18, 2022
2bc2215
refactor and add comments
wxiaoguang May 19, 2022
69b2ff7
make merge form work for writers
wxiaoguang May 19, 2022
05317de
Merge branch 'master' into auto-merge_webUI
6543 May 19, 2022
935ab7b
fine tune button colors
wxiaoguang May 19, 2022
0991637
hide the auto merge if this PR can be merged now
wxiaoguang May 19, 2022
5f6f1c9
Merge branch 'main' into auto-merge_webUI
6543 May 19, 2022
a078ba8
UX: hide delete_branch_after_merge for auto-merge
6543 May 20, 2022
53a8b04
UX: dont hide auto-merge schedule for admins
6543 May 20, 2022
3e204ee
UX: make scheduled auto-merges be overwritten from webUI
6543 May 20, 2022
4880009
Merge branch 'main' into auto-merge_webUI
6543 May 20, 2022
40f7796
Merge branch 'main' into auto-merge_webUI
wxiaoguang May 20, 2022
3fdc599
add comment for testing
wxiaoguang May 20, 2022
8dfe1eb
Merge branch 'main' into auto-merge_webUI
6543 May 20, 2022
c614ffa
add comment for testing
wxiaoguang May 20, 2022
837add8
fine tune css style
wxiaoguang May 20, 2022
6dfe7d6
Merge branch 'main' into auto-merge_webUI
6543 May 20, 2022
d9c36da
Merge branch 'main' into auto-merge_webUI
6543 May 20, 2022
ccd50c6
Merge branch 'main' into auto-merge_webUI
6543 May 20, 2022
fd93997
Merge branch 'main' into auto-merge_webUI
6543 May 20, 2022
402b6a0
Merge branch 'main' into auto-merge_webUI
6543 May 21, 2022
ba0173a
Merge branch 'main' into auto-merge_webUI
6543 May 23, 2022
78e1174
Merge branch 'main' into auto-merge_webUI
6543 May 24, 2022
6bef922
Merge branch 'main' into auto-merge_webUI
6543 Jun 2, 2022
6305f52
Merge branch 'main' into auto-merge_webUI
6543 Jun 3, 2022
8edb5c2
Update templates/repo/issue/view_content/pull.tmpl
wxiaoguang Jun 3, 2022
eb33a2f
Merge branch 'main' into auto-merge_webUI
6543 Jun 5, 2022
0502a21
Merge branch 'main' into auto-merge_webUI
wxiaoguang Jun 9, 2022
9bd5f97
UI adjuestment
wxiaoguang Jun 9, 2022
6303b2b
Merge branch 'main' into auto-merge_webUI
6543 Jun 10, 2022
0e2f19d
Merge branch 'main' into auto-merge_webUI
6543 Jun 10, 2022
81af3ba
Update web_src/js/components/PullRequestMergeForm.vue
wxiaoguang Jun 11, 2022
5dd9e56
Merge branch 'main' into auto-merge_webUI
6543 Jun 11, 2022
4f12809
Merge branch 'main' into auto-merge_webUI
lunny Jun 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions routers/web/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/organization"
pull_model "code.gitea.io/gitea/models/pull"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
Expand All @@ -35,6 +36,7 @@ import (
"code.gitea.io/gitea/modules/web/middleware"
"code.gitea.io/gitea/routers/utils"
asymkey_service "code.gitea.io/gitea/services/asymkey"
"code.gitea.io/gitea/services/automerge"
"code.gitea.io/gitea/services/forms"
"code.gitea.io/gitea/services/gitdiff"
pull_service "code.gitea.io/gitea/services/pull"
Expand Down Expand Up @@ -943,6 +945,24 @@ func MergePullRequest(ctx *context.Context) {
return
}

if form.MergeWhenChecksSucceed {
scheduled, err := automerge.ScheduleAutoMerge(ctx, ctx.Doer, pr, repo_model.MergeStyle(form.Do), form.MergeTitleField)
if err != nil {
if pull_model.IsErrAlreadyScheduledToAutoMerge(err) {
ctx.Flash.Success(ctx.Tr("repo.pulls.merge_on_status_success_already_scheduled"))
ctx.Redirect(fmt.Sprintf("%s/pulls/%d", ctx.Repo.RepoLink, pr.Index))
return
}
ctx.ServerError("ScheduleAutoMerge", err)
return
} else if scheduled {
// nothing more to do ...
ctx.Flash.Success(ctx.Tr("repo.pulls.merge_on_status_success"))
ctx.Redirect(fmt.Sprintf("%s/pulls/%d", ctx.Repo.RepoLink, pr.Index))
return
}
}

if err := pull_service.Merge(pr, ctx.Doer, ctx.Repo.GitRepo, repo_model.MergeStyle(form.Do), form.HeadCommitID, form.MergeTitleField); err != nil {
if models.IsErrInvalidMergeStyle(err) {
ctx.Flash.Error(ctx.Tr("repo.pulls.invalid_merge_option"))
Expand Down Expand Up @@ -1047,6 +1067,26 @@ func MergePullRequest(ctx *context.Context) {
ctx.Redirect(issue.Link())
}

// CancelAutoMergePullRequest cancels a scheduled pr
func CancelAutoMergePullRequest(ctx *context.Context) {
issue := checkPullInfo(ctx)
if ctx.Written() {
return
}

if err := pull_model.RemoveScheduledAutoMerge(ctx, ctx.Doer, issue.PullRequest.ID, true); err != nil {
if models.IsErrNotExist(err) {
6543 marked this conversation as resolved.
Show resolved Hide resolved
ctx.Flash.Error(ctx.Tr("repo.pulls.pull_request_not_scheduled"))
ctx.Redirect(fmt.Sprintf("%s/pulls/%d", ctx.Repo.RepoLink, issue.Index))
return
}
ctx.ServerError("RemoveScheduledAutoMerge", err)
return
}
ctx.Flash.Success(ctx.Tr("repo.pulls.pull_request_schedule_canceled"))
ctx.Redirect(fmt.Sprintf("%s/pulls/%d", ctx.Repo.RepoLink, issue.Index))
}

func stopTimerIfAvailable(user *user_model.User, issue *models.Issue) error {
if models.StopwatchExists(user.ID, issue.ID) {
if err := models.CreateOrStopIssueStopwatch(user, issue); err != nil {
Expand Down
1 change: 1 addition & 0 deletions routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,7 @@ func RegisterRoutes(m *web.Route) {
m.Get(".patch", repo.DownloadPullPatch)
m.Get("/commits", context.RepoRef(), repo.ViewPullCommits)
m.Post("/merge", context.RepoMustNotBeArchived(), bindIgnErr(forms.MergePullRequestForm{}), repo.MergePullRequest)
m.Post("/cancel_auto_merge", context.RepoMustNotBeArchived(), repo.CancelAutoMergePullRequest)
m.Post("/update", repo.UpdatePullRequest)
m.Post("/set_allow_maintainer_edit", bindIgnErr(forms.UpdateAllowEditsForm{}), repo.SetAllowEdits)
m.Post("/cleanup", context.RepoMustNotBeArchived(), context.RepoRef(), repo.CleanUpPullRequest)
Expand Down
Loading