Files
gitleaks/scan/commits.go
T
Zachary Rice 6adc045580 Simplify tests and continue on object not found errors (#633)
* adding files

* init better tests

* add basic .git

* more tests and test data

* nogit, unstaged tests

* removing unused testdata

* adding empty testdata

* rm gitmodules

* fixing tests

* remove with config

* adding with_config

* removing old test_data, updating config tests

* removing hooks in testdata repos
2021-09-09 11:46:31 -05:00

51 lines
1.2 KiB
Go

package scan
import (
"github.com/go-git/go-git/v5"
log "github.com/sirupsen/logrus"
"github.com/zricethezav/gitleaks/v7/config"
"github.com/zricethezav/gitleaks/v7/options"
)
// CommitsScanner is a commit scanner
type CommitsScanner struct {
opts options.Options
cfg config.Config
repo *git.Repository
repoName string
commits []string
}
// NewCommitsScanner creates and returns a commits scanner, notice the 's' in commits
func NewCommitsScanner(opts options.Options, cfg config.Config, repo *git.Repository, commits []string) *CommitsScanner {
return &CommitsScanner{
opts: opts,
cfg: cfg,
repo: repo,
commits: commits,
repoName: getRepoName(opts),
}
}
// Scan kicks off a CommitsScanner Scan
func (css *CommitsScanner) Scan() (Report, error) {
var scannerReport Report
for _, commitHash := range css.commits {
c, err := obtainCommit(css.repo, commitHash)
if err != nil {
log.Errorf("skipping %s, err: %v", commitHash, err)
continue
}
cs := NewCommitScanner(css.opts, css.cfg, css.repo, c)
commitReport, err := cs.Scan()
if err != nil {
return scannerReport, err
}
scannerReport.Leaks = append(scannerReport.Leaks, commitReport.Leaks...)
scannerReport.Commits++
}
return scannerReport, nil
}