Skip to content

Commit

Permalink
[#805] Fix linter errors
Browse files Browse the repository at this point in the history
- 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()
  • Loading branch information
mengdaming committed Oct 11, 2024
1 parent 5166814 commit 9f7198b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
14 changes: 6 additions & 8 deletions src/engine/tcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/engine/tcr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
11 changes: 7 additions & 4 deletions src/vcs/fake/vcs_test_fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
9 changes: 5 additions & 4 deletions src/vcs/git/git_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 5 additions & 4 deletions src/vcs/p4/p4_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 9f7198b

Please sign in to comment.