diff --git a/web_src/js/features/repo-issue.js b/web_src/js/features/repo-issue.js
index 4e077c14e2e69..f4fe185b78129 100644
--- a/web_src/js/features/repo-issue.js
+++ b/web_src/js/features/repo-issue.js
@@ -237,18 +237,31 @@ export function initRepoIssueStatusButton() {
export function initRepoPullRequestMerge() {
// Pull Request merge button
const $mergeButton = $('.merge-button > button');
- $mergeButton.on('click', function (e) {
+ const $mergeNowButton = $('.merge-now-button > button');
+ const mergeClickHandler = function (e) {
e.preventDefault();
- $(`.${$(this).data('do')}-fields`).show();
+ $(`.${$(this).attr('data-do')}-fields`).show();
$(this).parent().hide();
$('.instruct-toggle').hide();
$('.instruct-content').hide();
- });
+ $mergeButton.parent().hide();
+ $mergeNowButton.parent().hide();
+ };
+ $mergeButton.on('click', mergeClickHandler);
+ $mergeNowButton.on('click', mergeClickHandler);
$('.merge-button > .dropdown').dropdown({
onChange(_text, _value, $choice) {
- if ($choice.data('do')) {
+ if ($choice.attr('data-do')) {
$mergeButton.find('.button-text').text($choice.text());
- $mergeButton.data('do', $choice.data('do'));
+ $mergeButton.attr('data-do', $choice.attr('data-do'));
+ }
+ }
+ });
+ $('.merge-now-button > .dropdown').dropdown({
+ onChange(_text, _value, $choice) {
+ if ($choice.attr('data-do')) {
+ $mergeNowButton.find('.button-text').text($choice.text());
+ $mergeNowButton.attr('data-do', $choice.attr('data-do'));
}
}
});
@@ -257,6 +270,7 @@ export function initRepoPullRequestMerge() {
$(this).closest('.form').hide();
$mergeButton.parent().show();
$('.instruct-toggle').show();
+ $mergeNowButton.parent().show();
});
}
From daf146a24324574e0b8297e9a2394f6540ae7640 Mon Sep 17 00:00:00 2001
From: 6543 <6543@obermui.de>
Date: Sat, 7 May 2022 19:09:40 +0200
Subject: [PATCH 02/18] Revert "remove more WebUI only parts"
This reverts commit 6566141bf5f6ad086160f171c7a3e75dc378e42d.
---
routers/web/repo/pull.go | 40 ++++++++++++++++++++++++++++++++++++++++
routers/web/web.go | 1 +
2 files changed, 41 insertions(+)
diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go
index 7cedeec10e821..a2e193fde814a 100644
--- a/routers/web/repo/pull.go
+++ b/routers/web/repo/pull.go
@@ -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"
@@ -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"
@@ -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"))
@@ -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) {
+ 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 {
diff --git a/routers/web/web.go b/routers/web/web.go
index dcaad3d2bde1d..8c7886f344c7f 100644
--- a/routers/web/web.go
+++ b/routers/web/web.go
@@ -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)
From f1037f3a66ee8687746929f204f853b322b5fd0f Mon Sep 17 00:00:00 2001
From: 6543 <6543@obermui.de>
Date: Sun, 8 May 2022 15:50:49 +0200
Subject: [PATCH 03/18] ajust to #19649
---
routers/web/repo/pull.go | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go
index a2e193fde814a..67c3aa3711f0c 100644
--- a/routers/web/repo/pull.go
+++ b/routers/web/repo/pull.go
@@ -1074,8 +1074,8 @@ func CancelAutoMergePullRequest(ctx *context.Context) {
return
}
- if err := pull_model.RemoveScheduledAutoMerge(ctx, ctx.Doer, issue.PullRequest.ID, true); err != nil {
- if models.IsErrNotExist(err) {
+ if err := automerge.RemoveScheduledAutoMerge(ctx, ctx.Doer, issue.PullRequest); err != nil {
+ if db.IsErrNotExist(err) {
ctx.Flash.Error(ctx.Tr("repo.pulls.pull_request_not_scheduled"))
ctx.Redirect(fmt.Sprintf("%s/pulls/%d", ctx.Repo.RepoLink, issue.Index))
return
From 1c11584ec6eb6af8b50acb3d038471f219c1e075 Mon Sep 17 00:00:00 2001
From: wxiaoguang
Date: Wed, 18 May 2022 18:01:59 +0800
Subject: [PATCH 04/18] UI part for auto merge
---
options/locale/locale_en-US.ini | 30 +++---
routers/web/repo/pull.go | 8 +-
.../repo/issue/view_content/comments.tmpl | 4 +-
templates/repo/issue/view_content/pull.tmpl | 20 +++-
.../js/components/PullRequestMergeForm.vue | 100 ++++++++++++++++--
web_src/js/svg.js | 2 +
web_src/less/_base.less | 8 --
web_src/less/_repository.less | 4 -
8 files changed, 133 insertions(+), 43 deletions(-)
diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini
index ba619b413cbc9..225a50607df8a 100644
--- a/options/locale/locale_en-US.ini
+++ b/options/locale/locale_en-US.ini
@@ -1565,14 +1565,7 @@ pulls.squash_merge_pull_request = Create squash commit
pulls.merge_manually = Manually merged
pulls.merge_commit_id = The merge commit ID
pulls.require_signed_wont_sign = The branch requires signed commits but this merge will not be signed
-pulls.merge_pull_request_now = Merge Pull Request Now
-pulls.rebase_merge_pull_request_now = Rebase and Merge Now
-pulls.rebase_merge_commit_pull_request_now = Rebase and Merge Now (--no-ff)
-pulls.squash_merge_pull_request_now = Squash and Merge Now
-pulls.merge_pull_request_on_status_success = Merge Pull Request When All Checks Succeed
-pulls.rebase_merge_pull_request_on_status_success = Rebase and Merge When All Checks Succeed
-pulls.rebase_merge_commit_pull_request_on_status_success = Rebase and Merge (--no-ff) When All Checks Succeed
-pulls.squash_merge_pull_request_on_status_success = Squash and Merge When All Checks Succeed
+
pulls.invalid_merge_option = You cannot use this merge option for this pull request.
pulls.merge_conflict = Merge Failed: There was a conflict whilst merging. Hint: Try a different strategy
pulls.merge_conflict_summary = Error Message
@@ -1603,14 +1596,19 @@ pulls.reopened_at = `reopened this pull request %[2]
pulls.merge_instruction_hint = `You can also view command line instructions.`
pulls.merge_instruction_step1_desc = From your project repository, check out a new branch and test the changes.
pulls.merge_instruction_step2_desc = Merge the changes and update on Gitea.
-pulls.merge_on_status_success = The pull request was scheduled to merge when all checks succeed.
-pulls.merge_on_status_success_already_scheduled = This pull request is already scheduled to merge when all checks succeed.
-pulls.pr_has_pending_merge_on_success = %[1]s scheduled this pull request to auto merge when all checks succeed %[2]s.
-pulls.merge_pull_on_success_cancel = Cancel auto merge
-pulls.pull_request_not_scheduled = This pull request is not scheduled to auto merge.
-pulls.pull_request_schedule_canceled = The auto merge was canceled for this pull request.
-pulls.pull_request_scheduled_auto_merge = `scheduled this pull request to auto merge when all checks succeed %[1]s`
-pulls.pull_request_canceled_scheduled_auto_merge = `canceled auto merging this pull request when all checks succeed %[1]s`
+
+pulls.auto_merge_button_title = Auto Merge
+pulls.auto_merge_when_succeed = Auto merge when all checks succeed
+pulls.auto_merge_newly_scheduled = The pull request was scheduled to merge when all checks succeed.
+pulls.auto_merge_already_scheduled = This pull request is already scheduled to merge when all checks succeed.
+pulls.auto_merge_has_pending_schedule = %[1]s scheduled this pull request to auto merge when all checks succeed %[2]s.
+
+pulls.auto_merge_cancel_schedule = Cancel auto merge
+pulls.auto_merge_not_scheduled = This pull request is not scheduled to auto merge.
+pulls.auto_merge_canceled_schedule = The auto merge was canceled for this pull request.
+
+pulls.auto_merge_newly_scheduled_comment = `scheduled this pull request to auto merge when all checks succeed %[1]s`
+pulls.auto_merge_canceled_schedule_comment = `canceled auto merging this pull request when all checks succeed %[1]s`
milestones.new = New Milestone
milestones.open_tab = %d Open
diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go
index 41428ef9b44ed..30884f5c55ee7 100644
--- a/routers/web/repo/pull.go
+++ b/routers/web/repo/pull.go
@@ -972,7 +972,7 @@ func MergePullRequest(ctx *context.Context) {
scheduled, err := automerge.ScheduleAutoMerge(ctx, ctx.Doer, pr, repo_model.MergeStyle(form.Do), message)
if err != nil {
if pull_model.IsErrAlreadyScheduledToAutoMerge(err) {
- ctx.Flash.Success(ctx.Tr("repo.pulls.merge_on_status_success_already_scheduled"))
+ ctx.Flash.Success(ctx.Tr("repo.pulls.auto_merge_already_scheduled"))
ctx.Redirect(fmt.Sprintf("%s/pulls/%d", ctx.Repo.RepoLink, pr.Index))
return
}
@@ -980,7 +980,7 @@ func MergePullRequest(ctx *context.Context) {
return
} else if scheduled {
// nothing more to do ...
- ctx.Flash.Success(ctx.Tr("repo.pulls.merge_on_status_success"))
+ ctx.Flash.Success(ctx.Tr("repo.pulls.auto_merge_newly_scheduled"))
ctx.Redirect(fmt.Sprintf("%s/pulls/%d", ctx.Repo.RepoLink, pr.Index))
return
}
@@ -1099,14 +1099,14 @@ func CancelAutoMergePullRequest(ctx *context.Context) {
if err := automerge.RemoveScheduledAutoMerge(ctx, ctx.Doer, issue.PullRequest); err != nil {
if db.IsErrNotExist(err) {
- ctx.Flash.Error(ctx.Tr("repo.pulls.pull_request_not_scheduled"))
+ ctx.Flash.Error(ctx.Tr("repo.pulls.auto_merge_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.Flash.Success(ctx.Tr("repo.pulls.auto_merge_canceled_schedule"))
ctx.Redirect(fmt.Sprintf("%s/pulls/%d", ctx.Repo.RepoLink, issue.Index))
}
diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl
index 235f4c8fc2662..0258a9f9691c0 100644
--- a/templates/repo/issue/view_content/comments.tmpl
+++ b/templates/repo/issue/view_content/comments.tmpl
@@ -843,8 +843,8 @@
{{svg "octicon-git-merge" 16}}
{{.Poster.GetDisplayName}}
- {{if eq .Type 34}}{{$.i18n.Tr "repo.pulls.pull_request_scheduled_auto_merge" $createdStr | Safe}}
- {{else}}{{$.i18n.Tr "repo.pulls.pull_request_canceled_scheduled_auto_merge" $createdStr | Safe}}{{end}}
+ {{if eq .Type 34}}{{$.i18n.Tr "repo.pulls.auto_merge_newly_scheduled_comment" $createdStr | Safe}}
+ {{else}}{{$.i18n.Tr "repo.pulls.auto_merge_canceled_schedule_comment" $createdStr | Safe}}{{end}}
{{end}}
diff --git a/templates/repo/issue/view_content/pull.tmpl b/templates/repo/issue/view_content/pull.tmpl
index c764138fa0474..68a7fdc85d4d8 100644
--- a/templates/repo/issue/view_content/pull.tmpl
+++ b/templates/repo/issue/view_content/pull.tmpl
@@ -323,8 +323,18 @@
{{$approvers := .Issue.PullRequest.GetApprovers}}
{{if or $prUnit.PullRequestsConfig.AllowMerge $prUnit.PullRequestsConfig.AllowRebase $prUnit.PullRequestsConfig.AllowRebaseMerge $prUnit.PullRequestsConfig.AllowSquash}}
-