feat: Add avatar stacks (#37594)

Parse `Co-authored-by:` trailers from commit messages and surface
contributors as an avatar stack across the commit page, commits list, PR
commits tab, latest-commit row, blame, graph, and dashboard feed.

- Up to 10 visible 20px avatars, GitHub-style overlap (6px first stride,
4px between subsequent), `+N` chip for the rest.
- Label: 1 → name; 2 → `<a> and <b>`; 3+ → `<N> people` opens a Tippy
popup with all participants.
- Names and avatars link to the repo's commits-by-author search; fall
back to profile or `mailto:`.
- Trailer parsing uses `net/mail.ParseAddress`, scans only the trailing
paragraph, filters out the commit's own author/committer.
- Drops the non-standard `Co-committed-by:` emission on squash merge and
web edits.

Devtest: `/devtest/coauthor-avatars`.

Fixes #25521

----
<img width="353" height="277" alt="image"
src="https://github.com/user-attachments/assets/72092ceb-97ca-4b09-9557-0b72d3c5458e"
/>

<img width="533" height="328"
src="https://github.com/user-attachments/assets/11d0c8f8-8b3f-4f2e-9993-879f1c06bcc5"
/>

---------

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: Giteabot <teabot@gitea.io>
This commit is contained in:
bircni
2026-06-08 17:16:22 +00:00
committed by GitHub
co-authored by Claude Opus 4.7 silverwind wxiaoguang Giteabot
parent 2a84831400
commit 54916f708e
44 changed files with 912 additions and 322 deletions
+18
View File
@@ -0,0 +1,18 @@
{{template "devtest/devtest-header"}}
<div class="page-content devtest ui container">
<div>
<h1>Avatar Stack</h1>
<table class="ui basic table">
<thead><tr><th>Scenario</th><th>Rendered</th></tr></thead>
<tbody>
{{range $s := .AvatarStackScenarios}}
<tr>
<td>{{$s.Label}}</td>
<td>{{ctx.RenderUtils.AvatarStackWithNames $s.Data}}</td>
</tr>
{{end}}
</tbody>
</table>
</div>
</div>
{{template "devtest/devtest-footer"}}
+1 -1
View File
@@ -4,7 +4,7 @@
<h1>Commit Sign Badges</h1>
{{range $commit := .MockCommits}}
<div class="flex-text-block tw-my-2">
{{template "repo/commit_sign_badge" dict "Commit" $commit "CommitBaseLink" "/devtest/commit" "CommitSignVerification" $commit.Verification}}
{{template "repo/commit_sign_badge" dict "Commit" $commit.GitCommit "CommitBaseLink" "/devtest/commit" "CommitSignVerification" $commit.Verification}}
{{template "repo/commit_sign_badge" dict "CommitSignVerification" $commit.Verification}}
</div>
{{end}}
+1 -1
View File
@@ -43,7 +43,7 @@
<div class="blame-info">
<div class="blame-data">
<div class="blame-avatar">
{{$row.Avatar}}
{{if $row.AvatarStackData}}{{ctx.RenderUtils.AvatarStack $row.AvatarStackData}}{{end}}
</div>
<div class="blame-message muted-links" title="{{$row.CommitMessage}}">
{{ctx.RenderUtils.RenderCommitMessageLinkSubject $row.CommitMessage $row.CommitURL $.Repository}}
+23
View File
@@ -154,6 +154,29 @@
{{end}}
</div>
{{if .CommitOtherParticipants}}
<div class="flex-text-inline">
<span class="tw-text-text-light">{{ctx.Locale.Tr "repo.diff.coauthored_by"}}</span>
{{range $participant := .CommitOtherParticipants}}
{{$user := $participant.GiteaUser}}
{{$gitIdentity := $participant.GitIdentity}}
{{if $user}}
{{ctx.AvatarUtils.Avatar $user 20}}
<a class="muted" href="{{$user.HomeLink}}"><strong>{{$user.GetDisplayName}}</strong></a>
{{else}}
{{$gitName := $gitIdentity.Name}}
{{$gitEmail := $gitIdentity.Email}}
{{ctx.AvatarUtils.AvatarByEmail $gitEmail $gitName 20}}
{{if $gitEmail}}
<a class="muted" href="mailto:{{$gitEmail}}"><strong>{{$gitName}}</strong></a>
{{else}}
<strong>{{$gitName}}</strong>
{{end}}
{{end}}
{{end}}
</div>
{{end}}
{{if .Verification}}
{{template "repo/commit_sign_badge" dict "CommitSignVerification" .Verification}}
{{end}}
+2 -2
View File
@@ -64,10 +64,10 @@ so this template should be kept as small as possible, DO NOT put large component
{{- if $verified -}}
{{- if and $signingUser $signingUser.ID -}}
<span data-tooltip-content="{{$msgReason}}">{{svg "gitea-lock"}}</span>
<span data-tooltip-content="{{$msgSigningKey}}">{{ctx.AvatarUtils.Avatar $signingUser 16}}</span>
<span data-tooltip-content="{{$msgSigningKey}}">{{ctx.AvatarUtils.Avatar $signingUser 20}}</span>
{{- else -}}
<span data-tooltip-content="{{$msgReason}}">{{svg "gitea-lock-cog"}}</span>
<span data-tooltip-content="{{$msgSigningKey}}">{{ctx.AvatarUtils.AvatarByEmail $signingEmail "" 16}}</span>
<span data-tooltip-content="{{$msgSigningKey}}">{{ctx.AvatarUtils.AvatarByEmail $signingEmail "" 20}}</span>
{{- end -}}
{{- else -}}
<span data-tooltip-content="{{$msgReason}}">{{svg "gitea-unlock"}}</span>
+20 -30
View File
@@ -2,27 +2,21 @@
<table class="ui very basic table unstackable" id="commits-table">
<thead>
<tr>
<th class="three wide">{{ctx.Locale.Tr "repo.commits.author"}}</th>
<th class="four wide">{{ctx.Locale.Tr "repo.commits.author"}}</th>
<th class="two wide sha">{{StringUtils.ToUpper $.Repository.ObjectFormatName}}</th>
<th class="eight wide message">{{ctx.Locale.Tr "repo.commits.message"}}</th>
<th class="seven wide message">{{ctx.Locale.Tr "repo.commits.message"}}</th>
<th class="two wide tw-text-right">{{ctx.Locale.Tr "repo.commits.date"}}</th>
<th class="one wide"></th>
</tr>
</thead>
<tbody class="commit-list">
{{$commitRepoLink := $.RepoLink}}{{if $.CommitRepoLink}}{{$commitRepoLink = $.CommitRepoLink}}{{end}}
{{range $commit := .Commits}}
{{range $commit := $.Commits}}
{{$gitCommit := $commit.GitCommit}}
{{$commitID := $gitCommit.ID.String}}
<tr>
<td class="author">
<span class="author-wrapper">
{{- if .User -}}
{{- ctx.AvatarUtils.Avatar .User 20 "tw-mr-2" -}}
{{- .User.GetShortDisplayNameLinkHTML -}}
{{- else -}}
{{- ctx.AvatarUtils.AvatarByEmail .Author.Email .Author.Name 20 "tw-mr-2" -}}
{{- .Author.Name -}}
{{- end -}}
</span>
{{ctx.RenderUtils.AvatarStackWithNames $commit.AvatarStackData}}
</td>
<td class="sha">
{{$commitBaseLink := ""}}
@@ -33,52 +27,48 @@
{{else}}
{{$commitBaseLink = printf "%s/commit" $commitRepoLink}}
{{end}}
{{template "repo/commit_sign_badge" dict "Commit" . "CommitBaseLink" $commitBaseLink "CommitSignVerification" .Verification}}
{{template "repo/commit_sign_badge" dict "Commit" $gitCommit "CommitBaseLink" $commitBaseLink "CommitSignVerification" .Verification}}
</td>
<td class="message">
<span class="message-wrapper">
{{if $.PageIsWiki}}
<span class="commit-summary {{if gt $commit.ParentCount 1}} grey text{{end}}" title="{{$commit.MessageTitle}}">
{{$commit.MessageTitle | ctx.RenderUtils.RenderEmoji}}
<span class="commit-summary {{if gt $gitCommit.ParentCount 1}} grey text{{end}}" title="{{$gitCommit.MessageTitle}}">
{{$gitCommit.MessageTitle | ctx.RenderUtils.RenderEmoji}}
</span>
{{else}}
{{$commitLink:= printf "%s/commit/%s" $commitRepoLink (PathEscape $commit.ID.String)}}
<span class="commit-summary {{if gt $commit.ParentCount 1}} grey text{{end}}" title="{{$commit.MessageTitle}}">
{{ctx.RenderUtils.RenderCommitMessageLinkSubject $commit.MessageUTF8 $commitLink $.Repository}}
{{$commitLink:= printf "%s/commit/%s" $commitRepoLink (PathEscape $commitID)}}
<span class="commit-summary {{if gt $gitCommit.ParentCount 1}} grey text{{end}}" title="{{$gitCommit.MessageTitle}}">
{{ctx.RenderUtils.RenderCommitMessageLinkSubject $gitCommit.MessageUTF8 $commitLink $.Repository}}
</span>
{{end}}
</span>
{{if $commit.MessageBody}}
{{if $gitCommit.MessageBody}}
<button class="ui button ellipsis-button" aria-expanded="false" data-global-click="onRepoEllipsisButtonClick">...</button>
{{end}}
{{template "repo/commit_statuses" dict "Status" .Status "Statuses" .Statuses}}
{{if $commit.MessageBody}}
<pre class="commit-body tw-hidden">{{ctx.RenderUtils.RenderCommitBody $commit.MessageUTF8 $.Repository}}</pre>
{{if $gitCommit.MessageBody}}
<pre class="commit-body tw-hidden">{{ctx.RenderUtils.RenderCommitBody $gitCommit.MessageUTF8 $.Repository}}</pre>
{{end}}
{{if $.CommitsTagsMap}}
{{range (index $.CommitsTagsMap .ID.String)}}
{{range (index $.CommitsTagsMap $commitID)}}
{{- template "repo/tag/name" dict "AdditionalClasses" "tw-py-0" "RepoLink" $.Repository.Link "TagName" .TagName "IsRelease" (not .IsTag) -}}
{{end}}
{{end}}
</td>
{{if .Committer}}
<td class="tw-text-right">{{DateUtils.TimeSince .Committer.When}}</td>
{{else}}
<td class="tw-text-right">{{DateUtils.TimeSince .Author.When}}</td>
{{end}}
<td class="tw-text-right">{{DateUtils.TimeSince $gitCommit.Committer.When}}</td>
<td class="tw-text-right tw-py-0">
<button class="btn interact-bg tw-p-2 copy-commit-id" data-tooltip-content="{{ctx.Locale.Tr "copy_hash"}}" data-clipboard-text="{{.ID}}">{{svg "octicon-copy"}}</button>
<button class="btn interact-bg tw-p-2 copy-commit-id" data-tooltip-content="{{ctx.Locale.Tr "copy_hash"}}" data-clipboard-text="{{$commitID}}">{{svg "octicon-copy"}}</button>
{{/* at the moment, wiki doesn't support these "view" links like "view at history point" */}}
{{if not $.PageIsWiki}}
{{/* view single file diff */}}
{{if $.FileTreePath}}
<a class="btn interact-bg tw-p-2 view-single-diff" data-tooltip-content="{{ctx.Locale.Tr "repo.commits.view_file_diff"}}"
href="{{$commitRepoLink}}/commit/{{.ID.String}}?files={{$.FileTreePath}}"
href="{{$commitRepoLink}}/commit/{{$commitID}}?files={{$.FileTreePath}}"
>{{svg "octicon-file-diff"}}</a>
{{end}}
{{/* view at history point */}}
{{$viewCommitLink := printf "%s/src/commit/%s" $commitRepoLink (PathEscape .ID.String)}}
{{$viewCommitLink := printf "%s/src/commit/%s" $commitRepoLink (PathEscape $commitID)}}
{{if $.FileTreePath}}{{$viewCommitLink = printf "%s/%s" $viewCommitLink (PathEscapeSegments $.FileTreePath)}}{{end}}
<a class="btn interact-bg tw-p-2 view-commit-path" data-tooltip-content="{{ctx.Locale.Tr "repo.commits.view_path"}}" href="{{$viewCommitLink}}">{{svg "octicon-file-code"}}</a>
{{end}}
+11 -14
View File
@@ -1,35 +1,32 @@
{{$index := 0}}
<div class="timeline-item commits-list">
{{range $commit := .comment.Commits}}
{{range $commit := $.comment.Commits}}
{{$gitCommit := $commit.GitCommit}}
{{$tag := printf "%s-%d" $.comment.HashTag $index}}
{{$index = Eval $index "+" 1}}
<div class="flex-text-block" id="{{$tag}}">{{/*singular-commit*/}}
<span class="badge badge-commit">{{svg "octicon-git-commit"}}</span>
{{if .User}}
<a class="avatar" href="{{.User.HomeLink}}">{{ctx.AvatarUtils.Avatar .User 20}}</a>
{{else}}
{{ctx.AvatarUtils.AvatarByEmail .Author.Email .Author.Name 20}}
{{end}}
{{ctx.RenderUtils.AvatarStack $commit.AvatarStackData}}
{{$commitBaseLink := printf "%s/commit" $.comment.Issue.PullRequest.BaseRepo.Link}}
{{$commitLink:= printf "%s/%s" $commitBaseLink (PathEscape .ID.String)}}
{{$commitLink:= printf "%s/%s" $commitBaseLink (PathEscape $gitCommit.ID.String)}}
<span class="tw-flex-1 tw-font-mono gt-ellipsis" title="{{$commit.MessageTitle}}">
{{- ctx.RenderUtils.RenderCommitMessageLinkSubject $commit.MessageUTF8 $commitLink $.comment.Issue.PullRequest.BaseRepo -}}
<span class="tw-flex-1 tw-font-mono gt-ellipsis" title="{{$gitCommit.MessageTitle}}">
{{- ctx.RenderUtils.RenderCommitMessageLinkSubject $gitCommit.MessageUTF8 $commitLink $.comment.Issue.PullRequest.BaseRepo -}}
</span>
{{if $commit.MessageBody}}
{{if $gitCommit.MessageBody}}
<button class="ui button ellipsis-button show-panel toggle" data-panel="[data-singular-commit-body-for='{{$tag}}']">...</button>
{{end}}
<span class="flex-text-block">
{{template "repo/commit_statuses" dict "Status" .Status "Statuses" .Statuses}}
{{template "repo/commit_sign_badge" dict "Commit" . "CommitBaseLink" $commitBaseLink "CommitSignVerification" .Verification}}
{{template "repo/commit_statuses" dict "Status" $commit.Status "Statuses" $commit.Statuses}}
{{template "repo/commit_sign_badge" dict "Commit" $gitCommit "CommitBaseLink" $commitBaseLink "CommitSignVerification" $commit.Verification}}
</span>
</div>
{{if $commit.MessageBody}}
{{if $gitCommit.MessageBody}}
<pre class="commit-body tw-ml-[33px] tw-hidden" data-singular-commit-body-for="{{$tag}}">
{{- ctx.RenderUtils.RenderCommitBody $commit.MessageUTF8 $.comment.Issue.PullRequest.BaseRepo -}}
{{- ctx.RenderUtils.RenderCommitBody $gitCommit.MessageUTF8 $.comment.Issue.PullRequest.BaseRepo -}}
</pre>
{{end}}
{{end}}
+1 -8
View File
@@ -41,14 +41,7 @@
</span>
<span class="flex-text-inline tw-text-12">
{{if $commit.User}}
{{ctx.AvatarUtils.Avatar $commit.User 18}}
{{$commit.User.GetShortDisplayNameLinkHTML}}
{{else}}
{{$gitUserName := $commit.Commit.Author.Name}}
{{ctx.AvatarUtils.AvatarByEmail $commit.Commit.Author.Email $gitUserName 18}}
{{$gitUserName}}
{{end}}
{{ctx.RenderUtils.AvatarStackWithNames $commit.AvatarStackData}}
</span>
<span class="time flex-text-inline">{{DateUtils.FullTime $commit.Date}}</span>
+1 -9
View File
@@ -2,15 +2,7 @@
{{if not .LatestCommit}}
{{else}}
<span class="author-wrapper">
{{- if .LatestCommitUser -}}
{{- ctx.AvatarUtils.Avatar .LatestCommitUser 20 "tw-mr-2" -}}
<strong>{{.LatestCommitUser.GetShortDisplayNameLinkHTML}}</strong>
{{- else if .LatestCommit.Author -}}
{{- ctx.AvatarUtils.AvatarByEmail .LatestCommit.Author.Email .LatestCommit.Author.Name 20 "tw-mr-2" -}}
<strong>{{.LatestCommit.Author.Name}}</strong>
{{- end -}}
</span>
{{ctx.RenderUtils.AvatarStackWithNames .LatestCommitAvatarStackData}}
{{template "repo/commit_sign_badge" dict "Commit" .LatestCommit "CommitBaseLink" (print .RepoLink "/commit") "CommitSignVerification" .LatestCommitVerification}}
+3 -3
View File
@@ -89,10 +89,10 @@
{{$repo := .Repo}}
<div class="tw-flex tw-flex-col tw-gap-1">
{{range $pushCommit := $push.Commits}}
{{$commitLink := printf "%s/commit/%s" $repoLink .Sha1}}
{{$commitLink := printf "%s/commit/%s" $repoLink $pushCommit.Sha1}}
<div class="flex-text-block">
<img loading="lazy" alt class="ui avatar" src="{{$push.AvatarLink ctx .AuthorEmail}}" title="{{.AuthorName}}" width="16" height="16">
<a class="ui sha label" href="{{$commitLink}}">{{ShortSha .Sha1}}</a>
{{ctx.RenderUtils.AvatarStackPushCommit $pushCommit}}
<a class="ui sha label" href="{{$commitLink}}">{{ShortSha $pushCommit.Sha1}}</a>
<span class="tw-inline-block tw-truncate">
{{ctx.RenderUtils.RenderCommitMessage $pushCommit.Message $repo}}
</span>