code.gitea.io/gitea@v1.22.3/templates/repo/issue/view_content/pull.tmpl (about)

     1  {{if and .Issue.PullRequest.HasMerged (not .IsPullBranchDeletable)}}
     2  {{/* Then the merge box will not be displayed because this page already contains enough information */}}
     3  {{else}}
     4  <div class="timeline-item comment merge box">
     5  	<div class="timeline-avatar text {{if .Issue.PullRequest.HasMerged}}purple
     6  	{{- else if .Issue.IsClosed}}grey
     7  	{{- else if .IsPullWorkInProgress}}grey
     8  	{{- else if .IsFilesConflicted}}grey
     9  	{{- else if .IsPullRequestBroken}}red
    10  	{{- else if .IsBlockedByApprovals}}red
    11  	{{- else if .IsBlockedByRejection}}red
    12  	{{- else if .IsBlockedByOfficialReviewRequests}}red
    13  	{{- else if .IsBlockedByOutdatedBranch}}red
    14  	{{- else if .IsBlockedByChangedProtectedFiles}}red
    15  	{{- else if and .EnableStatusCheck (or .RequiredStatusCheckState.IsFailure .RequiredStatusCheckState.IsError)}}red
    16  	{{- else if and .EnableStatusCheck (or (not $.LatestCommitStatus) .RequiredStatusCheckState.IsPending .RequiredStatusCheckState.IsWarning)}}yellow
    17  	{{- else if and .AllowMerge .RequireSigned (not .WillSign)}}red
    18  	{{- else if .Issue.PullRequest.IsChecking}}yellow
    19  	{{- else if .Issue.PullRequest.IsEmpty}}grey
    20  	{{- else if .Issue.PullRequest.CanAutoMerge}}green
    21  	{{- else}}red{{end}}">{{svg "octicon-git-merge" 40}}</div>
    22  	<div class="content">
    23  		{{if .LatestCommitStatus}}
    24  		<div class="ui attached segment fitted">
    25  		{{template "repo/pulls/status" (dict
    26  			"CommitStatus" .LatestCommitStatus
    27  			"CommitStatuses" .LatestCommitStatuses
    28  			"MissingRequiredChecks" .MissingRequiredChecks
    29  			"ShowHideChecks" true
    30  			"is_context_required" .is_context_required
    31  		)}}
    32  		</div>
    33  		{{end}}
    34  		{{$showGeneralMergeForm := false}}
    35  		<div class="ui attached segment merge-section {{if not $.LatestCommitStatus}}no-header{{end}} flex-items-block">
    36  			{{if .Issue.PullRequest.HasMerged}}
    37  				{{if .IsPullBranchDeletable}}
    38  					<div class="item item-section text tw-flex-1">
    39  						<div class="item-section-left">
    40  							<h3 class="tw-mb-2">
    41  								{{ctx.Locale.Tr "repo.pulls.merged_success"}}
    42  							</h3>
    43  							<div class="merge-section-info">
    44  								{{ctx.Locale.Tr "repo.pulls.merged_info_text" (HTMLFormat "<code>%s</code>" .HeadTarget)}}
    45  							</div>
    46  						</div>
    47  						<div class="item-section-right">
    48  							<button class="delete-button ui button" data-url="{{.DeleteBranchLink}}">{{ctx.Locale.Tr "repo.branch.delete_html"}}</button>
    49  						</div>
    50  					</div>
    51  				{{end}}
    52  			{{else if .Issue.IsClosed}}
    53  				<div class="item item-section text tw-flex-1">
    54  					<div class="item-section-left">
    55  						<h3 class="tw-mb-2">{{ctx.Locale.Tr "repo.pulls.closed"}}</h3>
    56  						<div class="merge-section-info">
    57  							{{if .IsPullRequestBroken}}
    58  								{{ctx.Locale.Tr "repo.pulls.cant_reopen_deleted_branch"}}
    59  							{{else}}
    60  								{{ctx.Locale.Tr "repo.pulls.reopen_to_merge"}}
    61  							{{end}}
    62  						</div>
    63  					</div>
    64  					{{if and .IsPullBranchDeletable (not .IsPullRequestBroken)}}
    65  						<div class="item-section-right">
    66  							<button class="delete-button ui button" data-url="{{.DeleteBranchLink}}">{{ctx.Locale.Tr "repo.branch.delete_html"}}</button>
    67  						</div>
    68  					{{end}}
    69  				</div>
    70  			{{else if .IsPullFilesConflicted}}
    71  				<div class="item">
    72  					{{svg "octicon-x"}}
    73  					{{ctx.Locale.Tr "repo.pulls.files_conflicted"}}
    74  				</div>
    75  				<ul>
    76  					{{range .ConflictedFiles}}
    77  					<li>{{.}}</li>
    78  					{{end}}
    79  				</ul>
    80  			{{else if .IsPullRequestBroken}}
    81  				<div class="item">
    82  					{{svg "octicon-x"}}
    83  					{{ctx.Locale.Tr "repo.pulls.data_broken"}}
    84  				</div>
    85  			{{else if .IsPullWorkInProgress}}
    86  				<div class="item toggle-wip" data-title="{{.Issue.Title}}" data-wip-prefix="{{.WorkInProgressPrefix}}" data-update-url="{{.Issue.Link}}/title">
    87  					<div class="item-section-left flex-text-inline tw-flex-1">
    88  						{{svg "octicon-x"}}
    89  						{{ctx.Locale.Tr "repo.pulls.cannot_merge_work_in_progress"}}
    90  					</div>
    91  					{{if or .HasIssuesOrPullsWritePermission .IsIssuePoster}}
    92  						<button class="ui compact button">
    93  							{{ctx.Locale.Tr "repo.pulls.remove_prefix" .WorkInProgressPrefix}}
    94  						</button>
    95  					{{end}}
    96  				</div>
    97  				{{template "repo/issue/view_content/update_branch_by_merge" $}}
    98  			{{else if .Issue.PullRequest.IsChecking}}
    99  				<div class="item">
   100  					{{svg "octicon-sync"}}
   101  					{{ctx.Locale.Tr "repo.pulls.is_checking"}}
   102  				</div>
   103  			{{else if .Issue.PullRequest.IsAncestor}}
   104  				<div class="item">
   105  					{{svg "octicon-alert"}}
   106  					{{ctx.Locale.Tr "repo.pulls.is_ancestor"}}
   107  				</div>
   108  			{{else if or .Issue.PullRequest.CanAutoMerge .Issue.PullRequest.IsEmpty}}
   109  				{{if .IsBlockedByApprovals}}
   110  					<div class="item">
   111  						{{svg "octicon-x"}}
   112  						{{ctx.Locale.Tr "repo.pulls.blocked_by_approvals" .GrantedApprovals .ProtectedBranch.RequiredApprovals}}
   113  					</div>
   114  				{{else if .IsBlockedByRejection}}
   115  					<div class="item">
   116  						{{svg "octicon-x"}}
   117  					{{ctx.Locale.Tr "repo.pulls.blocked_by_rejection"}}
   118  					</div>
   119  				{{else if .IsBlockedByOfficialReviewRequests}}
   120  					<div class="item">
   121  						{{svg "octicon-x"}}
   122  					{{ctx.Locale.Tr "repo.pulls.blocked_by_official_review_requests"}}
   123  					</div>
   124  				{{else if .IsBlockedByOutdatedBranch}}
   125  					<div class="item">
   126  						{{svg "octicon-x"}}
   127  						{{ctx.Locale.Tr "repo.pulls.blocked_by_outdated_branch"}}
   128  					</div>
   129  				{{else if .IsBlockedByChangedProtectedFiles}}
   130  					<div class="item">
   131  						{{svg "octicon-x"}}
   132  						{{ctx.Locale.TrN $.ChangedProtectedFilesNum "repo.pulls.blocked_by_changed_protected_files_1" "repo.pulls.blocked_by_changed_protected_files_n"}}
   133  					</div>
   134  					<ul>
   135  						{{range .ChangedProtectedFiles}}
   136  						<li>{{.}}</li>
   137  						{{end}}
   138  					</ul>
   139  				{{else if and .EnableStatusCheck (or .RequiredStatusCheckState.IsError .RequiredStatusCheckState.IsFailure)}}
   140  					<div class="item">
   141  						{{svg "octicon-x"}}
   142  						{{ctx.Locale.Tr "repo.pulls.required_status_check_failed"}}
   143  					</div>
   144  				{{else if and .EnableStatusCheck (not .RequiredStatusCheckState.IsSuccess)}}
   145  					<div class="item">
   146  						{{svg "octicon-x"}}
   147  						{{ctx.Locale.Tr "repo.pulls.required_status_check_missing"}}
   148  					</div>
   149  				{{else if and .AllowMerge .RequireSigned (not .WillSign)}}
   150  					<div class="item">
   151  						{{svg "octicon-x"}}
   152  						{{ctx.Locale.Tr "repo.pulls.require_signed_wont_sign"}}
   153  					</div>
   154  					<div class="item">
   155  						{{svg "octicon-unlock"}}
   156  						{{ctx.Locale.Tr (printf "repo.signing.wont_sign.%s" .WontSignReason)}}
   157  					</div>
   158  				{{end}}
   159  
   160  				{{$notAllOverridableChecksOk := or .IsBlockedByApprovals .IsBlockedByRejection .IsBlockedByOfficialReviewRequests .IsBlockedByOutdatedBranch .IsBlockedByChangedProtectedFiles (and .EnableStatusCheck (not .RequiredStatusCheckState.IsSuccess))}}
   161  
   162  				{{/* admin can merge without checks, writer can merge when checks succeed */}}
   163  				{{$canMergeNow := and (or $.IsRepoAdmin (not $notAllOverridableChecksOk)) (or (not .AllowMerge) (not .RequireSigned) .WillSign)}}
   164  				{{/* admin and writer both can make an auto merge schedule */}}
   165  
   166  				{{if $canMergeNow}}
   167  					{{if $notAllOverridableChecksOk}}
   168  						<div class="item">
   169  							{{svg "octicon-dot-fill"}}
   170  							{{ctx.Locale.Tr "repo.pulls.required_status_check_administrator"}}
   171  						</div>
   172  					{{else}}
   173  						<div class="item">
   174  							{{svg "octicon-check"}}
   175  							{{ctx.Locale.Tr "repo.pulls.can_auto_merge_desc"}}
   176  						</div>
   177  					{{end}}
   178  					{{if .WillSign}}
   179  						<div class="item">
   180  							{{svg "octicon-lock" 16 "text green"}}
   181  							{{ctx.Locale.Tr "repo.signing.will_sign" .SigningKey}}
   182  						</div>
   183  					{{else if .IsSigned}}
   184  						<div class="item">
   185  							{{svg "octicon-unlock"}}
   186  							{{ctx.Locale.Tr (printf "repo.signing.wont_sign.%s" .WontSignReason)}}
   187  						</div>
   188  					{{end}}
   189  				{{end}}
   190  				{{template "repo/issue/view_content/update_branch_by_merge" $}}
   191  				{{if .Issue.PullRequest.IsEmpty}}
   192  					<div class="divider"></div>
   193  
   194  					<div class="item">
   195  						{{svg "octicon-alert"}}
   196  						{{ctx.Locale.Tr "repo.pulls.is_empty"}}
   197  					</div>
   198  				{{end}}
   199  
   200  				{{if .AllowMerge}} {{/* user is allowed to merge */}}
   201  					{{$prUnit := .Repository.MustGetUnit $.Context ctx.Consts.RepoUnitTypePullRequests}}
   202  					{{$approvers := (.Issue.PullRequest.GetApprovers ctx)}}
   203  					{{if or $prUnit.PullRequestsConfig.AllowMerge $prUnit.PullRequestsConfig.AllowRebase $prUnit.PullRequestsConfig.AllowRebaseMerge $prUnit.PullRequestsConfig.AllowSquash $prUnit.PullRequestsConfig.AllowFastForwardOnly}}
   204  						{{$hasPendingPullRequestMergeTip := ""}}
   205  						{{if .HasPendingPullRequestMerge}}
   206  							{{$createdPRMergeStr := TimeSinceUnix .PendingPullRequestMerge.CreatedUnix ctx.Locale}}
   207  							{{$hasPendingPullRequestMergeTip = ctx.Locale.Tr "repo.pulls.auto_merge_has_pending_schedule" .PendingPullRequestMerge.Doer.Name $createdPRMergeStr}}
   208  						{{end}}
   209  						<div class="divider"></div>
   210  						<script type="module">
   211  							const issueUrl = window.location.origin + {{$.Issue.Link}};
   212  							const defaultMergeTitle = {{.DefaultMergeMessage}};
   213  							const defaultSquashMergeTitle = {{.DefaultSquashMergeMessage}};
   214  							const defaultMergeMessage = {{if .DefaultMergeBody}}{{.DefaultMergeBody}}{{else}}`Reviewed-on: ${issueUrl}\n` + {{$approvers}}{{end}};
   215  							const defaultSquashMergeMessage = {{if .DefaultSquashMergeBody}}{{.DefaultSquashMergeBody}}{{else}}`Reviewed-on: ${issueUrl}\n` + {{$approvers}}{{end}};
   216  							const mergeForm = {
   217  								'baseLink': {{.Link}},
   218  								'textCancel': {{ctx.Locale.Tr "cancel"}},
   219  								'textDeleteBranch': {{ctx.Locale.Tr "repo.branch.delete" .HeadTarget}},
   220  								'textAutoMergeButtonWhenSucceed': {{ctx.Locale.Tr "repo.pulls.auto_merge_button_when_succeed"}},
   221  								'textAutoMergeWhenSucceed': {{ctx.Locale.Tr "repo.pulls.auto_merge_when_succeed"}},
   222  								'textAutoMergeCancelSchedule': {{ctx.Locale.Tr "repo.pulls.auto_merge_cancel_schedule"}},
   223  								'textClearMergeMessage': {{ctx.Locale.Tr "repo.pulls.clear_merge_message"}},
   224  								'textClearMergeMessageHint': {{ctx.Locale.Tr "repo.pulls.clear_merge_message_hint"}},
   225  								'textMergeCommitId': {{ctx.Locale.Tr "repo.pulls.merge_commit_id"}},
   226  
   227  								'canMergeNow': {{$canMergeNow}},
   228  								'allOverridableChecksOk': {{not $notAllOverridableChecksOk}},
   229  								'emptyCommit': {{.Issue.PullRequest.IsEmpty}},
   230  								'pullHeadCommitID': {{.PullHeadCommitID}},
   231  								'isPullBranchDeletable': {{.IsPullBranchDeletable}},
   232  								'defaultMergeStyle': {{.MergeStyle}},
   233  								'defaultDeleteBranchAfterMerge': {{$prUnit.PullRequestsConfig.DefaultDeleteBranchAfterMerge}},
   234  								'mergeMessageFieldPlaceHolder': {{ctx.Locale.Tr "repo.editor.commit_message_desc"}},
   235  								'defaultMergeMessage': defaultMergeMessage,
   236  
   237  								'hasPendingPullRequestMerge': {{.HasPendingPullRequestMerge}},
   238  								'hasPendingPullRequestMergeTip': {{$hasPendingPullRequestMergeTip}},
   239  							};
   240  
   241  							const generalHideAutoMerge = mergeForm.canMergeNow && mergeForm.allOverridableChecksOk; // if this pr can be merged now, then hide the auto merge
   242  							mergeForm['mergeStyles'] = [
   243  								{
   244  									'name': 'merge',
   245  									'allowed': {{$prUnit.PullRequestsConfig.AllowMerge}},
   246  									'textDoMerge': {{ctx.Locale.Tr "repo.pulls.merge_pull_request"}},
   247  									'mergeTitleFieldText': defaultMergeTitle,
   248  									'mergeMessageFieldText': defaultMergeMessage,
   249  									'hideAutoMerge': generalHideAutoMerge,
   250  								},
   251  								{
   252  									'name': 'rebase',
   253  									'allowed': {{$prUnit.PullRequestsConfig.AllowRebase}},
   254  									'textDoMerge': {{ctx.Locale.Tr "repo.pulls.rebase_merge_pull_request"}},
   255  									'hideMergeMessageTexts': true,
   256  									'hideAutoMerge': generalHideAutoMerge,
   257  								},
   258  								{
   259  									'name': 'rebase-merge',
   260  									'allowed': {{$prUnit.PullRequestsConfig.AllowRebaseMerge}},
   261  									'textDoMerge': {{ctx.Locale.Tr "repo.pulls.rebase_merge_commit_pull_request"}},
   262  									'mergeTitleFieldText': defaultMergeTitle,
   263  									'mergeMessageFieldText': defaultMergeMessage,
   264  									'hideAutoMerge': generalHideAutoMerge,
   265  								},
   266  								{
   267  									'name': 'squash',
   268  									'allowed': {{$prUnit.PullRequestsConfig.AllowSquash}},
   269  									'textDoMerge': {{ctx.Locale.Tr "repo.pulls.squash_merge_pull_request"}},
   270  									'mergeTitleFieldText': defaultSquashMergeTitle,
   271  									'mergeMessageFieldText': {{.GetCommitMessages}} + defaultSquashMergeMessage,
   272  									'hideAutoMerge': generalHideAutoMerge,
   273  								},
   274  								{
   275  									'name': 'fast-forward-only',
   276  									'allowed': {{and $prUnit.PullRequestsConfig.AllowFastForwardOnly (eq .Issue.PullRequest.CommitsBehind 0)}},
   277  									'textDoMerge': {{ctx.Locale.Tr "repo.pulls.fast_forward_only_merge_pull_request"}},
   278  									'hideMergeMessageTexts': true,
   279  									'hideAutoMerge': generalHideAutoMerge,
   280  								},
   281  								{
   282  									'name': 'manually-merged',
   283  									'allowed': {{$prUnit.PullRequestsConfig.AllowManualMerge}},
   284  									'textDoMerge': {{ctx.Locale.Tr "repo.pulls.merge_manually"}},
   285  									'hideMergeMessageTexts': true,
   286  									'hideAutoMerge': true,
   287  								}
   288  							];
   289  							window.config.pageData.pullRequestMergeForm = mergeForm;
   290  						</script>
   291  
   292  						{{$showGeneralMergeForm = true}}
   293  						<div id="pull-request-merge-form"></div>
   294  					{{else}}
   295  						{{/* no merge style was set in repo setting: not or ($prUnit.PullRequestsConfig.AllowMerge ...) */}}
   296  						<div class="divider"></div>
   297  						<div class="item text red">
   298  							{{svg "octicon-x"}}
   299  							{{ctx.Locale.Tr "repo.pulls.no_merge_desc"}}
   300  						</div>
   301  						<div class="item">
   302  							{{svg "octicon-info"}}
   303  							{{ctx.Locale.Tr "repo.pulls.no_merge_helper"}}
   304  						</div>
   305  					{{end}} {{/* end if the repo was set to use any merge style */}}
   306  				{{else}}
   307  					{{/* user is not allowed to merge */}}
   308  					<div class="divider"></div>
   309  					<div class="item">
   310  						{{svg "octicon-info"}}
   311  						{{ctx.Locale.Tr "repo.pulls.no_merge_access"}}
   312  					</div>
   313  				{{end}} {{/* end if user is allowed to merge or not */}}
   314  			{{else}}
   315  				{{/* Merge conflict without specific file. Suggest manual merge, only if all reviews and status checks OK. */}}
   316  				{{if .IsBlockedByApprovals}}
   317  					<div class="item text red">
   318  						{{svg "octicon-x"}}
   319  					{{ctx.Locale.Tr "repo.pulls.blocked_by_approvals" .GrantedApprovals .ProtectedBranch.RequiredApprovals}}
   320  					</div>
   321  				{{else if .IsBlockedByRejection}}
   322  					<div class="item text red">
   323  						{{svg "octicon-x"}}
   324  						{{ctx.Locale.Tr "repo.pulls.blocked_by_rejection"}}
   325  					</div>
   326  				{{else if .IsBlockedByOfficialReviewRequests}}
   327  					<div class="item text red">
   328  						{{svg "octicon-x"}}
   329  						{{ctx.Locale.Tr "repo.pulls.blocked_by_official_review_requests"}}
   330  					</div>
   331  				{{else if .IsBlockedByOutdatedBranch}}
   332  					<div class="item text red">
   333  						{{svg "octicon-x"}}
   334  						{{ctx.Locale.Tr "repo.pulls.blocked_by_outdated_branch"}}
   335  					</div>
   336  				{{else if .IsBlockedByChangedProtectedFiles}}
   337  					<div class="item text red">
   338  						{{svg "octicon-x"}}
   339  						{{ctx.Locale.TrN $.ChangedProtectedFilesNum "repo.pulls.blocked_by_changed_protected_files_1" "repo.pulls.blocked_by_changed_protected_files_n"}}
   340  					</div>
   341  					<ul>
   342  						{{range .ChangedProtectedFiles}}
   343  						<li>{{.}}</li>
   344  						{{end}}
   345  					</ul>
   346  				{{else if and .EnableStatusCheck (not .RequiredStatusCheckState.IsSuccess)}}
   347  					<div class="item text red">
   348  						{{svg "octicon-x"}}
   349  						{{ctx.Locale.Tr "repo.pulls.required_status_check_failed"}}
   350  					</div>
   351  				{{else if and .RequireSigned (not .WillSign)}}
   352  					<div class="item text red">
   353  						{{svg "octicon-x"}}
   354  						{{ctx.Locale.Tr "repo.pulls.require_signed_wont_sign"}}
   355  					</div>
   356  				{{else}}
   357  					<div class="item text red">
   358  						{{svg "octicon-x"}}
   359  						{{ctx.Locale.Tr "repo.pulls.cannot_auto_merge_desc"}}
   360  					</div>
   361  					<div class="item">
   362  						{{svg "octicon-info"}}
   363  						{{ctx.Locale.Tr "repo.pulls.cannot_auto_merge_helper"}}
   364  					</div>
   365  				{{end}}
   366  			{{end}}{{/* end if: pull request status */}}
   367  
   368  			{{/*
   369  			Manually Merged is not a well-known feature, it is used to mark a non-mergeable PR (already merged, conflicted) as merged
   370  			To test it:
   371  			* Enable "Manually Merged" feature in the Repository Settings
   372  			* Create a pull request, either:
   373  			* - Merge the pull request branch locally and push the merged commit to Gitea
   374  			* - Make some conflicts between the base branch and the pull request branch
   375  			* Then the Manually Merged form will be shown in the merge form
   376  			*/}}
   377  			{{if and $.StillCanManualMerge (not $showGeneralMergeForm)}}
   378  				<div class="divider"></div>
   379  				<form class="ui form form-fetch-action" action="{{.Link}}/merge" method="post">{{/* another similar form is in PullRequestMergeForm.vue*/}}
   380  					{{.CsrfTokenHtml}}
   381  					<div class="field">
   382  						<input type="text" name="merge_commit_id" placeholder="{{ctx.Locale.Tr "repo.pulls.merge_commit_id"}}">
   383  					</div>
   384  					<button class="ui red button" type="submit" name="do" value="manually-merged">
   385  						{{ctx.Locale.Tr "repo.pulls.merge_manually"}}
   386  					</button>
   387  				</form>
   388  			{{end}}
   389  
   390  			{{if and .Issue.PullRequest.HeadRepo (not .Issue.PullRequest.HasMerged) (not .Issue.IsClosed)}}
   391  				{{template "repo/issue/view_content/pull_merge_instruction" dict "PullRequest" .Issue.PullRequest "ShowMergeInstructions" .ShowMergeInstructions}}
   392  			{{end}}
   393  		</div>
   394  	</div>
   395  </div>
   396  {{end}}