Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions internal/gitlab/commit_mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,14 @@ func TestGitlabMRRefs(t *testing.T) {
require.Equal(t, "feature-branch", head)
require.Equal(t, "main", base)
}

// A commit with no author is recorded with an empty author, not " <>". One
// part is enough to keep the format.
func TestCommitFromGitlabCommit_MissingAuthorIsEmpty(t *testing.T) {
c := commitFromGitlabCommit(&gitlab.Commit{ID: "abc1230000000000000000000000000000000000"}, "my-branch")
require.Equal(t, "", c.Author)
c = commitFromGitlabCommit(&gitlab.Commit{ID: "abc1230000000000000000000000000000000000", AuthorName: "Steve Tooke"}, "my-branch")
require.Equal(t, "Steve Tooke <>", c.Author)
c = commitFromGitlabCommit(&gitlab.Commit{ID: "abc1230000000000000000000000000000000000", AuthorEmail: "tooky@kosli.com"}, "my-branch")
require.Equal(t, " <tooky@kosli.com>", c.Author)
}
7 changes: 6 additions & 1 deletion internal/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,15 @@ func commitFromGitlabCommit(commit *gitlab.Commit, branch string) types.Commit {
if commit.AuthoredDate != nil {
timestamp = commit.AuthoredDate.Unix()
}
// A commit with no author is recorded as "", not " <>".
author := ""
if commit.AuthorName != "" || commit.AuthorEmail != "" {
author = fmt.Sprintf("%s <%s>", commit.AuthorName, commit.AuthorEmail)
}
return types.Commit{
SHA: commit.ID,
Message: commit.Message,
Author: fmt.Sprintf("%s <%s>", commit.AuthorName, commit.AuthorEmail),
Author: author,
Timestamp: timestamp,
Branch: branch,
URL: commit.WebURL,
Expand Down
Loading