Documentation
¶
Overview ¶
Package analyze can analyze things.
Index ¶
- Constants
- type Analyzer
- func (a *Analyzer) AnalyzeLocalRepo(ctx context.Context, repoPath string) (*models.PackageInsights, error)
- func (a *Analyzer) AnalyzeManifest(ctx context.Context, manifestReader io.Reader, manifestType string) (*models.PackageInsights, error)
- func (a *Analyzer) AnalyzeOrg(ctx context.Context, org string, numberOfGoroutines *int) ([]*models.PackageInsights, error)
- func (a *Analyzer) AnalyzeRepo(ctx context.Context, repoString string, ref string) (*models.PackageInsights, error)
- func (a *Analyzer) AnalyzeStaleBranches(ctx context.Context, repoString string, numberOfGoroutines *int, expand *bool, ...) (*models.PackageInsights, error)
- func (a *Analyzer) GeneratePackageInsights(ctx context.Context, tempDir string, repo Repository, ref string) (*models.PackageInsights, error)
- type Formatter
- type GitClient
- type ProgressBarObserver
- func (o *ProgressBarObserver) OnAnalysisStarted(description string)
- func (o *ProgressBarObserver) OnDiscoveryCompleted(_ string, totalCount int)
- func (o *ProgressBarObserver) OnFinalizeCompleted()
- func (o *ProgressBarObserver) OnFinalizeStarted(_ int)
- func (o *ProgressBarObserver) OnRepoCompleted(_ string, _ *models.PackageInsights)
- func (o *ProgressBarObserver) OnRepoError(_ string, _ error)
- func (o *ProgressBarObserver) OnRepoSkipped(_ string, _ string)
- func (o *ProgressBarObserver) OnRepoStarted(_ string)
- func (o *ProgressBarObserver) OnStepCompleted(description string)
- type ProgressObserver
- type RepoBatch
- type Repository
- type ScmClient
Constants ¶
const TEMP_DIR_PREFIX = "poutine-*"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Analyzer ¶ added in v0.9.12
type Analyzer struct {
ScmClient ScmClient
GitClient GitClient
Formatter Formatter
Config *models.Config
Opa *opa.Opa
Observer ProgressObserver
}
func NewAnalyzer ¶ added in v0.9.12
func (*Analyzer) AnalyzeLocalRepo ¶ added in v0.9.12
func (*Analyzer) AnalyzeManifest ¶ added in v1.0.1
func (*Analyzer) AnalyzeOrg ¶ added in v0.9.12
func (*Analyzer) AnalyzeRepo ¶ added in v0.9.12
func (*Analyzer) AnalyzeStaleBranches ¶ added in v0.17.0
func (*Analyzer) GeneratePackageInsights ¶ added in v0.18.0
func (a *Analyzer) GeneratePackageInsights(ctx context.Context, tempDir string, repo Repository, ref string) (*models.PackageInsights, error)
type GitClient ¶ added in v0.9.12
type GitClient interface {
Clone(ctx context.Context, clonePath string, url string, token string, ref string) error
FetchCone(ctx context.Context, clonePath string, url string, token string, ref string, cone string) error
CommitSHA(clonePath string) (string, error)
LastCommitDate(ctx context.Context, clonePath string) (time.Time, error)
GetRemoteOriginURL(ctx context.Context, repoPath string) (string, error)
GetRepoHeadBranchName(ctx context.Context, repoPath string) (string, error)
GetUniqWorkflowsBranches(ctx context.Context, clonePath string) (map[string][]models.BranchInfo, error)
BlobMatches(ctx context.Context, clonePath string, blobsha string, regex *regexp.Regexp) (bool, []byte, error)
ListFiles(clonePath string, extensions []string) (map[string][]byte, error)
Cleanup(clonePath string)
}
type ProgressBarObserver ¶ added in v1.1.3
type ProgressBarObserver struct {
// contains filtered or unexported fields
}
ProgressBarObserver implements ProgressObserver by rendering a CLI progress bar. For org analysis it shows a repo-count bar (created on OnDiscoveryCompleted). For single-repo analysis it shows a step-level bar (created on first OnStepCompleted).
func NewProgressBarObserver ¶ added in v1.1.3
func NewProgressBarObserver(quiet bool) *ProgressBarObserver
func (*ProgressBarObserver) OnAnalysisStarted ¶ added in v1.1.3
func (o *ProgressBarObserver) OnAnalysisStarted(description string)
func (*ProgressBarObserver) OnDiscoveryCompleted ¶ added in v1.1.3
func (o *ProgressBarObserver) OnDiscoveryCompleted(_ string, totalCount int)
func (*ProgressBarObserver) OnFinalizeCompleted ¶ added in v1.1.3
func (o *ProgressBarObserver) OnFinalizeCompleted()
func (*ProgressBarObserver) OnFinalizeStarted ¶ added in v1.1.3
func (o *ProgressBarObserver) OnFinalizeStarted(_ int)
func (*ProgressBarObserver) OnRepoCompleted ¶ added in v1.1.3
func (o *ProgressBarObserver) OnRepoCompleted(_ string, _ *models.PackageInsights)
func (*ProgressBarObserver) OnRepoError ¶ added in v1.1.3
func (o *ProgressBarObserver) OnRepoError(_ string, _ error)
func (*ProgressBarObserver) OnRepoSkipped ¶ added in v1.1.3
func (o *ProgressBarObserver) OnRepoSkipped(_ string, _ string)
func (*ProgressBarObserver) OnRepoStarted ¶ added in v1.1.3
func (o *ProgressBarObserver) OnRepoStarted(_ string)
func (*ProgressBarObserver) OnStepCompleted ¶ added in v1.1.3
func (o *ProgressBarObserver) OnStepCompleted(description string)
type ProgressObserver ¶ added in v1.1.3
type ProgressObserver interface {
// OnAnalysisStarted is called from the main goroutine at the very
// beginning of any analysis, before any work begins. Useful for
// rendering an initial status indicator while discovery or cloning runs.
OnAnalysisStarted(description string)
// OnDiscoveryCompleted is called from the main goroutine when the
// total repo count is known (first batch with TotalCount > 0).
OnDiscoveryCompleted(org string, totalCount int)
// OnRepoStarted is called from a worker goroutine when analysis
// of a repo begins. Must be goroutine-safe.
OnRepoStarted(repo string)
// OnRepoCompleted is called from a worker goroutine when a repo
// finishes successfully. Must be goroutine-safe.
OnRepoCompleted(repo string, pkg *models.PackageInsights)
// OnRepoError is called from a worker goroutine when a repo
// analysis fails (non-fatal). Must be goroutine-safe.
OnRepoError(repo string, err error)
// OnRepoSkipped is called from the main goroutine when a repo is
// skipped (fork, empty, etc.).
OnRepoSkipped(repo string, reason string)
// OnStepCompleted is called when a sub-step within a single-repo
// analysis completes (e.g. "Cloning repository", "Analyzing repository").
// Used by AnalyzeRepo and AnalyzeStaleBranches for step-level progress.
// Called from the main goroutine.
OnStepCompleted(description string)
// OnFinalizeStarted is called from the main goroutine when the
// formatting/output phase begins, after all repos are processed.
OnFinalizeStarted(totalPackages int)
// OnFinalizeCompleted is called from the main goroutine when
// formatting is done.
OnFinalizeCompleted()
}
ProgressObserver receives structured progress events during analysis. All methods must be non-blocking — implementations should not perform expensive I/O or hold locks for extended periods.
Concurrency ¶
During AnalyzeOrg, methods are called from two contexts:
Main goroutine (sequential, never concurrent with each other):
- OnAnalysisStarted
- OnDiscoveryCompleted
- OnRepoSkipped
- OnFinalizeStarted
- OnFinalizeCompleted
Worker goroutines (called concurrently from multiple goroutines):
- OnRepoStarted
- OnRepoCompleted
- OnRepoError
Implementations MUST ensure that the worker-goroutine methods are goroutine-safe. Note that worker methods may also run concurrently with the main-goroutine methods above.
During AnalyzeRepo and AnalyzeStaleBranches all methods are called from a single goroutine.
type RepoBatch ¶
type RepoBatch struct {
TotalCount int
Repositories []Repository
Err error
}
type Repository ¶
type Repository interface {
GetProviderName() string
GetRepoIdentifier() string
GetIsFork() bool
BuildGitURL(baseURL string) string
GetHasIssues() bool
GetHasWiki() bool
GetHasDiscussion() bool
GetOpenIssuesCount() int
GetForksCount() int
GetStarsCount() int
GetPrimaryLanguage() string
GetSize() int
GetDefaultBranch() string
GetLicense() string
GetIsTemplate() bool
GetOrganizationID() int
GetRepositoryID() int
GetIsEmpty() bool
}
type ScmClient ¶
type ScmClient interface {
GetOrgRepos(ctx context.Context, org string) <-chan RepoBatch
GetRepo(ctx context.Context, org string, name string) (Repository, error)
GetToken() string
GetProviderName() string
GetProviderVersion(ctx context.Context) (string, error)
GetProviderBaseURL() string
ParseRepoAndOrg(string) (string, string, error)
}