From 8b2d11b940369592c81f0bd22c59d27080198847 Mon Sep 17 00:00:00 2001 From: Matheus Alcantara Date: Mon, 24 Jan 2022 08:48:22 -0300 Subject: [PATCH] git:chore - move CommitAuthor declaration to git pkg Signed-off-by: Matheus Alcantara --- .../entities/commit_author/commit_author.go | 23 ------------------- internal/services/formatters/service.go | 3 +-- internal/services/git/git.go | 21 ++++++++++++----- 3 files changed, 16 insertions(+), 31 deletions(-) delete mode 100644 internal/entities/commit_author/commit_author.go diff --git a/internal/entities/commit_author/commit_author.go b/internal/entities/commit_author/commit_author.go deleted file mode 100644 index 32a9a4a06..000000000 --- a/internal/entities/commit_author/commit_author.go +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2021 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package commitauthor - -type CommitAuthor struct { - Author string `json:"author"` - Email string `json:"email"` - CommitHash string `json:"commitHash"` - Message string `json:"message"` - Date string `json:"date"` -} diff --git a/internal/services/formatters/service.go b/internal/services/formatters/service.go index 2cfdea467..87a57a873 100644 --- a/internal/services/formatters/service.go +++ b/internal/services/formatters/service.go @@ -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" @@ -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 { diff --git a/internal/services/git/git.go b/internal/services/git/git.go index 8f1152898..67df957b2 100644 --- a/internal/services/git/git.go +++ b/internal/services/git/git.go @@ -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 } @@ -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() } @@ -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: "-", @@ -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 {