Skip to content

Commit 7dfbbb7

Browse files
feat: add commit annotations
1 parent f7be01e commit 7dfbbb7

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

pkg/provider/git.go

+8
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ func (repo *Repository) GetCommits(fromSha, toSha string) ([]*semrel.RawCommit,
111111
allCommits = append(allCommits, &semrel.RawCommit{
112112
SHA: commit.Hash.String(),
113113
RawMessage: commit.Message,
114+
Annotations: map[string]string{
115+
"author_name": commit.Author.Name,
116+
"author_email": commit.Author.Email,
117+
"author_date": commit.Author.When.Format(time.RFC3339),
118+
"committer_name": commit.Committer.Name,
119+
"committer_email": commit.Committer.Email,
120+
"committer_date": commit.Committer.When.Format(time.RFC3339),
121+
},
114122
})
115123
return nil
116124
})

pkg/provider/git_test.go

+14-7
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ func newRepository(t *testing.T) {
5353
require.NotNil(repo.auth)
5454
}
5555

56+
var gitCommitAuthor = &object.Signature{
57+
Name: "test",
58+
Email: "test@test.com",
59+
When: time.Now(),
60+
}
61+
5662
//gocyclo:ignore
5763
func setupRepo() (string, error) {
5864
dir, err := os.MkdirTemp("", "provider-git")
@@ -76,15 +82,10 @@ func setupRepo() (string, error) {
7682
return "", err
7783
}
7884

79-
author := &object.Signature{
80-
Name: "test",
81-
Email: "test@test.com",
82-
When: time.Now(),
83-
}
8485
versionCount := 0
8586
betaCount := 1
8687
for i := 0; i < 100; i++ {
87-
commit, commitErr := w.Commit(fmt.Sprintf("feat: commit %d", i), &git.CommitOptions{Author: author, AllowEmptyCommits: true})
88+
commit, commitErr := w.Commit(fmt.Sprintf("feat: commit %d", i), &git.CommitOptions{Author: gitCommitAuthor, AllowEmptyCommits: true})
8889
if commitErr != nil {
8990
return "", err
9091
}
@@ -110,7 +111,7 @@ func setupRepo() (string, error) {
110111
return "", err
111112
}
112113

113-
if _, err = w.Commit("fix: error", &git.CommitOptions{Author: author, AllowEmptyCommits: true}); err != nil {
114+
if _, err = w.Commit("fix: error", &git.CommitOptions{Author: gitCommitAuthor, AllowEmptyCommits: true}); err != nil {
114115
return "", err
115116
}
116117
if err = w.Checkout(&git.CheckoutOptions{Branch: plumbing.NewBranchReferenceName("master")}); err != nil {
@@ -169,6 +170,12 @@ func getCommits(t *testing.T) {
169170

170171
for _, c := range commits {
171172
require.True(strings.HasPrefix(c.RawMessage, "feat: commit"))
173+
require.Equal(gitCommitAuthor.Name, c.Annotations["author_name"])
174+
require.Equal(gitCommitAuthor.Email, c.Annotations["author_email"])
175+
require.Equal(gitCommitAuthor.When.Format(time.RFC3339), c.Annotations["author_date"])
176+
require.Equal(gitCommitAuthor.When.Format(time.RFC3339), c.Annotations["committer_date"])
177+
require.Equal(gitCommitAuthor.Name, c.Annotations["committer_name"])
178+
require.Equal(gitCommitAuthor.Email, c.Annotations["committer_email"])
172179
}
173180
}
174181

0 commit comments

Comments
 (0)