feat(ui): commit view redesign for pull request page (#7948)

Co-authored-by: 0ko <0ko@noreply.codeberg.org>
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7948
Reviewed-by: 0ko <0ko@noreply.codeberg.org>
This commit is contained in:
Yashwanth Rathakrishnan
2026-06-02 20:12:32 +02:00
committed by 0ko
co-authored by 0ko
parent 1d12151086
commit cce8152879
16 changed files with 402 additions and 62 deletions
+15
View File
@@ -28,6 +28,21 @@
</div>
</td>
<td class="sha">
{{$class := "ui sha label"}}
{{if .Signature}}
{{$class = (print $class " isSigned")}}
{{if .Verification.Verified}}
{{if eq .Verification.TrustStatus "trusted"}}
{{$class = (print $class " isVerified")}}
{{else if eq .Verification.TrustStatus "untrusted"}}
{{$class = (print $class " isVerifiedUntrusted")}}
{{else}}
{{$class = (print $class " isVerifiedUnmatched")}}
{{end}}
{{else if .Verification.Warning}}
{{$class = (print $class " isWarning")}}
{{end}}
{{end}}
{{$commitShaLink := ""}}
{{if $.PageIsWiki}}
{{$commitShaLink = (printf "%s/wiki/commit/%s" $commitRepoLink (PathEscape .ID.String))}}
+23 -24
View File
@@ -1,27 +1,22 @@
<h4 class="ui top attached header commits-table tw-flex tw-items-center tw-justify-between">
<div class="commits-table-left tw-flex tw-items-center">
{{if or .PageIsCommits (gt .CommitCount 0)}}
{{ctx.Locale.TrPluralString .CommitCount "counters.n_commits" (ctx.Locale.PrettyNumber .CommitCount)}}
{{else if .IsNothingToCompare}}
{{ctx.Locale.Tr "repo.commits.nothing_to_compare"}}
{{else}}
{{ctx.Locale.Tr "repo.commits.no_commits" $.BaseBranch $.HeadBranch}}
{{end}}
</div>
{{if .IsDiffCompare}}
<div class="commits-table-right tw-whitespace-nowrap">
<a href="{{$.CommitRepoLink}}/commit/{{.BeforeCommitID | PathEscape}}" class="primary sha label tw-mx-0">
<span class="shortsha">{{if not .BaseIsCommit}}{{if .BaseIsBranch}}{{svg "octicon-git-branch"}}{{else if .BaseIsTag}}{{svg "octicon-tag"}}{{end}}{{.BaseBranch}}{{else}}{{ShortSha .BaseBranch}}{{end}}</span>
</a>
...
<a href="{{$.CommitRepoLink}}/commit/{{.AfterCommitID | PathEscape}}" class="primary sha label tw-mx-0">
<span class="shortsha">{{if not .HeadIsCommit}}{{if .HeadIsBranch}}{{svg "octicon-git-branch"}}{{else if .HeadIsTag}}{{svg "octicon-tag"}}{{end}}{{.HeadBranch}}{{else}}{{ShortSha .HeadBranch}}{{end}}</span>
</a>
</div>
{{end}}
</h4>
{{if .PageIsCommits}}
<h4 class="ui top attached header commits-table tw-flex tw-items-center tw-justify-between">
<div class="commits-table-left tw-flex tw-items-center">
{{if or .PageIsCommits (gt .CommitCount 0)}}
{{ctx.Locale.TrPluralString .CommitCount "counters.n_commits" (ctx.Locale.PrettyNumber .CommitCount)}}
{{else if .IsNothingToCompare}}
{{ctx.Locale.Tr "repo.commits.nothing_to_compare"}}
{{else}}
{{ctx.Locale.Tr "repo.commits.no_commits" $.BaseBranch $.HeadBranch}}
{{end}}
</div>
{{if .IsDiffCompare}}
<div class="commits-table-right tw-whitespace-nowrap">
<a href="{{$.CommitRepoLink}}/commit/{{.BeforeCommitID | PathEscape}}" class="ui green sha label tw-mx-0">{{if not .BaseIsCommit}}{{if .BaseIsBranch}}{{svg "octicon-git-branch"}}{{else if .BaseIsTag}}{{svg "octicon-tag"}}{{end}}{{.BaseBranch}}{{else}}{{ShortSha .BaseBranch}}{{end}}</a>
...
<a href="{{$.CommitRepoLink}}/commit/{{.AfterCommitID | PathEscape}}" class="ui green sha label tw-mx-0">{{if not .HeadIsCommit}}{{if .HeadIsBranch}}{{svg "octicon-git-branch"}}{{else if .HeadIsTag}}{{svg "octicon-tag"}}{{end}}{{.HeadBranch}}{{else}}{{ShortSha .HeadBranch}}{{end}}</a>
</div>
{{end}}
</h4>
<div class="ui attached segment">
<form class="ignore-dirty" action="{{.RepoLink}}/commits/{{.BranchNameSubURL}}/search">
<div class="ui small fluid action input">
@@ -34,7 +29,11 @@
{{end}}
{{if and .Commits (gt .CommitCount 0)}}
{{template "repo/commits_list" .}}
{{if .PageIsPullCommits}}
{{template "repo/pulls/commits_list" .}}
{{else}}
{{template "repo/commits_list" .}}
{{end}}
{{end}}
{{if .OldFilename}}
+114
View File
@@ -0,0 +1,114 @@
{{$commitRepoLink := $.RepoLink}}
{{if $.CommitRepoLink}}{{$commitRepoLink = $.CommitRepoLink}}{{end}}
{{$prevDate := ""}}
{{range .Commits}}
{{$commitTime := .Committer.When}}
{{if not $commitTime}}{{$commitTime = .Author.When}}{{end}}
{{$commitDate := $commitTime.Format "2006-01-02"}}
{{if ne $commitDate $prevDate}}
{{if ne $prevDate ""}}</div></article>{{end}} <!-- close previous date group -->
{{$prevDate = $commitDate}}
<!-- Start a new commit group -->
<article class="commit-group">
<h4>{{DateUtils.AbsoluteShortWithDay $commitTime}}</h4>
<div class="commits tw-divide-y tw-divide-[--color-secondary]">
{{end}}
<div class="commit">
<div class="author">
{{$userName := .Author.Name}}
{{if .User}}
{{if and .User.FullName DefaultShowFullName}}
{{$userName = .User.FullName}}
{{end}}
{{ctx.AvatarUtils.Avatar .User 28}}<a class="muted author-name" href="{{.User.HomeLink}}">{{$userName}}</a>
{{else}}
{{ctx.AvatarUtils.AvatarByEmail .Author.Email .Author.Name 28}}
<span class="author-name">{{$userName}}</span>
{{end}}
</div>
<div class="message">
{{$commitLink := (printf "%s/pulls/%d/commits/%s" $commitRepoLink $.Issue.Index (PathEscape .ID.String))}}
<div class="message-wrapper">
{{RenderCommitMessageLinkSubject $.Context .Message $commitLink ($.Repository.ComposeMetas ctx)}}
{{if IsMultilineCommitMessage .Message}}
<button class="ui button js-toggle-commit-body ellipsis-button" aria-expanded="false">...</button>
{{end}}
<span class="ci-status">
{{template "repo/commit_statuses" dict "Status" .Status "Statuses" .Statuses}}
</span>
{{if IsMultilineCommitMessage .Message}}
<pre class="commit-body tw-hidden">{{RenderCommitBody $.Context .Message ($.Repository.ComposeMetas ctx)}}</pre>
{{end}}
</div>
</div>
<div class="actions">
<div class="button-sequence">
{{$commitShaLink := (printf "%s/pulls/%d/commits/%s" $commitRepoLink $.Issue.Index (PathEscape .ID.String))}}
{{template "repo/shabox" (dict
"sha1" .ID.String
"commitLink" $commitShaLink
"signature" .Signature
"verification" .Verification
)}}
<button class="btn interact-bg tw-p-2" data-clipboard-text="{{.ID}}">
{{svg "octicon-copy"}}
</button>
</div>
<details class="dropdown dir-rtl">
<summary class="border" aria-label="{{ctx.Locale.Tr "toggle_menu"}}">
{{svg "octicon-kebab-horizontal"}}
</summary>
<div class="content">
<ul>
{{if $.FileName}}
<li>
<a
class="interact item"
data-tooltip-content="{{ctx.Locale.Tr "repo.commits.view_single_diff"}}"
href="{{printf "%s/commit/%s?files=%s" $commitRepoLink (PathEscape .ID.String) (PathEscapeSegments $.FileName)}}">
{{svg "octicon-file-diff"}}
</a>
</li>
{{end}}
<li>
<a
class="interact item"
data-tooltip-content="{{ctx.Locale.Tr "repo.commits.view_path"}}"
href="{{if $.FileName}}{{printf "%s/src/commit/%s/%s" $commitRepoLink (PathEscape .ID.String) (PathEscapeSegments $.FileName)}}{{else}}{{printf "%s/src/commit/%s" $commitRepoLink (PathEscape .ID.String)}}{{end}}">
{{svg "octicon-file-code"}} {{ctx.Locale.Tr "repo.commits.view_path"}}
</a>
</li>
</ul>
</div>
</details>
</div>
<div class="date">
{{if .Committer}}{{DateUtils.TimeSince .Committer.When}}{{else}}{{DateUtils.TimeSince .Author.When}}{{end}}
</div>
<div class="commit-buttons">
<button class="btn interact-bg tw-p-2" data-tooltip-content="{{ctx.Locale.Tr "copy_hash"}}" data-clipboard-text="{{.ID}}">{{svg "octicon-copy"}}</button>
{{if $.FileName}}
<a
class="btn interact-bg tw-p-2"
data-tooltip-content="{{ctx.Locale.Tr "repo.commits.view_single_diff"}}"
href="{{printf "%s/commit/%s?files=%s" $commitRepoLink (PathEscape .ID.String) (PathEscapeSegments $.FileName)}}">
{{svg "octicon-file-diff"}}
</a>
{{end}}
<a
class="btn interact-bg tw-p-2"
data-tooltip-content="{{ctx.Locale.Tr "repo.commits.view_path"}}"
href="{{if $.FileName}}{{printf "%s/src/commit/%s/%s" $commitRepoLink (PathEscape .ID.String) (PathEscapeSegments $.FileName)}}{{else}}{{printf "%s/src/commit/%s" $commitRepoLink (PathEscape .ID.String)}}{{end}}">
{{svg "octicon-file-code"}}
</a>
</div>
</div>
{{end}}
</div></div> <!-- Final group close -->
+3 -1
View File
@@ -1,7 +1,9 @@
{{if .IsSigned}}
<style>
.comment,
.commit-summary,
.singular-commit,
.commit-header,
.message-wrapper,
.commit-body {
.mention[href="{{AppSubUrl}}/{{.SignedUser.Name}}" i] {
background-color: var(--color-primary-alpha-30);