diff --git a/internal/gitlab/commit_mapping_test.go b/internal/gitlab/commit_mapping_test.go index a5fdf9417..26299681e 100644 --- a/internal/gitlab/commit_mapping_test.go +++ b/internal/gitlab/commit_mapping_test.go @@ -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, " ", c.Author) +} diff --git a/internal/gitlab/gitlab.go b/internal/gitlab/gitlab.go index 48af5c52f..7a725158b 100644 --- a/internal/gitlab/gitlab.go +++ b/internal/gitlab/gitlab.go @@ -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,