Skip to content

Commit

Permalink
feat: pass commit annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
christophwitzko committed Jan 13, 2023
1 parent 8643fc2 commit 92eda2f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/analyzer/commit_analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ func (da *DefaultCommitAnalyzer) Version() string {
}

func (da *DefaultCommitAnalyzer) analyzeSingleCommit(rawCommit *semrel.RawCommit) *semrel.Commit {
c := &semrel.Commit{Change: &semrel.Change{}}
c.SHA = rawCommit.SHA
c.Raw = strings.Split(rawCommit.RawMessage, "\n")
c := &semrel.Commit{
SHA: rawCommit.SHA,
Raw: strings.Split(rawCommit.RawMessage, "\n"),
Change: &semrel.Change{},
Annotations: rawCommit.Annotations,
}
found := commitPattern.FindAllStringSubmatch(c.Raw[0], -1)
if len(found) < 1 {
return c
Expand Down
14 changes: 14 additions & 0 deletions pkg/analyzer/commit_analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package analyzer

import (
"fmt"
"strings"
"testing"

"github.com/go-semantic-release/semantic-release/v2/pkg/semrel"
Expand All @@ -24,9 +25,22 @@ func createRawCommit(sha, message string) *semrel.RawCommit {
return &semrel.RawCommit{
SHA: sha,
RawMessage: message,
Annotations: map[string]string{
"author_name": "test",
"my-annotation": "true",
},
}
}

func TestAnnotations(t *testing.T) {
defaultAnalyzer := &DefaultCommitAnalyzer{}
rawCommit := createRawCommit("a", "feat: new feature")
commit := defaultAnalyzer.analyzeSingleCommit(rawCommit)
require.Equal(t, rawCommit.SHA, commit.SHA)
require.Equal(t, rawCommit.RawMessage, strings.Join(commit.Raw, "\n"))
require.Equal(t, rawCommit.Annotations, commit.Annotations)
}

func TestDefaultAnalyzer(t *testing.T) {
testCases := []struct {
RawCommit *semrel.RawCommit
Expand Down

0 comments on commit 92eda2f

Please sign in to comment.