Skip to content

Commit

Permalink
feat: add commit annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
christophwitzko committed Jan 13, 2023
1 parent f926e16 commit 08ad5c3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
11 changes: 11 additions & 0 deletions pkg/provider/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"regexp"
"strings"
"time"

"github.com/Masterminds/semver/v3"
"github.com/go-semantic-release/semantic-release/v2/pkg/provider"
Expand Down Expand Up @@ -121,6 +122,16 @@ func (repo *GitHubRepository) GetCommits(fromSha, toSha string) ([]*semrel.RawCo
allCommits = append(allCommits, &semrel.RawCommit{
SHA: sha,
RawMessage: commit.Commit.GetMessage(),
Annotations: map[string]string{
"author_login": commit.GetAuthor().GetLogin(),
"author_name": commit.Commit.GetAuthor().GetName(),
"author_email": commit.Commit.GetAuthor().GetEmail(),
"author_date": commit.Commit.GetAuthor().GetDate().Format(time.RFC3339),
"committer_login": commit.GetCommitter().GetLogin(),
"committer_name": commit.Commit.GetCommitter().GetName(),
"committer_email": commit.Commit.GetCommitter().GetEmail(),
"committer_date": commit.Commit.GetCommitter().GetDate().Format(time.RFC3339),
},
})
}
if done || resp.NextPage == 0 {
Expand Down
34 changes: 29 additions & 5 deletions pkg/provider/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/url"
"strings"
"testing"
"time"

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

func createGithubCommit(sha, message string) *github.RepositoryCommit {
return &github.RepositoryCommit{SHA: &sha, Commit: &github.Commit{Message: &message}}
}

var (
commitType = "commit"
tagType = "tag"
testSHA = "deadbeef"

githubAuthorLogin = "author-login"
githubAuthorName = "author"
githubAuthorEmail = "[email protected]"
githubTimestamp = time.Now()

githubAuthor = &github.CommitAuthor{
Name: &githubAuthorName,
Email: &githubAuthorEmail,
Date: &githubTimestamp,
}
)

var testSHA = "deadbeef"
func createGithubCommit(sha, message string) *github.RepositoryCommit {
return &github.RepositoryCommit{
SHA: &sha,
Commit: &github.Commit{Message: &message, Author: githubAuthor, Committer: githubAuthor},
Author: &github.User{Login: &githubAuthorLogin},
Committer: &github.User{Login: &githubAuthorLogin},
}
}

func createGithubRef(ref string) *github.Reference {
return &github.Reference{Ref: &ref, Object: &github.GitObject{SHA: &testSHA, Type: &commitType}}
Expand Down Expand Up @@ -206,6 +222,14 @@ func TestGithubGetCommits(t *testing.T) {
idxOff := i + 1
require.Equal(t, c.SHA, githubCommits[idxOff].GetSHA())
require.Equal(t, c.RawMessage, githubCommits[idxOff].Commit.GetMessage())
require.Equal(t, c.Annotations["author_login"], githubCommits[idxOff].GetAuthor().GetLogin())
require.Equal(t, c.Annotations["author_name"], githubCommits[idxOff].Commit.GetAuthor().GetName())
require.Equal(t, c.Annotations["author_email"], githubCommits[idxOff].Commit.GetAuthor().GetEmail())
require.Equal(t, c.Annotations["committer_login"], githubCommits[idxOff].GetCommitter().GetLogin())
require.Equal(t, c.Annotations["committer_name"], githubCommits[idxOff].Commit.GetCommitter().GetName())
require.Equal(t, c.Annotations["committer_email"], githubCommits[idxOff].Commit.GetCommitter().GetEmail())
require.Equal(t, c.Annotations["author_date"], githubCommits[idxOff].Commit.GetAuthor().GetDate().Format(time.RFC3339))
require.Equal(t, c.Annotations["committer_date"], githubCommits[idxOff].Commit.GetCommitter().GetDate().Format(time.RFC3339))
}
}

Expand Down

0 comments on commit 08ad5c3

Please sign in to comment.