Skip to content
Snippets Groups Projects
Commit 7dfbbb7d authored by Christoph Witzko's avatar Christoph Witzko
Browse files

feat: add commit annotations

parent f7be01e3
No related branches found
No related tags found
No related merge requests found
......@@ -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
})
......
......@@ -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"])
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment