aboutsummaryrefslogtreecommitdiffstats
path: root/templates/repo
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2022-06-11 16:44:20 +0200
committerGitHub <noreply@github.com>2022-06-11 16:44:20 +0200
commita9cc9c0f7afacb2e51cfd1885d392f56dca0c7f5 (patch)
tree97c5ec44aa74ac8718d3760d47008f788d8e7d6d /templates/repo
parentce3dd04c63a048fe791ed864c2023fd37b09e427 (diff)
downloadgitea-a9cc9c0f7afacb2e51cfd1885d392f56dca0c7f5.tar.gz
gitea-a9cc9c0f7afacb2e51cfd1885d392f56dca0c7f5.zip
Auto merge pull requests when all checks succeeded via WebUI (#19648)
Add WebUI part of Auto merge feature close #19621 Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: delvh <dev.lh@web.de>
Diffstat (limited to 'templates/repo')
-rw-r--r--templates/repo/issue/view_content/comments.tmpl4
-rw-r--r--templates/repo/issue/view_content/pull.tmpl198
-rw-r--r--templates/repo/issue/view_content/pull_merge_instruction.tmpl19
3 files changed, 122 insertions, 99 deletions
diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl
index 235f4c8fc2..0258a9f969 100644
--- a/templates/repo/issue/view_content/comments.tmpl
+++ b/templates/repo/issue/view_content/comments.tmpl
@@ -843,8 +843,8 @@
<span class="badge">{{svg "octicon-git-merge" 16}}</span>
<span class="text grey">
<a class="author" href="{{.Poster.HomeLink}}">{{.Poster.GetDisplayName}}</a>
- {{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}}
</span>
</div>
{{end}}
diff --git a/templates/repo/issue/view_content/pull.tmpl b/templates/repo/issue/view_content/pull.tmpl
index c764138fa0..d2282f07f6 100644
--- a/templates/repo/issue/view_content/pull.tmpl
+++ b/templates/repo/issue/view_content/pull.tmpl
@@ -251,8 +251,14 @@
{{$.i18n.Tr (printf "repo.signing.wont_sign.%s" .WontSignReason) }}
</div>
{{end}}
+
{{$notAllOverridableChecksOk := or .IsBlockedByApprovals .IsBlockedByRejection .IsBlockedByOfficialReviewRequests .IsBlockedByOutdatedBranch .IsBlockedByChangedProtectedFiles (and .EnableStatusCheck (not .RequiredStatusCheckState.IsSuccess))}}
- {{if and (or $.IsRepoAdmin (not $notAllOverridableChecksOk)) (or (not .AllowMerge) (not .RequireSigned) .WillSign)}}
+
+ {{/* admin can merge without checks, writer can merge when checkes succeed */}}
+ {{$canMergeNow := and (or $.IsRepoAdmin (not $notAllOverridableChecksOk)) (or (not .AllowMerge) (not .RequireSigned) .WillSign)}}
+ {{/* admin and writer both can make an auto merge schedule */}}
+
+ {{if $canMergeNow}}
{{if $notAllOverridableChecksOk}}
<div class="item">
<i class="icon icon-octicon">{{svg "octicon-dot-fill"}}</i>
@@ -277,7 +283,6 @@
{{end}}
{{end}}
- {{$canAutoMerge = true}}
{{if (gt .Issue.PullRequest.CommitsBehind 0)}}
<div class="ui divider"></div>
<div class="item item-section">
@@ -317,112 +322,111 @@
</div>
{{end}}
- {{if and (or $.IsRepoAdmin (not $notAllOverridableChecksOk)) (or (not .AllowMerge) (not .RequireSigned) .WillSign)}}
- {{if .AllowMerge}}
- {{$prUnit := .Repository.MustGetUnit $.UnitTypePullRequests}}
- {{$approvers := .Issue.PullRequest.GetApprovers}}
- {{if or $prUnit.PullRequestsConfig.AllowMerge $prUnit.PullRequestsConfig.AllowRebase $prUnit.PullRequestsConfig.AllowRebaseMerge $prUnit.PullRequestsConfig.AllowSquash}}
+ {{if .AllowMerge}} {{/* user is allowed to merge */}}
+ {{$prUnit := .Repository.MustGetUnit $.UnitTypePullRequests}}
+ {{$approvers := .Issue.PullRequest.GetApprovers}}
+ {{if or $prUnit.PullRequestsConfig.AllowMerge $prUnit.PullRequestsConfig.AllowRebase $prUnit.PullRequestsConfig.AllowRebaseMerge $prUnit.PullRequestsConfig.AllowSquash}}
+ {{$hasPendingPullRequestMergeTip := ""}}
+ {{if .HasPendingPullRequestMerge}}
+ {{$createdPRMergeStr := TimeSinceUnix .PendingPullRequestMerge.CreatedUnix $.i18n.Lang}}
+ {{$hasPendingPullRequestMergeTip = $.i18n.Tr "repo.pulls.auto_merge_has_pending_schedule" .PendingPullRequestMerge.Doer.Name $createdPRMergeStr}}
+ {{end}}
+ <div class="ui divider"></div>
+ <script>
+ <!-- /* eslint-disable */ -->
+ (() => {
+ const defaultMergeTitle = {{.DefaultMergeMessage}};
+ const defaultSquashMergeTitle = {{.DefaultSquashMergeMessage}};
+ const defaultMergeMessage = 'Reviewed-on: ' + {{$.Issue.HTMLURL}} + '\n' + {{$approvers}};
+ const mergeForm = {
+ 'baseLink': {{.Link}},
+ 'textCancel': {{$.i18n.Tr "cancel"}},
+ 'textDeleteBranch': {{$.i18n.Tr "repo.branch.delete" .HeadTarget}},
+ 'textAutoMergeButtonWhenSucceed': {{$.i18n.Tr "repo.pulls.auto_merge_button_when_succeed"}},
+ 'textAutoMergeWhenSucceed': {{$.i18n.Tr "repo.pulls.auto_merge_when_succeed"}},
+ 'textAutoMergeCancelSchedule': {{$.i18n.Tr "repo.pulls.auto_merge_cancel_schedule"}},
- <div class="ui divider"></div>
+ 'canMergeNow': {{$canMergeNow}},
+ 'allOverridableChecksOk': {{not $notAllOverridableChecksOk}},
+ 'pullHeadCommitID': {{.PullHeadCommitID}},
+ 'isPullBranchDeletable': {{.IsPullBranchDeletable}},
+ 'defaultDeleteBranchAfterMerge': {{$prUnit.PullRequestsConfig.DefaultDeleteBranchAfterMerge}},
+ 'mergeMessageFieldPlaceHolder': {{$.i18n.Tr "repo.editor.commit_message_desc"}},
- <script>
- <!-- /* eslint-disable */ -->
- (() => {
- const defaultMergeTitle = {{.DefaultMergeMessage}};
- const defaultSquashMergeTitle = {{.DefaultSquashMergeMessage}};
- const defaultMergeMessage = 'Reviewed-on: ' + {{$.Issue.HTMLURL}} + '\n' + {{$approvers}};
- const mergeForm = {
- 'baseLink': {{.Link}},
- 'textCancel': {{$.i18n.Tr "cancel"}},
- 'textDeleteBranch': {{$.i18n.Tr "repo.branch.delete" .HeadTarget}},
+ 'hasPendingPullRequestMerge': {{.HasPendingPullRequestMerge}},
+ 'hasPendingPullRequestMergeTip': {{$hasPendingPullRequestMergeTip}},
+ };
- 'allOverridableChecksOk': {{not $notAllOverridableChecksOk}},
- 'pullHeadCommitID': {{.PullHeadCommitID}},
- 'isPullBranchDeletable': {{.IsPullBranchDeletable}},
- 'defaultDeleteBranchAfterMerge': {{$prUnit.PullRequestsConfig.DefaultDeleteBranchAfterMerge}},
- 'mergeMessageFieldPlaceHolder': {{$.i18n.Tr "repo.editor.commit_message_desc"}},
- };
- mergeForm['mergeStyles'] = [
- {
- 'name': 'merge',
- 'allowed': {{$prUnit.PullRequestsConfig.AllowMerge}},
- 'textDoMerge': {{$.i18n.Tr "repo.pulls.merge_pull_request"}},
- 'mergeTitleFieldText': defaultMergeTitle,
- 'mergeMessageFieldText': defaultMergeMessage,
- },
- {
- 'name': 'rebase',
- 'allowed': {{$prUnit.PullRequestsConfig.AllowRebase}},
- 'textDoMerge': {{$.i18n.Tr "repo.pulls.rebase_merge_pull_request"}},
- 'hideMergeMessageTexts': true,
- },
- {
- 'name': 'rebase-merge',
- 'allowed': {{$prUnit.PullRequestsConfig.AllowRebaseMerge}},
- 'textDoMerge': {{$.i18n.Tr "repo.pulls.rebase_merge_commit_pull_request"}},
- 'mergeTitleFieldText': defaultMergeTitle,
- 'mergeMessageFieldText': defaultMergeMessage,
- },
- {
- 'name': 'squash',
- 'allowed': {{$prUnit.PullRequestsConfig.AllowSquash}},
- 'textDoMerge': {{$.i18n.Tr "repo.pulls.squash_merge_pull_request"}},
- 'mergeTitleFieldText': defaultSquashMergeTitle,
- 'mergeMessageFieldText': defaultMergeMessage,
- },
- {
- 'name': 'manually-merged',
- 'allowed': {{and $prUnit.PullRequestsConfig.AllowManualMerge $.IsRepoAdmin}},
- 'textDoMerge': {{$.i18n.Tr "repo.pulls.merge_manually"}},
- 'hideMergeMessageTexts': true,
- }
- ];
- window.config.pageData.pullRequestMergeForm = mergeForm;
- })();
- </script>
+ const generalHideAutoMerge = mergeForm.canMergeNow && mergeForm.allOverridableChecksOk; // if this PR can be merged now, then hide the auto merge
+ mergeForm['mergeStyles'] = [
+ {
+ 'name': 'merge',
+ 'allowed': {{$prUnit.PullRequestsConfig.AllowMerge}},
+ 'textDoMerge': {{$.i18n.Tr "repo.pulls.merge_pull_request"}},
+ 'mergeTitleFieldText': defaultMergeTitle,
+ 'mergeMessageFieldText': defaultMergeMessage,
+ 'hideAutoMerge': generalHideAutoMerge,
+ },
+ {
+ 'name': 'rebase',
+ 'allowed': {{$prUnit.PullRequestsConfig.AllowRebase}},
+ 'textDoMerge': {{$.i18n.Tr "repo.pulls.rebase_merge_pull_request"}},
+ 'hideMergeMessageTexts': true,
+ 'hideAutoMerge': generalHideAutoMerge,
+ },
+ {
+ 'name': 'rebase-merge',
+ 'allowed': {{$prUnit.PullRequestsConfig.AllowRebaseMerge}},
+ 'textDoMerge': {{$.i18n.Tr "repo.pulls.rebase_merge_commit_pull_request"}},
+ 'mergeTitleFieldText': defaultMergeTitle,
+ 'mergeMessageFieldText': defaultMergeMessage,
+ 'hideAutoMerge': generalHideAutoMerge,
+ },
+ {
+ 'name': 'squash',
+ 'allowed': {{$prUnit.PullRequestsConfig.AllowSquash}},
+ 'textDoMerge': {{$.i18n.Tr "repo.pulls.squash_merge_pull_request"}},
+ 'mergeTitleFieldText': defaultSquashMergeTitle,
+ 'mergeMessageFieldText': defaultMergeMessage,
+ 'hideAutoMerge': generalHideAutoMerge,
+ },
+ {
+ 'name': 'manually-merged',
+ 'allowed': {{and $prUnit.PullRequestsConfig.AllowManualMerge $.IsRepoAdmin}},
+ 'textDoMerge': {{$.i18n.Tr "repo.pulls.merge_manually"}},
+ 'hideMergeMessageTexts': true,
+ 'hideAutoMerge': true,
+ }
+ ];
+ window.config.pageData.pullRequestMergeForm = mergeForm;
+ })();
+ </script>
- <div id="pull-request-merge-form"></div>
+ <div id="pull-request-merge-form"></div>
- {{if .ShowMergeInstructions}}
- <div class="instruct-toggle mt-3"> {{$.i18n.Tr "repo.pulls.merge_instruction_hint" | Safe}} </div>
- <div class="instruct-content" style="display:none">
- <div class="ui divider"></div>
- <div><h3 class="di">{{$.i18n.Tr "step1"}} </h3>{{$.i18n.Tr "repo.pulls.merge_instruction_step1_desc"}}</div>
- <div class="ui secondary segment">
- {{if eq .Issue.PullRequest.Flow 0}}
- <div>git checkout -b {{if ne .Issue.PullRequest.HeadRepo.ID .Issue.PullRequest.BaseRepo.ID}}{{.Issue.PullRequest.HeadRepo.OwnerName}}-{{end}}{{.Issue.PullRequest.HeadBranch}} {{.Issue.PullRequest.BaseBranch}}</div>
- <div>git pull {{if ne .Issue.PullRequest.HeadRepo.ID .Issue.PullRequest.BaseRepo.ID}}{{.Issue.PullRequest.HeadRepo.HTMLURL}}{{else}}origin{{end}} {{.Issue.PullRequest.HeadBranch}}</div>
- {{else}}
- <div>git fetch origin {{.Issue.PullRequest.GetGitRefName}}:{{.Issue.PullRequest.HeadBranch}}</div>
- {{end}}
- </div>
- <div><h3 class="di">{{$.i18n.Tr "step2"}} </h3>{{$.i18n.Tr "repo.pulls.merge_instruction_step2_desc"}}</div>
- <div class="ui secondary segment">
- <div>git checkout {{.Issue.PullRequest.BaseBranch}}</div>
- <div>git merge --no-ff {{if ne .Issue.PullRequest.HeadRepo.ID .Issue.PullRequest.BaseRepo.ID}}{{.Issue.PullRequest.HeadRepo.OwnerName}}-{{end}}{{.Issue.PullRequest.HeadBranch}}</div>
- <div>git push origin {{.Issue.PullRequest.BaseBranch}}</div>
- </div>
- </div>
- {{end}}
- {{else}}
- <div class="ui divider"></div>
- <div class="item text red">
- {{svg "octicon-x"}}
- {{$.i18n.Tr "repo.pulls.no_merge_desc"}}
- </div>
- <div class="item">
- {{svg "octicon-info"}}
- {{$.i18n.Tr "repo.pulls.no_merge_helper"}}
- </div>
+ {{if .ShowMergeInstructions}}
+ {{template "repo/issue/view_content/pull_merge_instruction" (dict "i18n" .i18n "Issue" .Issue)}}
{{end}}
{{else}}
+ {{/* no merge style was set in repo setting: not or ($prUnit.PullRequestsConfig.AllowMerge ...) */}}
<div class="ui divider"></div>
+ <div class="item text red">
+ {{svg "octicon-x"}}
+ {{$.i18n.Tr "repo.pulls.no_merge_desc"}}
+ </div>
<div class="item">
{{svg "octicon-info"}}
- {{$.i18n.Tr "repo.pulls.no_merge_access"}}
+ {{$.i18n.Tr "repo.pulls.no_merge_helper"}}
</div>
- {{end}}
- {{end}}
+ {{end}} {{/* end if the repo was set to use any merge style */}}
+ {{else}}
+ {{/* user is not allowed to merge */}}
+ <div class="ui divider"></div>
+ <div class="item">
+ {{svg "octicon-info"}}
+ {{$.i18n.Tr "repo.pulls.no_merge_access"}}
+ </div>
+ {{end}} {{/* end if user is allowed to merge or not */}}
{{else}}
{{/* Merge conflict without specific file. Suggest manual merge, only if all reviews and status checks OK. */}}
{{if .IsBlockedByApprovals}}
diff --git a/templates/repo/issue/view_content/pull_merge_instruction.tmpl b/templates/repo/issue/view_content/pull_merge_instruction.tmpl
new file mode 100644
index 0000000000..0ed70860f3
--- /dev/null
+++ b/templates/repo/issue/view_content/pull_merge_instruction.tmpl
@@ -0,0 +1,19 @@
+<div class="instruct-toggle mt-3"> {{$.i18n.Tr "repo.pulls.merge_instruction_hint" | Safe}} </div>
+<div class="instruct-content" style="display:none">
+ <div class="ui divider"></div>
+ <div><h3 class="di">{{$.i18n.Tr "step1"}} </h3>{{$.i18n.Tr "repo.pulls.merge_instruction_step1_desc"}}</div>
+ <div class="ui secondary segment">
+ {{if eq $.Issue.PullRequest.Flow 0}}
+ <div>git checkout -b {{if ne $.Issue.PullRequest.HeadRepo.ID $.Issue.PullRequest.BaseRepo.ID}}{{$.Issue.PullRequest.HeadRepo.OwnerName}}-{{end}}{{$.Issue.PullRequest.HeadBranch}} {{$.Issue.PullRequest.BaseBranch}}</div>
+ <div>git pull {{if ne $.Issue.PullRequest.HeadRepo.ID $.Issue.PullRequest.BaseRepo.ID}}{{$.Issue.PullRequest.HeadRepo.HTMLURL}}{{else}}origin{{end}} {{$.Issue.PullRequest.HeadBranch}}</div>
+ {{else}}
+ <div>git fetch origin {{$.Issue.PullRequest.GetGitRefName}}:{{$.Issue.PullRequest.HeadBranch}}</div>
+ {{end}}
+ </div>
+ <div><h3 class="di">{{$.i18n.Tr "step2"}} </h3>{{$.i18n.Tr "repo.pulls.merge_instruction_step2_desc"}}</div>
+ <div class="ui secondary segment">
+ <div>git checkout {{$.Issue.PullRequest.BaseBranch}}</div>
+ <div>git merge --no-ff {{if ne $.Issue.PullRequest.HeadRepo.ID $.Issue.PullRequest.BaseRepo.ID}}{{$.Issue.PullRequest.HeadRepo.OwnerName}}-{{end}}{{$.Issue.PullRequest.HeadBranch}}</div>
+ <div>git push origin {{$.Issue.PullRequest.BaseBranch}}</div>
+ </div>
+</div>