diff --git a/CHANGELOG.md b/CHANGELOG.md index 509af0aa..358ee315 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ CHANGELOG 1.13.0 ---- - Github PR support +- Github has its own go file. All other services, bitbucket, gitlab, etc should follow this convention 1.12.1 ---- diff --git a/README.md b/README.md index 005bb275..a5ac3a0c 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ Application Options: --github-user= Github user to audit --github-org= Github organization to audit --github-url= GitHub API Base URL, use for GitHub Enterprise. Example: https://github.example.com/api/v3/ (default: https://api.github.com/) + --github-pr= Github PR url to audit. This does not clone the repo. GITHUB_TOKEN must be set -p, --private Include private repos in audit -b, --branch= branch name to audit (defaults to HEAD) -c, --commit= sha of commit to stop at diff --git a/gitleaks_test.go b/gitleaks_test.go index 611e1ea2..6c93a368 100644 --- a/gitleaks_test.go +++ b/gitleaks_test.go @@ -198,6 +198,7 @@ func TestRun(t *testing.T) { whiteListRepos []string numLeaks int configPath string + commitPerPage int }{ { testOpts: Options{ @@ -293,6 +294,23 @@ func TestRun(t *testing.T) { numLeaks: 0, expectedErrMsg: "", }, + { + testOpts: Options{ + GithubPR: "https://github.com/gitleakstest/gronit/pull/1", + }, + description: "test github pr", + numLeaks: 4, + expectedErrMsg: "", + }, + { + testOpts: Options{ + GithubPR: "https://github.com/gitleakstest/gronit/pull/1", + }, + description: "test github pr", + numLeaks: 4, + expectedErrMsg: "", + commitPerPage: 1, + }, } g := goblin.Goblin(t) for _, test := range tests { @@ -301,12 +319,16 @@ func TestRun(t *testing.T) { if test.configPath != "" { os.Setenv("GITLEAKS_CONFIG", test.configPath) } + if test.commitPerPage != 0 { + githubPages = test.commitPerPage + } opts = test.testOpts leaks, err := run() if err != nil { g.Assert(err.Error()).Equal(test.expectedErrMsg) } g.Assert(len(leaks)).Equal(test.numLeaks) + githubPages = 100 }) }) } diff --git a/main.go b/main.go index 72182d93..95138e4f 100644 --- a/main.go +++ b/main.go @@ -63,7 +63,7 @@ type Options struct { GithubUser string `long:"github-user" description:"Github user to audit"` GithubOrg string `long:"github-org" description:"Github organization to audit"` GithubURL string `long:"github-url" default:"https://api.github.com/" description:"GitHub API Base URL, use for GitHub Enterprise. Example: https://github.example.com/api/v3/"` - GithubPR string `long:"github-pr" description:"Github PR number to audit. This does not clone the repo."` + GithubPR string `long:"github-pr" description:"Github PR url to audit. This does not clone the repo. GITHUB_TOKEN must be set"` IncludePrivate bool `short:"p" long:"private" description:"Include private repos in audit"` /* @@ -240,10 +240,11 @@ func main() { if opts.Report != "" { writeReport(leaks) } - log.Infof("%d commits inspected in %s", totalCommits, durafmt.Parse(time.Now().Sub(now)).String()) if len(leaks) != 0 { - log.Warnf("%d leaks detected", len(leaks)) + log.Warnf("%d leaks detected. %d commits inspected in %s", len(leaks), totalCommits, durafmt.Parse(time.Now().Sub(now)).String()) os.Exit(leakExit) + } else { + log.Infof("%d leaks detected. %d commits inspected in %s", len(leaks), totalCommits, durafmt.Parse(time.Now().Sub(now)).String()) } }