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

feat: add commit annotations

parent 68b29a0a
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"os" "os"
"regexp" "regexp"
"strconv" "strconv"
"time"
"github.com/Masterminds/semver/v3" "github.com/Masterminds/semver/v3"
"github.com/go-semantic-release/semantic-release/v2/pkg/provider" "github.com/go-semantic-release/semantic-release/v2/pkg/provider"
...@@ -110,6 +111,14 @@ func (repo *GitLabRepository) GetCommits(fromSha, toSha string) ([]*semrel.RawCo ...@@ -110,6 +111,14 @@ func (repo *GitLabRepository) GetCommits(fromSha, toSha string) ([]*semrel.RawCo
allCommits = append(allCommits, &semrel.RawCommit{ allCommits = append(allCommits, &semrel.RawCommit{
SHA: commit.ID, SHA: commit.ID,
RawMessage: commit.Message, RawMessage: commit.Message,
Annotations: map[string]string{
"author_name": commit.AuthorName,
"author_email": commit.AuthorEmail,
"author_date": commit.AuthoredDate.Format(time.RFC3339),
"committer_name": commit.CommitterName,
"committer_email": commit.CommitterEmail,
"committer_date": commit.CommittedDate.Format(time.RFC3339),
},
}) })
} }
......
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"net/http/httptest" "net/http/httptest"
"strconv" "strconv"
"testing" "testing"
"time"
"github.com/go-semantic-release/semantic-release/v2/pkg/provider" "github.com/go-semantic-release/semantic-release/v2/pkg/provider"
"github.com/go-semantic-release/semantic-release/v2/pkg/semrel" "github.com/go-semantic-release/semantic-release/v2/pkg/semrel"
...@@ -46,7 +47,17 @@ func TestNewGitlabRepository(t *testing.T) { ...@@ -46,7 +47,17 @@ func TestNewGitlabRepository(t *testing.T) {
} }
func createGitlabCommit(sha, message string) *gitlab.Commit { func createGitlabCommit(sha, message string) *gitlab.Commit {
return &gitlab.Commit{ID: sha, Message: message} commitDate := time.Now()
return &gitlab.Commit{
ID: sha,
Message: message,
AuthorName: "author",
AuthorEmail: "author@gitlab.com",
AuthoredDate: &commitDate,
CommitterName: "committer",
CommitterEmail: "committer@gitlab.com",
CommittedDate: &commitDate,
}
} }
var testSHA = "deadbeef" var testSHA = "deadbeef"
...@@ -157,6 +168,12 @@ func TestGitlabGetCommits(t *testing.T) { ...@@ -157,6 +168,12 @@ func TestGitlabGetCommits(t *testing.T) {
for i, c := range commits { for i, c := range commits {
require.Equal(t, c.SHA, gitlabCommits[i].ID) require.Equal(t, c.SHA, gitlabCommits[i].ID)
require.Equal(t, c.RawMessage, gitlabCommits[i].Message) require.Equal(t, c.RawMessage, gitlabCommits[i].Message)
require.Equal(t, c.Annotations["author_name"], gitlabCommits[i].AuthorName)
require.Equal(t, c.Annotations["author_email"], gitlabCommits[i].AuthorEmail)
require.Equal(t, c.Annotations["committer_name"], gitlabCommits[i].CommitterName)
require.Equal(t, c.Annotations["committer_email"], gitlabCommits[i].CommitterEmail)
require.Equal(t, c.Annotations["author_date"], gitlabCommits[i].AuthoredDate.Format(time.RFC3339))
require.Equal(t, c.Annotations["committer_date"], gitlabCommits[i].CommittedDate.Format(time.RFC3339))
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment