gitea源码

pull_merge_box.tmpl 17KB

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