From 9f7198b1bdcb1efc0a9bc514bb3a826e1658f331 Mon Sep 17 00:00:00 2001 From: Damien Menanteau Date: Fri, 11 Oct 2024 13:35:12 +0200 Subject: [PATCH] [#805] Fix linter errors - add missing method descriptions - ignore gosec false positive in tcr_test.go - simplify tcr.parseCommitStatus() - rewrite tcr.isTCRCommitMessage() so that it leverages on tcr.parseCommitStatus() --- src/engine/tcr.go | 14 ++++++-------- src/engine/tcr_test.go | 2 +- src/vcs/fake/vcs_test_fake.go | 11 +++++++---- src/vcs/git/git_impl.go | 9 +++++---- src/vcs/p4/p4_impl.go | 9 +++++---- 5 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/engine/tcr.go b/src/engine/tcr.go index 6f09a101..bc2bcdea 100644 --- a/src/engine/tcr.go +++ b/src/engine/tcr.go @@ -250,7 +250,7 @@ func (tcr *TCREngine) queryVCSLogs(p params.Params) vcs.LogItems { } func isTCRCommitMessage(msg string) bool { - return strings.Index(msg, messagePassed.toString(true)) == 0 || strings.Index(msg, messageFailed.toString(true)) == 0 + return parseCommitStatus(msg) != events.StatusUnknown } func parseCommitMessage(message string) events.TCREvent { @@ -294,15 +294,13 @@ func parseCommitHeaderAndEvents(message string) (string, events.TCREvent) { } func parseCommitStatus(header string) events.CommandStatus { - commitStatus := events.StatusUnknown if strings.Contains(header, messagePassed.Tag) { - commitStatus = events.StatusPass - } else if strings.Contains(header, messageFailed.Tag) { - commitStatus = events.StatusFail - } else { - commitStatus = events.StatusUnknown + return events.StatusPass + } + if strings.Contains(header, messageFailed.Tag) { + return events.StatusFail } - return commitStatus + return events.StatusUnknown } func (tcr *TCREngine) setMessageSuffix(suffix string) { diff --git a/src/engine/tcr_test.go b/src/engine/tcr_test.go index b6d5c082..f40ac9d6 100644 --- a/src/engine/tcr_test.go +++ b/src/engine/tcr_test.go @@ -47,7 +47,7 @@ import ( ) const ( - passedCommitMessage = "✅ [TCR - PASSED] tests passing" + passedCommitMessage = "✅ [TCR - PASSED] tests passing" //nolint:gosec failedCommitMessage = "❌ [TCR - FAILED] tests failing" revertedCommitMessage = "⏪ [TCR - REVERTED] revert changes" ) diff --git a/src/vcs/fake/vcs_test_fake.go b/src/vcs/fake/vcs_test_fake.go index 68f6eb67..c552dac7 100644 --- a/src/vcs/fake/vcs_test_fake.go +++ b/src/vcs/fake/vcs_test_fake.go @@ -82,10 +82,6 @@ type ( } ) -func (vf *VCSFake) SupportsEmojis() bool { - return vf.supportsEmojis -} - func (vf *VCSFake) fakeCommand(cmd Command) (err error) { vf.lastCommands = append(vf.lastCommands, cmd) if vf.settings.FailingCommands.contains(cmd) { @@ -219,10 +215,17 @@ func (vf *VCSFake) CheckRemoteAccess() bool { return vf.settings.RemoteAccessWorking } +// GetLastCommitSubjects returns the list of last commit subjects func (vf *VCSFake) GetLastCommitSubjects() []string { return vf.lastCommitSubjects } +// SupportsEmojis indicates if the VCS supports emojis in commit messages +func (vf *VCSFake) SupportsEmojis() bool { + return vf.supportsEmojis +} + +// SetSupportsEmojis allows to configure VCS fake's support for emojis func (vf *VCSFake) SetSupportsEmojis(flag bool) { vf.supportsEmojis = flag } diff --git a/src/vcs/git/git_impl.go b/src/vcs/git/git_impl.go index 83da5fef..a4f187a1 100644 --- a/src/vcs/git/git_impl.go +++ b/src/vcs/git/git_impl.go @@ -58,10 +58,6 @@ type gitImpl struct { traceGitFunction func(params ...string) (err error) } -func (g *gitImpl) SupportsEmojis() bool { - return true -} - // New initializes the git implementation based on the provided directory from local clone func New(dir string, remoteName string) (vcs.Interface, error) { return newGitImpl(plainOpen, dir, remoteName) @@ -388,6 +384,11 @@ func (g *gitImpl) CheckRemoteAccess() bool { return false } +// SupportsEmojis indicates if the VCS supports emojis in commit messages (true in case of git) +func (*gitImpl) SupportsEmojis() bool { + return true +} + // traceGit runs a git command and traces its output. // The command is launched from the git root directory func (g *gitImpl) traceGit(args ...string) error { diff --git a/src/vcs/p4/p4_impl.go b/src/vcs/p4/p4_impl.go index 55d3bc81..04113382 100644 --- a/src/vcs/p4/p4_impl.go +++ b/src/vcs/p4/p4_impl.go @@ -53,10 +53,6 @@ type p4Impl struct { tracePipedP4Function func(toCmd shell.Command, params ...string) (err error) } -func (p *p4Impl) SupportsEmojis() bool { - return false -} - // New initializes the p4 implementation based on the provided directory from local clone func New(dir string) (vcs.Interface, error) { return newP4Impl(plainOpen, dir, false) @@ -260,6 +256,11 @@ func (*p4Impl) CheckRemoteAccess() bool { return true } +// SupportsEmojis indicates if the VCS supports emojis in commit messages (false in case of Perforce) +func (*p4Impl) SupportsEmojis() bool { + return false +} + // traceP4 runs a p4 command and traces its output. // The command is launched from the p4 root directory func (p *p4Impl) traceP4(args ...string) error {