From 08ad5c30a8027b3176fdc8ada5b5bdc73647c6fe Mon Sep 17 00:00:00 2001 From: Christoph Witzko Date: Fri, 13 Jan 2023 15:45:52 +0100 Subject: [PATCH] feat: add commit annotations --- pkg/provider/github.go | 11 +++++++++++ pkg/provider/github_test.go | 34 +++++++++++++++++++++++++++++----- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/pkg/provider/github.go b/pkg/provider/github.go index 9137f63..78abc1c 100644 --- a/pkg/provider/github.go +++ b/pkg/provider/github.go @@ -7,6 +7,7 @@ import ( "os" "regexp" "strings" + "time" "github.com/Masterminds/semver/v3" "github.com/go-semantic-release/semantic-release/v2/pkg/provider" @@ -121,6 +122,16 @@ func (repo *GitHubRepository) GetCommits(fromSha, toSha string) ([]*semrel.RawCo allCommits = append(allCommits, &semrel.RawCommit{ SHA: sha, RawMessage: commit.Commit.GetMessage(), + Annotations: map[string]string{ + "author_login": commit.GetAuthor().GetLogin(), + "author_name": commit.Commit.GetAuthor().GetName(), + "author_email": commit.Commit.GetAuthor().GetEmail(), + "author_date": commit.Commit.GetAuthor().GetDate().Format(time.RFC3339), + "committer_login": commit.GetCommitter().GetLogin(), + "committer_name": commit.Commit.GetCommitter().GetName(), + "committer_email": commit.Commit.GetCommitter().GetEmail(), + "committer_date": commit.Commit.GetCommitter().GetDate().Format(time.RFC3339), + }, }) } if done || resp.NextPage == 0 { diff --git a/pkg/provider/github_test.go b/pkg/provider/github_test.go index 91b9b7f..a59ba46 100644 --- a/pkg/provider/github_test.go +++ b/pkg/provider/github_test.go @@ -8,6 +8,7 @@ import ( "net/url" "strings" "testing" + "time" "github.com/go-semantic-release/semantic-release/v2/pkg/provider" "github.com/go-semantic-release/semantic-release/v2/pkg/semrel" @@ -41,16 +42,31 @@ func TestNewGithubRepository(t *testing.T) { require.Equal("github.enterprise", repo.client.BaseURL.Host) } -func createGithubCommit(sha, message string) *github.RepositoryCommit { - return &github.RepositoryCommit{SHA: &sha, Commit: &github.Commit{Message: &message}} -} - var ( commitType = "commit" tagType = "tag" + testSHA = "deadbeef" + + githubAuthorLogin = "author-login" + githubAuthorName = "author" + githubAuthorEmail = "author@github.com" + githubTimestamp = time.Now() + + githubAuthor = &github.CommitAuthor{ + Name: &githubAuthorName, + Email: &githubAuthorEmail, + Date: &githubTimestamp, + } ) -var testSHA = "deadbeef" +func createGithubCommit(sha, message string) *github.RepositoryCommit { + return &github.RepositoryCommit{ + SHA: &sha, + Commit: &github.Commit{Message: &message, Author: githubAuthor, Committer: githubAuthor}, + Author: &github.User{Login: &githubAuthorLogin}, + Committer: &github.User{Login: &githubAuthorLogin}, + } +} func createGithubRef(ref string) *github.Reference { return &github.Reference{Ref: &ref, Object: &github.GitObject{SHA: &testSHA, Type: &commitType}} @@ -206,6 +222,14 @@ func TestGithubGetCommits(t *testing.T) { idxOff := i + 1 require.Equal(t, c.SHA, githubCommits[idxOff].GetSHA()) require.Equal(t, c.RawMessage, githubCommits[idxOff].Commit.GetMessage()) + require.Equal(t, c.Annotations["author_login"], githubCommits[idxOff].GetAuthor().GetLogin()) + require.Equal(t, c.Annotations["author_name"], githubCommits[idxOff].Commit.GetAuthor().GetName()) + require.Equal(t, c.Annotations["author_email"], githubCommits[idxOff].Commit.GetAuthor().GetEmail()) + require.Equal(t, c.Annotations["committer_login"], githubCommits[idxOff].GetCommitter().GetLogin()) + require.Equal(t, c.Annotations["committer_name"], githubCommits[idxOff].Commit.GetCommitter().GetName()) + require.Equal(t, c.Annotations["committer_email"], githubCommits[idxOff].Commit.GetCommitter().GetEmail()) + require.Equal(t, c.Annotations["author_date"], githubCommits[idxOff].Commit.GetAuthor().GetDate().Format(time.RFC3339)) + require.Equal(t, c.Annotations["committer_date"], githubCommits[idxOff].Commit.GetCommitter().GetDate().Format(time.RFC3339)) } }