Skip to content

Commit

Permalink
git:chore - move CommitAuthor declaration to git pkg (#948)
Browse files Browse the repository at this point in the history
Signed-off-by: Matheus Alcantara <matheus.alcantara@zup.com.br>
  • Loading branch information
matheusalcantarazup authored Jan 25, 2022
1 parent a175361 commit ae31579
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 31 deletions.
23 changes: 0 additions & 23 deletions internal/entities/commit_author/commit_author.go

This file was deleted.

3 changes: 1 addition & 2 deletions internal/services/formatters/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
engine "github.com/ZupIT/horusec-engine"

"github.com/ZupIT/horusec/config"
commitauthor "github.com/ZupIT/horusec/internal/entities/commit_author"
dockerentity "github.com/ZupIT/horusec/internal/entities/docker"
"github.com/ZupIT/horusec/internal/helpers/messages"
customrules "github.com/ZupIT/horusec/internal/services/custom_rules"
Expand All @@ -53,7 +52,7 @@ type CustomRules interface {

// Git is the interface that handle Git operations
type Git interface {
CommitAuthor(line string, file string) commitauthor.CommitAuthor
CommitAuthor(line string, file string) git.CommitAuthor
}

type Service struct {
Expand Down
21 changes: 15 additions & 6 deletions internal/services/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,19 @@ import (
"github.com/ZupIT/horusec-devkit/pkg/utils/logger"

"github.com/ZupIT/horusec/config"
commitauthor "github.com/ZupIT/horusec/internal/entities/commit_author"
"github.com/ZupIT/horusec/internal/helpers/messages"
)

// CommitAuthor contains commit author information to a given
// file and line.
type CommitAuthor struct {
Author string `json:"author"`
Email string `json:"email"`
CommitHash string `json:"commitHash"`
Message string `json:"message"`
Date string `json:"date"`
}

type Git struct {
config *config.Config
}
Expand All @@ -41,14 +50,14 @@ func New(cfg *config.Config) *Git {
}
}

func (g *Git) CommitAuthor(line, filePath string) commitauthor.CommitAuthor {
func (g *Git) CommitAuthor(line, filePath string) CommitAuthor {
if !g.existsGitFolderInPath() || !g.config.EnableCommitAuthor {
return g.newCommitAuthorNotFound()
}
return g.executeGitBlame(line, filePath)
}

func (g *Git) executeGitBlame(line, filePath string) commitauthor.CommitAuthor {
func (g *Git) executeGitBlame(line, filePath string) CommitAuthor {
if g.lineOrPathNotFound(line, filePath) {
return g.newCommitAuthorNotFound()
}
Expand All @@ -63,8 +72,8 @@ func (g *Git) lineOrPathNotFound(line, path string) bool {
return line == "-" || path == "-" || line == "" || path == ""
}

func (g *Git) newCommitAuthorNotFound() commitauthor.CommitAuthor {
return commitauthor.CommitAuthor{
func (g *Git) newCommitAuthorNotFound() CommitAuthor {
return CommitAuthor{
Author: "-",
Email: "-",
CommitHash: "-",
Expand Down Expand Up @@ -111,7 +120,7 @@ func (g *Git) executeCMD(line, filePath string) ([]byte, error) {
return response, err
}

func (g *Git) parseOutput(output []byte) (author commitauthor.CommitAuthor) {
func (g *Git) parseOutput(output []byte) (author CommitAuthor) {
output = g.replaceCarets(output)

if err := json.Unmarshal(output, &author); err != nil {
Expand Down

0 comments on commit ae31579

Please sign in to comment.