diff --git a/pkg/provider/git.go b/pkg/provider/git.go index 75191cb0803f2ce4f82a9518b2f5517868cd4762..9e81d9b24634da0315dd7b6500d6427c8d1ce9d7 100644 --- a/pkg/provider/git.go +++ b/pkg/provider/git.go @@ -111,6 +111,14 @@ func (repo *Repository) GetCommits(fromSha, toSha string) ([]*semrel.RawCommit, allCommits = append(allCommits, &semrel.RawCommit{ SHA: commit.Hash.String(), RawMessage: commit.Message, + Annotations: map[string]string{ + "author_name": commit.Author.Name, + "author_email": commit.Author.Email, + "author_date": commit.Author.When.Format(time.RFC3339), + "committer_name": commit.Committer.Name, + "committer_email": commit.Committer.Email, + "committer_date": commit.Committer.When.Format(time.RFC3339), + }, }) return nil }) diff --git a/pkg/provider/git_test.go b/pkg/provider/git_test.go index ec6f956131ed7b25541a61ce9124235e46fb3ca1..1a4a7ecdd7cae6100fe40114ec0e97a0dbf43adc 100644 --- a/pkg/provider/git_test.go +++ b/pkg/provider/git_test.go @@ -53,6 +53,12 @@ func newRepository(t *testing.T) { require.NotNil(repo.auth) } +var gitCommitAuthor = &object.Signature{ + Name: "test", + Email: "test@test.com", + When: time.Now(), +} + //gocyclo:ignore func setupRepo() (string, error) { dir, err := os.MkdirTemp("", "provider-git") @@ -76,15 +82,10 @@ func setupRepo() (string, error) { return "", err } - author := &object.Signature{ - Name: "test", - Email: "test@test.com", - When: time.Now(), - } versionCount := 0 betaCount := 1 for i := 0; i < 100; i++ { - commit, commitErr := w.Commit(fmt.Sprintf("feat: commit %d", i), &git.CommitOptions{Author: author, AllowEmptyCommits: true}) + commit, commitErr := w.Commit(fmt.Sprintf("feat: commit %d", i), &git.CommitOptions{Author: gitCommitAuthor, AllowEmptyCommits: true}) if commitErr != nil { return "", err } @@ -110,7 +111,7 @@ func setupRepo() (string, error) { return "", err } - if _, err = w.Commit("fix: error", &git.CommitOptions{Author: author, AllowEmptyCommits: true}); err != nil { + if _, err = w.Commit("fix: error", &git.CommitOptions{Author: gitCommitAuthor, AllowEmptyCommits: true}); err != nil { return "", err } if err = w.Checkout(&git.CheckoutOptions{Branch: plumbing.NewBranchReferenceName("master")}); err != nil { @@ -169,6 +170,12 @@ func getCommits(t *testing.T) { for _, c := range commits { require.True(strings.HasPrefix(c.RawMessage, "feat: commit")) + require.Equal(gitCommitAuthor.Name, c.Annotations["author_name"]) + require.Equal(gitCommitAuthor.Email, c.Annotations["author_email"]) + require.Equal(gitCommitAuthor.When.Format(time.RFC3339), c.Annotations["author_date"]) + require.Equal(gitCommitAuthor.When.Format(time.RFC3339), c.Annotations["committer_date"]) + require.Equal(gitCommitAuthor.Name, c.Annotations["committer_name"]) + require.Equal(gitCommitAuthor.Email, c.Annotations["committer_email"]) } }