Skip to content

Commit 08ad5c3

Browse files
feat: add commit annotations
1 parent f926e16 commit 08ad5c3

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

pkg/provider/github.go

+11
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"regexp"
99
"strings"
10+
"time"
1011

1112
"github.com/Masterminds/semver/v3"
1213
"github.com/go-semantic-release/semantic-release/v2/pkg/provider"
@@ -121,6 +122,16 @@ func (repo *GitHubRepository) GetCommits(fromSha, toSha string) ([]*semrel.RawCo
121122
allCommits = append(allCommits, &semrel.RawCommit{
122123
SHA: sha,
123124
RawMessage: commit.Commit.GetMessage(),
125+
Annotations: map[string]string{
126+
"author_login": commit.GetAuthor().GetLogin(),
127+
"author_name": commit.Commit.GetAuthor().GetName(),
128+
"author_email": commit.Commit.GetAuthor().GetEmail(),
129+
"author_date": commit.Commit.GetAuthor().GetDate().Format(time.RFC3339),
130+
"committer_login": commit.GetCommitter().GetLogin(),
131+
"committer_name": commit.Commit.GetCommitter().GetName(),
132+
"committer_email": commit.Commit.GetCommitter().GetEmail(),
133+
"committer_date": commit.Commit.GetCommitter().GetDate().Format(time.RFC3339),
134+
},
124135
})
125136
}
126137
if done || resp.NextPage == 0 {

pkg/provider/github_test.go

+29-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/url"
99
"strings"
1010
"testing"
11+
"time"
1112

1213
"github.com/go-semantic-release/semantic-release/v2/pkg/provider"
1314
"github.com/go-semantic-release/semantic-release/v2/pkg/semrel"
@@ -41,16 +42,31 @@ func TestNewGithubRepository(t *testing.T) {
4142
require.Equal("github.enterprise", repo.client.BaseURL.Host)
4243
}
4344

44-
func createGithubCommit(sha, message string) *github.RepositoryCommit {
45-
return &github.RepositoryCommit{SHA: &sha, Commit: &github.Commit{Message: &message}}
46-
}
47-
4845
var (
4946
commitType = "commit"
5047
tagType = "tag"
48+
testSHA = "deadbeef"
49+
50+
githubAuthorLogin = "author-login"
51+
githubAuthorName = "author"
52+
githubAuthorEmail = "[email protected]"
53+
githubTimestamp = time.Now()
54+
55+
githubAuthor = &github.CommitAuthor{
56+
Name: &githubAuthorName,
57+
Email: &githubAuthorEmail,
58+
Date: &githubTimestamp,
59+
}
5160
)
5261

53-
var testSHA = "deadbeef"
62+
func createGithubCommit(sha, message string) *github.RepositoryCommit {
63+
return &github.RepositoryCommit{
64+
SHA: &sha,
65+
Commit: &github.Commit{Message: &message, Author: githubAuthor, Committer: githubAuthor},
66+
Author: &github.User{Login: &githubAuthorLogin},
67+
Committer: &github.User{Login: &githubAuthorLogin},
68+
}
69+
}
5470

5571
func createGithubRef(ref string) *github.Reference {
5672
return &github.Reference{Ref: &ref, Object: &github.GitObject{SHA: &testSHA, Type: &commitType}}
@@ -206,6 +222,14 @@ func TestGithubGetCommits(t *testing.T) {
206222
idxOff := i + 1
207223
require.Equal(t, c.SHA, githubCommits[idxOff].GetSHA())
208224
require.Equal(t, c.RawMessage, githubCommits[idxOff].Commit.GetMessage())
225+
require.Equal(t, c.Annotations["author_login"], githubCommits[idxOff].GetAuthor().GetLogin())
226+
require.Equal(t, c.Annotations["author_name"], githubCommits[idxOff].Commit.GetAuthor().GetName())
227+
require.Equal(t, c.Annotations["author_email"], githubCommits[idxOff].Commit.GetAuthor().GetEmail())
228+
require.Equal(t, c.Annotations["committer_login"], githubCommits[idxOff].GetCommitter().GetLogin())
229+
require.Equal(t, c.Annotations["committer_name"], githubCommits[idxOff].Commit.GetCommitter().GetName())
230+
require.Equal(t, c.Annotations["committer_email"], githubCommits[idxOff].Commit.GetCommitter().GetEmail())
231+
require.Equal(t, c.Annotations["author_date"], githubCommits[idxOff].Commit.GetAuthor().GetDate().Format(time.RFC3339))
232+
require.Equal(t, c.Annotations["committer_date"], githubCommits[idxOff].Commit.GetCommitter().GetDate().Format(time.RFC3339))
209233
}
210234
}
211235

0 commit comments

Comments
 (0)