diff --git a/src/code/diff.css b/src/code/diff.css index c2d5027..dcbb3fc 100644 --- a/src/code/diff.css +++ b/src/code/diff.css @@ -422,3 +422,118 @@ .diff-file-body .data-table { background: var(--bgColor-default); } + +/* PR files for a single commit: github.com's commit message Box above the diff (templates/custom/footer.tmpl puts it + in place of Gitea's "showing only changes of commit X" banner). Measured on github.com 2026-10-16: muted band with + the 16px semibold title, 12px mono body and a row with the Prev / Next ButtonGroup left and "Browse files" right; + a default-background row below with the author sentence and "commit " + copy button in muted 12px. */ +.gh-pr-commit { + margin-bottom: var(--base-size-16); + overflow: hidden; + border: var(--borderWidth-thin) solid var(--borderColor-default); + border-radius: var(--borderRadius-medium); + background: var(--bgColor-default); +} + +.gh-pr-commit-message { + display: flex; + flex-direction: column; + gap: var(--base-size-8); + padding: var(--base-size-16); + border-bottom: var(--borderWidth-thin) solid var(--borderColor-default); + background: var(--bgColor-muted); +} + +.gh-pr-commit-title { + margin: 0; + color: var(--fgColor-default); + font-size: var(--text-title-size-small); + font-weight: var(--base-text-weight-semibold); + line-height: var(--text-title-lineHeight-small); + overflow-wrap: anywhere; +} + +.gh-pr-commit-body { + margin: 0; + color: var(--fgColor-default); + font-family: var(--fontStack-monospace); + font-size: var(--text-body-size-small); + line-height: var(--text-body-lineHeight-small); + white-space: pre-wrap; + overflow-wrap: anywhere; +} + +/* a body longer than 10 lines shows its first 8 and fades out over the last 2 (footer.tmpl adds .is-collapsed) */ +.gh-pr-commit-body.is-collapsed { + max-height: 8lh; + overflow: hidden; + mask-image: linear-gradient(to bottom, currentColor calc(100% - 2lh), transparent); +} + +.gh-pr-commit-toggle { + display: inline-flex; + align-self: flex-start; + padding: 0; + border: 0; + background: none; + color: var(--fgColor-accent); + font-size: var(--text-body-size-small); + cursor: pointer; +} + +.gh-pr-commit-toggle:hover { + text-decoration: underline; +} + +.gh-pr-commit-toggle > span { + display: inline-flex; + align-items: center; + gap: var(--base-size-4); +} + +.gh-pr-commit-toggle[aria-expanded="true"] > .gh-pr-commit-toggle-more, +.gh-pr-commit-toggle[aria-expanded="false"] > .gh-pr-commit-toggle-less { + display: none; +} + +.gh-pr-commit-actions { + display: flex; + flex-wrap: wrap; + align-items: center; + justify-content: space-between; + gap: var(--base-size-8); + margin-top: var(--base-size-8); +} + +.gh-pr-commit-meta { + display: flex; + flex-wrap: wrap; + align-items: center; + justify-content: space-between; + gap: var(--base-size-8); + padding: var(--base-size-8) var(--base-size-16); + color: var(--fgColor-muted); + font-size: var(--text-body-size-medium); +} + +.gh-pr-commit-people .avatar { + margin-right: var(--base-size-4); + vertical-align: middle; +} + +.gh-pr-commit-people strong { + color: var(--fgColor-default); + font-weight: var(--base-text-weight-semibold); +} + +.gh-pr-commit-sha { + display: inline-flex; + align-items: center; + gap: var(--base-size-4); + font-family: var(--fontStack-monospace); + font-size: var(--text-body-size-small); +} + +.gh-pr-commit-sha > a { + color: var(--fgColor-default); +} diff --git a/templates/custom/footer.tmpl b/templates/custom/footer.tmpl index 9b50227..20d18f4 100644 --- a/templates/custom/footer.tmpl +++ b/templates/custom/footer.tmpl @@ -15,4 +15,109 @@ .observe(document.body, {childList: true, subtree: true}); })(); +{{- /* PR "Files changed" for a single commit (/pulls/N/commits/): github.com shows the commit's message box + (title, body, Prev / Next ButtonGroup, Browse files; author row with the short SHA) above the diff. Gitea only has + the "showing only changes of commit X" banner (repo/diff/box.tmpl, same in 1.27.3 and 28.1.0), so the box is + rendered here and replaces that banner instead of overriding box.tmpl (which differs between the two versions). + CompareInfo.Commits is newest first (git log base..head): Prev = the item after the current one, Next = the item + before it. */ -}} +{{- if and .PageIsPullFiles .IsShowingOnlySingleCommit .CompareInfo -}} +{{- $prev := "" -}}{{- $next := "" -}}{{- $newer := "" -}}{{- $cur := false -}} +{{- range .CompareInfo.Commits -}} + {{- $id := .ID.String -}} + {{- if and $cur (not $prev) -}}{{- $prev = $id -}}{{- end -}} + {{- if eq $id $.AfterCommitID -}}{{- $cur = . -}}{{- $next = $newer -}}{{- end -}} + {{- $newer = $id -}} +{{- end -}} +{{- if $cur -}} +{{- $query := print "?style=" (Iif $.IsSplitStyle "split" "unified") "&whitespace=" $.WhitespaceBehavior "&show-outdated=" $.ShowOutdatedComments -}} +{{- $author := HTMLFormat "%s%s" (ctx.AvatarUtils.AvatarByEmail $cur.Author.Email $cur.Author.Email 20) $cur.Author.Name -}} +{{- /* github.com's labels in English: Gitea's "Previous" reads "Prev"; other languages keep their translation */ -}} +{{- $prevLabel := ctx.Locale.Tr "repo.issues.previous" -}}{{- if eq (print $prevLabel) "Previous" -}}{{- $prevLabel = "Prev" -}}{{- end -}} +{{- /* likewise "Browse files" for Gitea's English "Browse Source" */ -}} +{{- $browseLabel := ctx.Locale.Tr "repo.diff.browse_source" -}}{{- if eq (print $browseLabel) "Browse Source" -}}{{- $browseLabel = "Browse files" -}}{{- end -}} +{{- $committerIsAuthor := and (eq $cur.Committer.Name $cur.Author.Name) (eq $cur.Committer.Email $cur.Author.Email) -}} + + +{{- end -}} +{{- end -}} {{- end -}} diff --git a/templates/repo/commits_list.tmpl b/templates/repo/commits_list.tmpl index a64ae35..8500c53 100644 --- a/templates/repo/commits_list.tmpl +++ b/templates/repo/commits_list.tmpl @@ -36,7 +36,7 @@ {{$gitCommit.MessageTitle | ctx.RenderUtils.RenderEmoji}} {{else}} - {{$commitLink:= printf "%s/commit/%s" $commitRepoLink (PathEscape $commitID)}} + {{$commitLink:= printf "%s/commit/%s" $commitRepoLink (PathEscape $commitID)}}{{/* gitea-theme-github: on a PR's Commits tab github.com opens the commit inside the PR (Prev / Next, custom/footer.tmpl) from the title too, not only from the SHA; github-* themes only. */}}{{if and $.PageIsPullCommits (StringUtils.HasPrefix ctx.CurrentWebTheme.InternalName "github-")}}{{$commitLink = printf "%s/%s" $commitBaseLink (PathEscape $commitID)}}{{end}} {{ctx.RenderUtils.RenderCommitMessageLinkSubject $gitCommit.MessageUTF8 $commitLink $.Repository}}