Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git:chore - move CommitAuthor declaration to git pkg #948

Merged
merged 1 commit into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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