mirror of
https://github.com/go-gitea/gitea.git
synced 2026-06-15 20:25:18 +02:00
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>
168 lines
6.0 KiB
Go
168 lines
6.0 KiB
Go
// Copyright 2019 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package repository
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
repo_model "gitea.dev/models/repo"
|
|
"gitea.dev/models/unittest"
|
|
"gitea.dev/modules/git"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestPushCommits_ToAPIPayloadCommits(t *testing.T) {
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
pushCommits := NewPushCommits()
|
|
pushCommits.Commits = []*PushCommit{
|
|
{
|
|
Sha1: "69554a6",
|
|
CommitterEmail: "user2@example.com",
|
|
CommitterName: "User2",
|
|
AuthorEmail: "user2@example.com",
|
|
AuthorName: "User2",
|
|
Message: "not signed commit",
|
|
},
|
|
{
|
|
Sha1: "27566bd",
|
|
CommitterEmail: "user2@example.com",
|
|
CommitterName: "User2",
|
|
AuthorEmail: "user2@example.com",
|
|
AuthorName: "User2",
|
|
Message: "good signed commit (with not yet validated email)",
|
|
},
|
|
{
|
|
Sha1: "5099b81",
|
|
CommitterEmail: "user2@example.com",
|
|
CommitterName: "User2",
|
|
AuthorEmail: "user2@example.com",
|
|
AuthorName: "User2",
|
|
Message: "good signed commit",
|
|
},
|
|
}
|
|
pushCommits.HeadCommit = &PushCommit{Sha1: "69554a6"}
|
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 16})
|
|
payloadCommits, headCommit, err := pushCommits.ToAPIPayloadCommits(t.Context(), repo)
|
|
assert.NoError(t, err)
|
|
assert.Len(t, payloadCommits, 3)
|
|
assert.NotNil(t, headCommit)
|
|
|
|
assert.Equal(t, "69554a6", payloadCommits[0].ID)
|
|
assert.Equal(t, "not signed commit", payloadCommits[0].Message)
|
|
assert.Equal(t, "https://try.gitea.io/user2/repo16/commit/69554a6", payloadCommits[0].URL)
|
|
assert.Equal(t, "User2", payloadCommits[0].Committer.Name)
|
|
assert.Equal(t, "user2", payloadCommits[0].Committer.UserName)
|
|
assert.Equal(t, "User2", payloadCommits[0].Author.Name)
|
|
assert.Equal(t, "user2", payloadCommits[0].Author.UserName)
|
|
assert.Equal(t, []string{}, payloadCommits[0].Added)
|
|
assert.Equal(t, []string{}, payloadCommits[0].Removed)
|
|
assert.Equal(t, []string{"readme.md"}, payloadCommits[0].Modified)
|
|
|
|
assert.Equal(t, "27566bd", payloadCommits[1].ID)
|
|
assert.Equal(t, "good signed commit (with not yet validated email)", payloadCommits[1].Message)
|
|
assert.Equal(t, "https://try.gitea.io/user2/repo16/commit/27566bd", payloadCommits[1].URL)
|
|
assert.Equal(t, "User2", payloadCommits[1].Committer.Name)
|
|
assert.Equal(t, "user2", payloadCommits[1].Committer.UserName)
|
|
assert.Equal(t, "User2", payloadCommits[1].Author.Name)
|
|
assert.Equal(t, "user2", payloadCommits[1].Author.UserName)
|
|
assert.Equal(t, []string{}, payloadCommits[1].Added)
|
|
assert.Equal(t, []string{}, payloadCommits[1].Removed)
|
|
assert.Equal(t, []string{"readme.md"}, payloadCommits[1].Modified)
|
|
|
|
assert.Equal(t, "5099b81", payloadCommits[2].ID)
|
|
assert.Equal(t, "good signed commit", payloadCommits[2].Message)
|
|
assert.Equal(t, "https://try.gitea.io/user2/repo16/commit/5099b81", payloadCommits[2].URL)
|
|
assert.Equal(t, "User2", payloadCommits[2].Committer.Name)
|
|
assert.Equal(t, "user2", payloadCommits[2].Committer.UserName)
|
|
assert.Equal(t, "User2", payloadCommits[2].Author.Name)
|
|
assert.Equal(t, "user2", payloadCommits[2].Author.UserName)
|
|
assert.Equal(t, []string{"readme.md"}, payloadCommits[2].Added)
|
|
assert.Equal(t, []string{}, payloadCommits[2].Removed)
|
|
assert.Equal(t, []string{}, payloadCommits[2].Modified)
|
|
|
|
assert.Equal(t, "69554a6", headCommit.ID)
|
|
assert.Equal(t, "not signed commit", headCommit.Message)
|
|
assert.Equal(t, "https://try.gitea.io/user2/repo16/commit/69554a6", headCommit.URL)
|
|
assert.Equal(t, "User2", headCommit.Committer.Name)
|
|
assert.Equal(t, "user2", headCommit.Committer.UserName)
|
|
assert.Equal(t, "User2", headCommit.Author.Name)
|
|
assert.Equal(t, "user2", headCommit.Author.UserName)
|
|
assert.Equal(t, []string{}, headCommit.Added)
|
|
assert.Equal(t, []string{}, headCommit.Removed)
|
|
assert.Equal(t, []string{"readme.md"}, headCommit.Modified)
|
|
}
|
|
|
|
func TestCommitToPushCommit(t *testing.T) {
|
|
now := time.Now()
|
|
sig := &git.Signature{
|
|
Email: "example@example.com",
|
|
Name: "John Doe",
|
|
When: now,
|
|
}
|
|
const hexString = "0123456789abcdef0123456789abcdef01234567"
|
|
sha1, err := git.NewIDFromString(hexString)
|
|
assert.NoError(t, err)
|
|
pushCommit := CommitToPushCommit(&git.Commit{
|
|
ID: sha1,
|
|
Author: sig,
|
|
Committer: sig,
|
|
CommitMessage: git.CommitMessage{MessageRaw: "Commit Message"},
|
|
})
|
|
assert.Equal(t, hexString, pushCommit.Sha1)
|
|
assert.Equal(t, "Commit Message", pushCommit.Message)
|
|
assert.Equal(t, "example@example.com", pushCommit.AuthorEmail)
|
|
assert.Equal(t, "John Doe", pushCommit.AuthorName)
|
|
assert.Equal(t, "example@example.com", pushCommit.CommitterEmail)
|
|
assert.Equal(t, "John Doe", pushCommit.CommitterName)
|
|
assert.Equal(t, now, pushCommit.Timestamp)
|
|
}
|
|
|
|
func TestListToPushCommits(t *testing.T) {
|
|
now := time.Now()
|
|
sig := &git.Signature{
|
|
Email: "example@example.com",
|
|
Name: "John Doe",
|
|
When: now,
|
|
}
|
|
|
|
const hexString1 = "0123456789abcdef0123456789abcdef01234567"
|
|
hash1, err := git.NewIDFromString(hexString1)
|
|
assert.NoError(t, err)
|
|
const hexString2 = "fedcba9876543210fedcba9876543210fedcba98"
|
|
hash2, err := git.NewIDFromString(hexString2)
|
|
assert.NoError(t, err)
|
|
|
|
l := []*git.Commit{
|
|
{
|
|
ID: hash1,
|
|
Author: sig,
|
|
Committer: sig,
|
|
CommitMessage: git.CommitMessage{MessageRaw: "Message1"},
|
|
},
|
|
{
|
|
ID: hash2,
|
|
Author: sig,
|
|
Committer: sig,
|
|
CommitMessage: git.CommitMessage{MessageRaw: "Message2"},
|
|
},
|
|
}
|
|
|
|
pushCommits := GitToPushCommits(l)
|
|
if assert.Len(t, pushCommits.Commits, 2) {
|
|
assert.Equal(t, "Message1", pushCommits.Commits[0].Message)
|
|
assert.Equal(t, hexString1, pushCommits.Commits[0].Sha1)
|
|
assert.Equal(t, "example@example.com", pushCommits.Commits[0].AuthorEmail)
|
|
assert.Equal(t, now, pushCommits.Commits[0].Timestamp)
|
|
|
|
assert.Equal(t, "Message2", pushCommits.Commits[1].Message)
|
|
assert.Equal(t, hexString2, pushCommits.Commits[1].Sha1)
|
|
assert.Equal(t, "example@example.com", pushCommits.Commits[1].AuthorEmail)
|
|
assert.Equal(t, now, pushCommits.Commits[1].Timestamp)
|
|
}
|
|
}
|