Skip to content

Commit

Permalink
services/git:bugfix - error git diff breaking parse and invalid filepath
Browse files Browse the repository at this point in the history
Signed-off-by: Nathan Martins <nathan.martins@zup.com.br>
  • Loading branch information
nathanmartinszup committed Dec 3, 2021
1 parent 59c327f commit 259fe2b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
9 changes: 7 additions & 2 deletions internal/services/formatters/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,15 @@ func (s *Service) RemoveSrcFolderFromPath(path string) string {
if path == "" || len(path) <= 4 || !strings.Contains(path[:4], "src") {
return path
}

path = strings.Replace(filepath.ToSlash(path), "/src/", "", 1)

if runtime.GOOS == "windows" {
return strings.Replace(path, `src\`, "", 1)
return filepath.FromSlash(path)
}
return strings.Replace(path, "src/", "", 1)


return path
}

func (s *Service) GetCodeWithMaxCharacters(code string, column int) string {
Expand Down
7 changes: 6 additions & 1 deletion internal/services/formatters/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,14 @@ func TestService_GetCodeWithMaxCharacters(t *testing.T) {
func TestRemoveSrcFolderFromPath(t *testing.T) {
t.Run("should return path without src prefix", func(t *testing.T) {
monitorController := NewFormatterService(&analysis.Analysis{}, testutil.NewDockerMock(), &config.Config{})
result := monitorController.RemoveSrcFolderFromPath(filepath.Join("src", "something"))
result := monitorController.RemoveSrcFolderFromPath(filepath.Join("/", "src", "something"))
assert.Equal(t, filepath.Base("something"), result)
})
t.Run("should return path without src prefix", func(t *testing.T) {
monitorController := NewFormatterService(&analysis.Analysis{}, testutil.NewDockerMock(), &config.Config{})
result := monitorController.RemoveSrcFolderFromPath(filepath.Join("/", "src", "something", "test"))
assert.Equal(t, filepath.Join("something", "test"), result)
})
t.Run("should return path without diff when src is after 4 index position", func(t *testing.T) {
monitorController := NewFormatterService(&analysis.Analysis{}, testutil.NewDockerMock(), &config.Config{})
result := monitorController.RemoveSrcFolderFromPath(filepath.Join("something", "src"))
Expand Down
1 change: 1 addition & 0 deletions internal/services/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func (g *Git) executeCMD(line, filePath string) ([]byte, error) {
"git",
"log",
"-1",
"--no-patch",
`--format={
^^^^^author^^^^^: ^^^^^%an^^^^^,
^^^^^email^^^^^:^^^^^%ae^^^^^,
Expand Down

0 comments on commit 259fe2b

Please sign in to comment.