From cc60918d769187b1f00c30fd2831a3fa04250d0d Mon Sep 17 00:00:00 2001 From: Ahmad ATWI Date: Fri, 11 Oct 2024 10:45:03 +0200 Subject: [PATCH] [#805] Update tcr.wrapCommitMessage() so that it includes or not the emoji depending on the VCS support for emojis - Added a property in the vcs_test_fake for the emojis - Added a test for the two variance of the method --- src/engine/tcr.go | 2 +- src/engine/tcr_test.go | 19 +++++++++++++++++++ src/vcs/fake/vcs_test_fake.go | 8 +++++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/engine/tcr.go b/src/engine/tcr.go index ae52efb4..54f268f4 100644 --- a/src/engine/tcr.go +++ b/src/engine/tcr.go @@ -323,7 +323,7 @@ func (tcr *TCREngine) setMessageSuffix(suffix string) { } func (tcr *TCREngine) wrapCommitMessages(header CommitMessage, event *events.TCREvent) []string { - messages := []string{header.toString(true)} + messages := []string{header.toString(tcr.vcs.SupportsEmojis())} if event != nil { messages = append(messages, event.ToYAML()) } diff --git a/src/engine/tcr_test.go b/src/engine/tcr_test.go index 9ea60d56..e62ef579 100644 --- a/src/engine/tcr_test.go +++ b/src/engine/tcr_test.go @@ -961,6 +961,25 @@ func Test_adding_suffix_to_tcr_commit_messages(t *testing.T) { } } +func Test_building_the_commit_message_depending_on_the_vcs(t *testing.T) { + tests := []struct { + desc string + supportsEmoji bool + }{ + {"with vcs supporting emoji", true}, + {"with vcs not supporting emoji", false}, + } + for _, test := range tests { + t.Run(test.desc, func(t *testing.T) { + p := params.AParamSet(params.WithRunMode(runmode.OneShot{})) + tcr, vcsFake := initTCREngineWithFakes(p, nil, nil, nil) + vcsFake.SetSupportsEmojis(test.supportsEmoji) + result := tcr.wrapCommitMessages(messagePassed, events.ATcrEvent()) + assert.Equal(t, test.supportsEmoji, strings.ContainsRune(result[0], messagePassed.Emoji)) + }) + } +} + func Test_count_files(t *testing.T) { tests := []struct { desc string diff --git a/src/vcs/fake/vcs_test_fake.go b/src/vcs/fake/vcs_test_fake.go index 649c9679..68f6eb67 100644 --- a/src/vcs/fake/vcs_test_fake.go +++ b/src/vcs/fake/vcs_test_fake.go @@ -78,11 +78,12 @@ type ( remoteName string lastCommands []Command lastCommitSubjects []string + supportsEmojis bool } ) func (vf *VCSFake) SupportsEmojis() bool { - return true + return vf.supportsEmojis } func (vf *VCSFake) fakeCommand(cmd Command) (err error) { @@ -101,6 +102,7 @@ func NewVCSFake(settings Settings) *VCSFake { remoteName: "vcs-fake-remote-name", lastCommitSubjects: make([]string, 0), lastCommands: make([]Command, 0), + supportsEmojis: true, } } @@ -220,3 +222,7 @@ func (vf *VCSFake) CheckRemoteAccess() bool { func (vf *VCSFake) GetLastCommitSubjects() []string { return vf.lastCommitSubjects } + +func (vf *VCSFake) SetSupportsEmojis(flag bool) { + vf.supportsEmojis = flag +}