fix: csv report in excel

This commit is contained in:
Ramon authored and dani committed 2021-10-10 12:45:35 +02:00
commit bd707fa9c4
2 files changed
+5 -1

No files matched your search

+1
View File
@@ -35,6 +35,7 @@ release-builds:
env GOOS="linux" GOARCH="mips" go build -o "build/gitleaks-linux-mips" $(LDFLAGS)
env GOOS="linux" GOARCH="mips" go build -o "build/gitleaks-linux-mips" $(LDFLAGS)
env GOOS="darwin" GOARCH="amd64" go build -o "build/gitleaks-darwin-amd64" $(LDFLAGS)
env GOOS="darwin" GOARCH="arm64" go build -o "build/gitleaks-darwin-arm64" $(LDFLAGS)
deploy:
@echo "$(DOCKER_PASSWORD)" | docker login -u "$(DOCKER_USERNAME)" --password-stdin
+4 -1
View File
@@ -5,6 +5,7 @@ import (
"encoding/json"
"os"
"strings"
"regexp"
"time"
"github.com/sirupsen/logrus"
@@ -57,13 +58,15 @@ func WriteReport(report Report, opts options.Options, cfg config.Config) error {
return err
}
case "csv":
newLineRegex := regexp.MustCompile("[\r]*\n")
w := csv.NewWriter(file)
err = w.Write([]string{"repo", "line", "commit", "offender", "leakURL", "rule", "tags", "commitMsg", "author", "email", "file", "date"})
if err != nil {
return err
}
for _, leak := range report.Leaks {
err := w.Write([]string{leak.Repo, leak.Line, leak.Commit, leak.Offender, leak.LeakURL, leak.Rule, leak.Tags, leak.Message, leak.Author, leak.Email, leak.File, leak.Date.Format(time.RFC3339)})
commitFirstLine := newLineRegex.ReplaceAllString(leak.Message, " ")
err := w.Write([]string{leak.Repo, leak.Line, leak.Commit, leak.Offender, leak.LeakURL, leak.Rule, leak.Tags, commitFirstLine, leak.Author, leak.Email, leak.File, leak.Date.Format(time.RFC3339)})
if err != nil {
return err
}