Documentation
¶
Index ¶
- func CountDirectories(dirPath string) (int, error)
- func DefaultGoWorkflowTypes() []string
- func GetInternalDeps(result RepoResult, allResults []RepoResult) []string
- func ParseDuration(s string) (time.Duration, error)
- type CLIGitBackend
- type GitBackend
- type GoModResult
- type ProgressFunc
- type RepoResult
- func GetTransitiveDependents(seeds []RepoResult, allResults []RepoResult) []RepoResult
- func ScanDirectory(dirPath string) ([]RepoResult, error)
- func ScanDirectoryWithProgress(dirPath string, progressFn ProgressFunc, opts ScanOptions) ([]RepoResult, error)
- func TopologicalSort(results []RepoResult) ([]RepoResult, []string)
- func (r RepoResult) HasDependency(modulePath string) bool
- func (r RepoResult) HasDirectDependency(modulePath string) bool
- func (r RepoResult) HasIssues() bool
- func (r RepoResult) MatchesDependency(modulePath string, directOnly, prefix bool) bool
- func (r RepoResult) ModifiedSince(d time.Duration) bool
- func (r RepoResult) NeedsPush() bool
- type ScanOptions
- type WorkflowCheckOptions
- type WorkflowCompliance
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CountDirectories ¶
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.
func ParseDuration ¶ added in v0.9.0
ParseDuration parses duration strings like "7d", "2w", "1m", "24h" for use with RepoResult.ModifiedSince. Supported custom units: d (days), w (weeks), m (months, 30 days). Bare N-unit values are matched against the custom format first, since Go's stdlib time.ParseDuration also accepts "m" as minutes and would otherwise shadow the "months" unit — e.g. "1m" is ambiguous between 1 minute and 1 month, and callers of this format mean months.
Combo forms the custom format doesn't match (e.g. "1h30m", "90s") fall back to time.ParseDuration.
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, err error)
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)
A non-nil err means status could not be determined; callers must not treat that as "clean" (see GitBackend.GetStatus).
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.
// err is non-nil when the status could not be determined (e.g. the git
// invocation failed); callers must not treat a non-nil err as "clean".
GetStatus(repoPath string, checkUnpushed bool) (hasUncommitted, hasUnpushed bool, err error)
}
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 ¶
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)
StatusError string // Non-empty when GetStatus failed; HasUncommittedChanges/HasUnpushedCommits are unknown, not false, in that case
}
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) HasIssues ¶ added in v0.9.0
func (r RepoResult) HasIssues() bool
HasIssues reports whether the repo has any of the issues gitscan's root command flags: uncommitted changes, replace directives, a module name mismatch, or a failed git status check.
func (RepoResult) MatchesDependency ¶ added in v0.9.0
func (r RepoResult) MatchesDependency(modulePath string, directOnly, prefix bool) bool
MatchesDependency reports whether the repo depends on modulePath.
If directOnly is set, only requirements the repo's go.mod lists without a "// indirect" comment count. If prefix is set, modulePath is matched as a path prefix (e.g. to match any major version of a module, such as "github.com/google/go-github" matching ".../go-github/v88"). When GoModFiles is populated (recurse mode), nested go.mod files are checked too.
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, or if that status could not be determined (StatusError set) — an unknown status is treated as needing attention rather than silently reported as clean.
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 git CLI 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.