Refactor pull request view (7) (#37524)

Almost done

`pull_merge_box.tmpl` only has about 80 lines now, and (almost) all
variable accesses are strictly typed.

---------

Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: Claude (Opus 4.7) <noreply@anthropic.com>
Co-authored-by: Nicolas <bircni@icloud.com>
This commit is contained in:
wxiaoguang
2026-05-05 04:13:38 +08:00
committed by GitHub
parent 89a49de0fd
commit a90d5dd131
11 changed files with 439 additions and 380 deletions
@@ -7,219 +7,67 @@
data-pull-link="{{$.Issue.Link}}"
{{end}}
>
{{$statusCheckData := .StatusCheckData}}
{{$requiredStatusCheckState := $statusCheckData.RequiredChecksState}}
<div class="timeline-avatar {{$data.TimelineIconClass}}">{{svg "octicon-git-merge" 40}}</div>
<div class="content">
<div class="ui segment fitted avatar-content-left-arrow">
<div class="merge-section flex-divided-list flex-items-block items-px-default">
{{if .LatestCommitStatus}}
{{template "repo/issue/view_content/pull_merge_status_checks" (dict
"CommitStatuses" .LatestCommitStatuses
"StatusCheckData" $statusCheckData
)}}
<div class="merge-section flex-divided-list items-px-default">
{{if $data.ShowStatusCheck}}
{{template "repo/issue/view_content/pull_merge_status_checks" (dict "StatusCheckData" $data.StatusCheckData)}}
{{end}}
{{if .Issue.PullRequest.HasMerged}}
{{if .IsPullBranchDeletable}}
<div class="item item-section text tw-flex-1">
<div class="item-section-left">
<h3 class="tw-mb-2">
{{ctx.Locale.Tr "repo.pulls.merged_success"}}
</h3>
<div class="merge-section-info">
{{ctx.Locale.Tr "repo.pulls.merged_info_text" (HTMLFormat "<code>%s</code>" .HeadTarget)}}
</div>
</div>
<div class="item-section-right">
{{if $data.ClosedInfoTitle}}
<div class="item flex-left-right">
<div>
<h3 class="tw-mb-2">{{$data.ClosedInfoTitle}}</h3>
<div>{{$data.ClosedInfoBody}}</div>
</div>
{{if $data.IsPullBranchDeletable}}
<div>
<button class="ui button link-action delete-branch-after-merge" data-url="{{.DeleteBranchLink}}">{{ctx.Locale.Tr "repo.branch.delete_html"}}</button>
</div>
</div>
{{end}}
</div>
{{end}}
{{range $infoSection := $data.InfoSections}}
{{if $infoSection.InfoItems}}
<div class="item">
{{range $infoItem := $infoSection.InfoItems}}
<div class="flex-text-block {{$infoItem.ItemClass}}">{{$infoItem.SvgIconHTML}} {{$infoItem.InfoHTML}}</div>
{{if $infoItem.ListItems}}
<ul class="tw-pl-[36px]">{{/* align with the info icon and text */}}
{{range $listItem := $infoItem.ListItems}}
<li>{{$listItem}}</li>
{{end}}
</ul>
{{end}}
{{end}}
</div>
{{end}}
{{else if .Issue.IsClosed}}
<div class="item item-section text tw-flex-1">
<div class="item-section-left">
<h3 class="tw-mb-2">{{ctx.Locale.Tr "repo.pulls.closed"}}</h3>
<div class="merge-section-info">
{{if .IsPullRequestBroken}}
{{ctx.Locale.Tr "repo.pulls.cant_reopen_deleted_branch"}}
{{else}}
{{ctx.Locale.Tr "repo.pulls.reopen_to_merge"}}
{{end}}
</div>
</div>
{{if and .IsPullBranchDeletable (not .IsPullRequestBroken)}}
<div class="item-section-right">
<button class="ui button link-action delete-branch-after-merge" data-url="{{.DeleteBranchLink}}">{{ctx.Locale.Tr "repo.branch.delete_html"}}</button>
</div>
{{end}}
</div>
{{else if .IsPullFilesConflicted}}
{{end}}
{{if $data.ShowUpdatePullInfo}}
<div class="item">
{{svg "octicon-x"}}
{{ctx.Locale.Tr "repo.pulls.files_conflicted"}}
{{template "repo/issue/view_content/update_branch_by_merge" (dict "MergeBoxData" $data "Issue" $.Issue)}}
</div>
<ul class="item">
{{range .ConflictedFiles}}
<li>{{.}}</li>
{{else}}
<li>{{ctx.Locale.Tr "repo.pulls.files_conflicted_no_listed_files"}}</li>
{{end}}
</ul>
{{else if .IsPullRequestBroken}}
<div class="item">
{{svg "octicon-x"}}
{{ctx.Locale.Tr "repo.pulls.data_broken"}}
</div>
{{else if .IsPullWorkInProgress}}
<div class="item">
<div class="item-section-left flex-text-inline tw-flex-1">
{{svg "octicon-x"}}
{{ctx.Locale.Tr "repo.pulls.cannot_merge_work_in_progress"}}
{{end}}
{{if $.IsPullWorkInProgress}}
<div class="item flex-left-right">
<div class="flex-text-block">
{{svg "octicon-x"}} {{ctx.Locale.Tr "repo.pulls.cannot_merge_work_in_progress"}}
</div>
{{if or .HasIssuesOrPullsWritePermission .IsIssuePoster}}
<button class="ui compact button" data-global-init="initPullRequestWipToggle" data-title="{{.Issue.Title}}" data-wip-prefix="{{.WorkInProgressPrefix}}" data-update-url="{{.Issue.Link}}/title">
{{ctx.Locale.Tr "repo.pulls.remove_prefix" .WorkInProgressPrefix}}
</button>
<button class="ui compact button" data-global-init="initPullRequestWipToggle" data-title="{{.Issue.Title}}" data-wip-prefix="{{.WorkInProgressPrefix}}" data-update-url="{{.Issue.Link}}/title">
{{ctx.Locale.Tr "repo.pulls.remove_prefix" .WorkInProgressPrefix}}
</button>
{{end}}
</div>
{{template "repo/issue/view_content/update_branch_by_merge" $}}
{{else if .Issue.PullRequest.IsChecking}}
<div class="item">
{{svg "gitea-running" 16 "rotate-clockwise"}}
{{ctx.Locale.Tr "repo.pulls.is_checking"}}
</div>
{{else if .Issue.PullRequest.IsAncestor}}
<div class="item">
{{svg "octicon-alert"}}
{{ctx.Locale.Tr "repo.pulls.is_ancestor"}}
</div>
{{else}}
{{if .IsBlockedByApprovals}}
<div class="item">
{{svg "octicon-x"}}
{{if .RequireApprovalsWhitelist}}
{{ctx.Locale.Tr "repo.pulls.blocked_by_approvals_whitelisted" .GrantedApprovals .ProtectedBranch.RequiredApprovals}}
{{else}}
{{ctx.Locale.Tr "repo.pulls.blocked_by_approvals" .GrantedApprovals .ProtectedBranch.RequiredApprovals}}
{{end}}
</div>
{{else if .IsBlockedByRejection}}
<div class="item">
{{svg "octicon-x"}}
{{ctx.Locale.Tr "repo.pulls.blocked_by_rejection"}}
</div>
{{else if .IsBlockedByOfficialReviewRequests}}
<div class="item">
{{svg "octicon-x"}}
{{ctx.Locale.Tr "repo.pulls.blocked_by_official_review_requests"}}
</div>
{{else if .IsBlockedByOutdatedBranch}}
<div class="item">
{{svg "octicon-x"}}
{{ctx.Locale.Tr "repo.pulls.blocked_by_outdated_branch"}}
</div>
{{else if .IsBlockedByChangedProtectedFiles}}
<div class="item">
{{svg "octicon-x"}}
{{ctx.Locale.TrN $.ChangedProtectedFilesNum "repo.pulls.blocked_by_changed_protected_files_1" "repo.pulls.blocked_by_changed_protected_files_n"}}
</div>
<ul class="item">
{{range .ChangedProtectedFiles}}
<li>{{.}}</li>
{{end}}
</ul>
{{else if and .EnableStatusCheck (or $requiredStatusCheckState.IsError $requiredStatusCheckState.IsFailure)}}
<div class="item">
{{svg "octicon-x"}}
{{ctx.Locale.Tr "repo.pulls.required_status_check_failed"}}
</div>
{{else if and .EnableStatusCheck (not $requiredStatusCheckState.IsSuccess)}}
<div class="item">
{{svg "octicon-x"}}
{{ctx.Locale.Tr "repo.pulls.required_status_check_missing"}}
</div>
{{else if and .AllowMerge .RequireSigned (not .WillSign)}}
<div class="item">
{{svg "octicon-x"}}
{{ctx.Locale.Tr "repo.pulls.require_signed_wont_sign"}}
</div>
<div class="item">
{{svg "octicon-unlock"}}
{{ctx.Locale.Tr (printf "repo.signing.wont_sign.%s" .WontSignReason)}}
</div>
{{else if not .Issue.PullRequest.IsStatusMergeable}}
<div class="item tw-text-red">
{{svg "octicon-x"}}
{{ctx.Locale.Tr "repo.pulls.cannot_auto_merge_desc"}}
</div>
<div class="item">
{{svg "octicon-info"}}
{{ctx.Locale.Tr "repo.pulls.cannot_auto_merge_helper"}}
</div>
{{end}}
{{$notAllOverridableChecksOk := $data.HasOverridableBlockers}}
{{$canMergeNow := $data.CanMergeNow}}
{{if $canMergeNow}}
{{if $notAllOverridableChecksOk}}
<div class="item">
{{svg "octicon-dot-fill"}}
{{ctx.Locale.Tr "repo.pulls.required_status_check_administrator"}}
</div>
{{else}}
<div class="item">
{{svg "octicon-check"}}
{{ctx.Locale.Tr "repo.pulls.can_auto_merge_desc"}}
</div>
{{end}}
{{if .WillSign}}
<div class="item">
{{svg "octicon-lock" 16 "tw-text-green"}}
{{ctx.Locale.Tr "repo.signing.will_sign" .SigningKeyMergeDisplay}}
</div>
{{else if .IsSigned}}
<div class="item">
{{svg "octicon-unlock"}}
{{ctx.Locale.Tr (printf "repo.signing.wont_sign.%s" .WontSignReason)}}
</div>
{{end}}
{{end}}
{{if .Issue.PullRequest.IsEmpty}}
<div class="item">
{{svg "octicon-alert"}}
{{ctx.Locale.Tr "repo.pulls.is_empty"}}
</div>
{{end}}
{{template "repo/issue/view_content/update_branch_by_merge" (dict "MergeBoxData" $data "Issue" $.Issue)}}
{{if not .AllowMerge}} {{/* user is allowed to merge */}}
{{/* user is not allowed to merge */}}
<div class="item">
{{svg "octicon-info"}}
{{ctx.Locale.Tr "repo.pulls.no_merge_access"}}
</div>
{{end}}
{{end}}{{/* end if: pull request status */}}
{{end}}
{{if $data.MergeFormProps}}
{{/* The merge form is a Vue component. After mounted, it has a button for choosing merge style, so make it have min-height to avoid layout shifting */}}
<div class="item">
<div id="pull-request-merge-form" class="tw-min-h-[40px] tw-w-full" data-merge-form-props="{{JsonUtils.EncodeToString $data.MergeFormProps}}"></div>
</div>
{{else if and .AllowMerge .Issue.PullRequest.IsStatusMergeable}}
{{/* no merge style was set in repo setting */}}
<div class="item tw-text-red">
{{svg "octicon-x"}}
{{ctx.Locale.Tr "repo.pulls.no_merge_desc"}}
</div>
<div class="item">
{{svg "octicon-info"}}
{{ctx.Locale.Tr "repo.pulls.no_merge_helper"}}
</div>
{{end}}
{{if $data.ShowPullCommands}}
@@ -1,10 +1,9 @@
{{/* Template Attributes:
* CommitStatuses: all commit status elements
* StatusCheckData: additional status check data, see backend pullCommitStatusCheckData struct
* StatusCheckData: see backend pullCommitStatusCheckData struct
*/}}
{{$commitStatuses := $.CommitStatuses}}
{{$statusCheckData := $.StatusCheckData}}
{{if $statusCheckData}}
{{$commitStatuses := $statusCheckData.PullCommitStatuses}}
<div class="item flex-left-right commit-status-toggle">
<div>{{$statusCheckData.CommitStatusCheckPrompt ctx.Locale}}</div>
<button data-global-click="onCommitStatusChecksToggle" class="btn interact-fg"
@@ -1,35 +1,33 @@
{{$data := $.MergeBoxData}}
{{$issue := $.Issue}}
{{if $data.ShowUpdatePullInfo}}
<div class="item flex-left-right">
<div class="flex-text-block">
{{svg "octicon-alert"}}
{{ctx.Locale.Tr "repo.pulls.outdated_with_base_branch"}}
</div>
<div>
{{if and $data.UpdateAllowed $data.UpdateByRebaseAllowed}}
<div id="update-pr-branch-with-base" class="ui buttons">
<button class="ui button" data-do="{{$issue.Link}}/update">
<span class="button-text">
{{ctx.Locale.Tr "repo.pulls.update_branch"}}
</span>
</button>
<div class="ui dropdown icon button">
{{svg "octicon-triangle-down"}}
<div class="menu">
<a class="item active selected" data-do="{{$issue.Link}}/update">{{ctx.Locale.Tr "repo.pulls.update_branch"}}</a>
<a class="item" data-do="{{$issue.Link}}/update?style=rebase">{{ctx.Locale.Tr "repo.pulls.update_branch_rebase"}}</a>
</div>
<div class="tw-w-full flex-left-right">
<div class="flex-text-block">
{{svg "octicon-alert"}}
{{ctx.Locale.Tr "repo.pulls.outdated_with_base_branch"}}
</div>
<div>
{{if and $data.UpdateAllowed $data.UpdateByRebaseAllowed}}
<div id="update-pr-branch-with-base" class="ui buttons">
<button class="ui button" data-do="{{$issue.Link}}/update">
<span class="button-text">
{{ctx.Locale.Tr "repo.pulls.update_branch"}}
</span>
</button>
<div class="ui dropdown icon button">
{{svg "octicon-triangle-down"}}
<div class="menu">
<a class="item active selected" data-do="{{$issue.Link}}/update">{{ctx.Locale.Tr "repo.pulls.update_branch"}}</a>
<a class="item" data-do="{{$issue.Link}}/update?style=rebase">{{ctx.Locale.Tr "repo.pulls.update_branch_rebase"}}</a>
</div>
</div>
{{end}}
{{if and $data.UpdateAllowed (not $data.UpdateByRebaseAllowed)}}
<form action="{{$issue.Link}}/update" method="post">
<button class="ui compact button">
<span class="ui text">{{ctx.Locale.Tr "repo.pulls.update_branch"}}</span>
</button>
</form>
{{end}}
</div>
</div>
{{end}}
{{if and $data.UpdateAllowed (not $data.UpdateByRebaseAllowed)}}
<form action="{{$issue.Link}}/update" method="post">
<button class="ui compact button">
<span class="ui text">{{ctx.Locale.Tr "repo.pulls.update_branch"}}</span>
</button>
</form>
{{end}}
</div>
{{end}}
</div>