You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pull.tmpl 17KB

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