Skip to content

Commit 92eda2f

Browse files
feat: pass commit annotations
1 parent 8643fc2 commit 92eda2f

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

pkg/analyzer/commit_analyzer.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ func (da *DefaultCommitAnalyzer) Version() string {
2828
}
2929

3030
func (da *DefaultCommitAnalyzer) analyzeSingleCommit(rawCommit *semrel.RawCommit) *semrel.Commit {
31-
c := &semrel.Commit{Change: &semrel.Change{}}
32-
c.SHA = rawCommit.SHA
33-
c.Raw = strings.Split(rawCommit.RawMessage, "\n")
31+
c := &semrel.Commit{
32+
SHA: rawCommit.SHA,
33+
Raw: strings.Split(rawCommit.RawMessage, "\n"),
34+
Change: &semrel.Change{},
35+
Annotations: rawCommit.Annotations,
36+
}
3437
found := commitPattern.FindAllStringSubmatch(c.Raw[0], -1)
3538
if len(found) < 1 {
3639
return c

pkg/analyzer/commit_analyzer_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package analyzer
22

33
import (
44
"fmt"
5+
"strings"
56
"testing"
67

78
"github.com/go-semantic-release/semantic-release/v2/pkg/semrel"
@@ -24,9 +25,22 @@ func createRawCommit(sha, message string) *semrel.RawCommit {
2425
return &semrel.RawCommit{
2526
SHA: sha,
2627
RawMessage: message,
28+
Annotations: map[string]string{
29+
"author_name": "test",
30+
"my-annotation": "true",
31+
},
2732
}
2833
}
2934

35+
func TestAnnotations(t *testing.T) {
36+
defaultAnalyzer := &DefaultCommitAnalyzer{}
37+
rawCommit := createRawCommit("a", "feat: new feature")
38+
commit := defaultAnalyzer.analyzeSingleCommit(rawCommit)
39+
require.Equal(t, rawCommit.SHA, commit.SHA)
40+
require.Equal(t, rawCommit.RawMessage, strings.Join(commit.Raw, "\n"))
41+
require.Equal(t, rawCommit.Annotations, commit.Annotations)
42+
}
43+
3044
func TestDefaultAnalyzer(t *testing.T) {
3145
testCases := []struct {
3246
RawCommit *semrel.RawCommit

0 commit comments

Comments
 (0)