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
|
|
@ -29,6 +29,13 @@ const (
|
|||
EnvRepository = "GITHUB_REPOSITORY"
|
||||
)
|
||||
|
||||
var (
|
||||
gitHubActionsBotAuthor = git.Author{
|
||||
Name: "github-actions[bot]",
|
||||
Email: "41898282+github-actions[bot]@users.noreply.github.com",
|
||||
}
|
||||
)
|
||||
|
||||
var _ forge.Forge = &GitHub{}
|
||||
|
||||
type GitHub struct {
|
||||
|
|
@ -61,6 +68,22 @@ func (g *GitHub) GitAuth() transport.AuthMethod {
|
|||
}
|
||||
}
|
||||
|
||||
func (g *GitHub) CommitAuthor(ctx context.Context) (git.Author, error) {
|
||||
g.log.DebugContext(ctx, "getting commit author from current token user")
|
||||
|
||||
user, _, err := g.client.Users.Get(ctx, "")
|
||||
if err != nil {
|
||||
g.log.WarnContext(ctx, "failed to get commit author from API, using default github-actions[bot] user", "error", err)
|
||||
|
||||
return gitHubActionsBotAuthor, nil
|
||||
}
|
||||
|
||||
return git.Author{
|
||||
Name: user.GetName(),
|
||||
Email: user.GetEmail(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (g *GitHub) LatestTags(ctx context.Context) (git.Releases, error) {
|
||||
g.log.DebugContext(ctx, "listing all tags in github repository")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue