scanner

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 2, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CountDirectories

func CountDirectories(dirPath string) (int, error)

CountDirectories counts the number of scannable directories.

func DefaultGoWorkflowTypes

func DefaultGoWorkflowTypes() []string

DefaultGoWorkflowTypes returns the default required workflow types for Go projects.

func GetInternalDeps

func GetInternalDeps(result RepoResult, allResults []RepoResult) []string

GetInternalDeps returns dependencies that are also in the results set (managed modules). It maps from directory name to module name for matching.

Types

type CLIGitBackend

type CLIGitBackend struct{}

CLIGitBackend implements GitBackend using git CLI commands.

func NewCLIGitBackend

func NewCLIGitBackend() *CLIGitBackend

NewCLIGitBackend creates a new CLI git backend.

func (*CLIGitBackend) GetStatus

func (c *CLIGitBackend) GetStatus(repoPath string, checkUnpushed bool) (hasUncommitted, hasUnpushed bool)

GetStatus uses `git status --porcelain -b` to check both uncommitted changes and unpushed commits. Output format:

  • First line: ## branch...upstream [ahead N, behind M]
  • Remaining lines: file status (if any uncommitted changes)

func (*CLIGitBackend) IsRepo

func (c *CLIGitBackend) IsRepo(path string) bool

IsRepo checks if the path is a git repository. Delegates to the root gogit library, which also recognizes worktree gitfiles.

type GitBackend

type GitBackend interface {
	// IsRepo checks if the path is a git repository.
	IsRepo(path string) bool
	// GetStatus returns uncommitted changes and unpushed commits status.
	GetStatus(repoPath string, checkUnpushed bool) (hasUncommitted, hasUnpushed bool)
}

GitBackend provides git operations for repository scanning.

func DefaultGitBackend

func DefaultGitBackend() GitBackend

DefaultGitBackend returns the default git backend (git CLI).

type GoModResult

type GoModResult struct {
	Path               string   // Path to go.mod relative to repo root
	ModuleName         string   // Module name from go.mod
	Dependencies       []string // Required module paths (direct + indirect)
	DirectDependencies []string // Required module paths without "// indirect"
	ReplaceCount       int      // Number of replace directives
}

GoModResult holds analysis results for a single go.mod file.

type ProgressFunc

type ProgressFunc func(current, total int, name string)

ProgressFunc is called during scanning with current progress.

type RepoResult

type RepoResult struct {
	Name                  string
	Path                  string
	IsGitRepo             bool
	HasGoMod              bool
	HasUncommittedChanges bool
	HasUnpushedCommits    bool
	HasReplaceDirectives  bool
	HasModuleMismatch     bool
	ModuleName            string
	ReplaceCount          int
	Dependencies          []string           // Dependencies from root go.mod (direct + indirect)
	DirectDependencies    []string           // Dependencies from root go.mod without "// indirect"
	GoModFiles            []GoModResult      // All go.mod files (when recurse=true)
	LatestModTime         time.Time          // Most recent file modification time
	WorkflowCompliance    WorkflowCompliance // Workflow compliance status (when workflow check enabled)
}

RepoResult holds the analysis results for a single repository.

func GetTransitiveDependents

func GetTransitiveDependents(seeds []RepoResult, allResults []RepoResult) []RepoResult

GetTransitiveDependents returns all repos that transitively depend on the given seed repos. This finds repos that may need updating when seed repos are updated.

func ScanDirectory

func ScanDirectory(dirPath string) ([]RepoResult, error)

ScanDirectory scans all direct subdirectories in the given path.

func ScanDirectoryWithProgress

func ScanDirectoryWithProgress(dirPath string, progressFn ProgressFunc, opts ScanOptions) ([]RepoResult, error)

ScanDirectoryWithProgress scans directories and reports progress via callback.

func TopologicalSort

func TopologicalSort(results []RepoResult) ([]RepoResult, []string)

TopologicalSort returns repos in dependency order (dependencies before dependents). Uses Kahn's algorithm. Returns sorted results and any cycles detected.

func (RepoResult) HasDependency

func (r RepoResult) HasDependency(modulePath string) bool

HasDependency checks if the repo depends on the given module path, whether directly required or pulled in transitively as "// indirect". When GoModFiles is populated (recurse mode), checks all go.mod files.

func (RepoResult) HasDirectDependency added in v0.8.0

func (r RepoResult) HasDirectDependency(modulePath string) bool

HasDirectDependency checks if the repo directly requires the given module path (i.e. the require line has no "// indirect" comment). Unlike HasDependency, this excludes modules only pulled in transitively. When GoModFiles is populated (recurse mode), checks all go.mod files.

func (RepoResult) ModifiedSince

func (r RepoResult) ModifiedSince(d time.Duration) bool

ModifiedSince returns true if the repo has files modified within the given duration.

func (RepoResult) NeedsPush

func (r RepoResult) NeedsPush() bool

NeedsPush returns true if the repo has uncommitted changes or unpushed commits.

type ScanOptions

type ScanOptions struct {
	Recurse       bool                 // Search for nested go.mod files
	CheckModTime  bool                 // Compute latest modification time (expensive)
	CheckUnpushed bool                 // Check for unpushed commits
	Workers       int                  // Number of parallel workers (0 = GOMAXPROCS)
	GitBackend    GitBackend           // Git backend to use (nil = default go-git backend)
	Workflow      WorkflowCheckOptions // Workflow compliance checking options
}

ScanOptions configures the scanning behavior.

type WorkflowCheckOptions

type WorkflowCheckOptions struct {
	Enabled       bool
	RefRepo       string   // e.g., "plexusone/.github"
	RefBranch     string   // e.g., "main"
	RequiredTypes []string // e.g., ["go-ci", "go-lint", "go-sast-codeql"]
}

WorkflowCheckOptions configures workflow compliance checking.

type WorkflowCompliance

type WorkflowCompliance struct {
	HasWorkflows      bool     `json:"hasWorkflows"`
	WorkflowFiles     []string `json:"workflowFiles"`
	UsesReusable      bool     `json:"usesReusable"`
	ReusableWorkflows []string `json:"reusableWorkflows"`
	RefRepoMatch      bool     `json:"refRepoMatch"`
	MissingWorkflows  []string `json:"missingWorkflows"`
	ComplianceLevel   string   `json:"complianceLevel"` // full, partial, none
}

WorkflowCompliance represents workflow compliance status for a repository.

func CheckWorkflowCompliance

func CheckWorkflowCompliance(repoPath string, opts WorkflowCheckOptions) WorkflowCompliance

CheckWorkflowCompliance checks workflow compliance for a repository.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL