mirror of
https://github.com/apricote/releaser-pleaser.git
synced 2026-01-13 21:21:03 +00:00
feat: real user as commit author (#187)
Previously all commits were authored and committed by
releaser-pleaser <>
This looked weird when looking at the commit. We now check with the
Forge API for details on the currently authenticated user, and use that
name and email as the commit author. The commit committer stays the same
for now.
In GitHub, the default `$GITHUB_TOKEN` does not allow access to the
required endpoint, so for github the user `github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>` is hardcoded
when the request fails.
This commit is contained in:
parent
f2786c8f39
commit
175d6d0633
6 changed files with 121 additions and 13 deletions
46
internal/git/git_test.go
Normal file
46
internal/git/git_test.go
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
package git
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/go-git/go-git/v5/plumbing/object"
|
||||
)
|
||||
|
||||
func TestAuthor_signature(t *testing.T) {
|
||||
now := time.Now()
|
||||
|
||||
tests := []struct {
|
||||
author Author
|
||||
want *object.Signature
|
||||
}{
|
||||
{author: Author{Name: "foo", Email: "bar@example.com"}, want: &object.Signature{Name: "foo", Email: "bar@example.com", When: now}},
|
||||
{author: Author{Name: "bar", Email: "foo@example.com"}, want: &object.Signature{Name: "bar", Email: "foo@example.com", When: now}},
|
||||
}
|
||||
for i, tt := range tests {
|
||||
t.Run(strconv.FormatInt(int64(i), 10), func(t *testing.T) {
|
||||
if got := tt.author.signature(now); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("signature() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAuthor_String(t *testing.T) {
|
||||
tests := []struct {
|
||||
author Author
|
||||
want string
|
||||
}{
|
||||
{author: Author{Name: "foo", Email: "bar@example.com"}, want: "foo <bar@example.com>"},
|
||||
{author: Author{Name: "bar", Email: "foo@example.com"}, want: "bar <foo@example.com>"},
|
||||
}
|
||||
for i, tt := range tests {
|
||||
t.Run(strconv.FormatInt(int64(i), 10), func(t *testing.T) {
|
||||
if got := tt.author.String(); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("String() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue