mirror of
https://github.com/trufflesecurity/trufflehog.git
synced 2024-11-10 07:04:24 +00:00
Fix forks and repos counter, add metric for orgs enumerated (#2118)
This commit is contained in:
parent
62c628fb52
commit
75e869faff
2 changed files with 23 additions and 2 deletions
|
@ -39,4 +39,12 @@ var (
|
|||
Help: "Total number of GitHub repositories scanned.",
|
||||
},
|
||||
[]string{"source_name"})
|
||||
|
||||
githubOrgsEnumerated = promauto.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Namespace: common.MetricsNamespace,
|
||||
Subsystem: common.MetricsSubsystem,
|
||||
Name: "github_orgs_enumerated",
|
||||
Help: "Total number of GitHub organizations enumerated.",
|
||||
},
|
||||
[]string{"source_name"})
|
||||
)
|
||||
|
|
|
@ -200,6 +200,8 @@ func (s *Source) processRepos(ctx context.Context, target string, listRepos repo
|
|||
numRepos, numForks int
|
||||
)
|
||||
|
||||
uniqueOrgs := map[string]struct{}{}
|
||||
|
||||
for {
|
||||
someRepos, res, err := listRepos(ctx, target, listOpts)
|
||||
if err == nil {
|
||||
|
@ -220,7 +222,16 @@ func (s *Source) processRepos(ctx context.Context, target string, listRepos repo
|
|||
if r.GetFork() && !s.conn.IncludeForks {
|
||||
continue
|
||||
}
|
||||
numForks++
|
||||
|
||||
if r.GetFork() {
|
||||
numForks++
|
||||
}
|
||||
|
||||
numRepos++
|
||||
|
||||
if r.GetOwner().GetType() == "Organization" {
|
||||
uniqueOrgs[r.GetOwner().GetLogin()] = struct{}{}
|
||||
}
|
||||
|
||||
repoName, repoURL := r.GetFullName(), r.GetCloneURL()
|
||||
s.repoSizes.addRepo(repoURL, r.GetSize())
|
||||
|
@ -234,7 +245,9 @@ func (s *Source) processRepos(ctx context.Context, target string, listRepos repo
|
|||
}
|
||||
opts.Page = res.NextPage
|
||||
}
|
||||
logger.V(2).Info("found repos", "total", numRepos, "num_forks", numForks)
|
||||
|
||||
logger.V(2).Info("found repos", "total", numRepos, "num_forks", numForks, "num_orgs", len(uniqueOrgs))
|
||||
githubOrgsEnumerated.WithLabelValues(s.name).Set(float64(len(uniqueOrgs)))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue