Documentation
¶
Overview ¶
Package hercules contains the functions which are needed to gather various statistics from a Git repository.
The analysis is expressed in a form of the tree: there are nodes - "pipeline items" - which require some other nodes to be executed prior to selves and in turn provide the data for dependent nodes. There are several service items which do not produce any useful statistics but rather provide the requirements for other items. The top-level items include:
- BurndownAnalysis - line burndown statistics for project, files and developers.
- CouplesAnalysis - coupling statistics for files and developers.
- ShotnessAnalysis - structural hotness and couples, powered by tree-sitter in the default build.
The typical API usage is to initialize the Pipeline class:
import "github.com/go-git/go-git/v5" var repository *git.Repository // ...initialize repository... pipeline := hercules.NewPipeline(repository)
Then add the required analysis:
ba := pipeline.DeployItem(&hercules.BurndownAnalysis{}).(hercules.LeafPipelineItem)
This call will add all the needed intermediate pipeline items. Then link and execute the analysis tree:
pipeline.Initialize(nil) result, err := pipeline.Run(pipeline.Commits(false))
Finally extract the result:
result := result[ba].(hercules.BurndownResult)
The actual usage example is cmd/hercules/root.go - the command line tool's code.
You can provide additional options via `facts` on initialization. For example, to provide your own logger, enable people-tracking, and set a custom tick size:
pipe.Initialize(map[string]interface{}{
hercules.ConfigLogger: zap.NewExample().Sugar(),
hercules.ConfigTickSize: 12,
leaves.ConfigBurndownTrackPeople: true,
})
Hercules depends heavily on https://github.com/go-git/go-git and leverages the diff algorithm through https://github.com/sergi/go-diff.
Besides, BurndownAnalysis involves File and RBTree. These are low level data structures which enable incremental blaming. File carries an instance of RBTree and the current line burndown state. RBTree implements the red-black balanced binary tree and is based on https://github.com/yasushi-saito/rbtree.
Coupling stats are supposed to be further processed rather than observed directly. labours.py uses Swivel embeddings and visualises them in Tensorflow Projector.
Structural analyses and comment extraction are powered by tree-sitter in the default build.
Index ¶
- Constants
- Variables
- func EnablePathFlagTypeMasquerade()
- func FactValue[T any](facts map[string]any, key string) (T, bool, error)
- func LoadCommitsFromFile(path string, repository *git.Repository) ([]*object.Commit, error)
- func NewLogger() core.Logger
- func PathifyFlagValue(flag *pflag.Flag)
- func QualifyRepositoryPath(repository, path string) string
- func RequiredFactValue[T any](facts map[string]any, key string) (T, error)
- func SafeYamlString(str string) string
- type CachedBlob
- type CommitComponent
- type CommonAnalysisResult
- type ConfigurationOption
- type ConfigurationOptionType
- type DisconnectedCommitsError
- type DisposablePipelineItem
- type DuplicateCommitError
- type FactTypeError
- type FeaturedPipelineItem
- type FileDiffData
- type FileIdResolver
- type FlagConfiguration
- type HibernateablePipelineItem
- type IdentityResolver
- type LeafPipelineItem
- type Logger
- type NoopMerger
- type OneShotMergeProcessor
- type Pipeline
- type PipelineItem
- type PipelineItemRegistry
- type RepositoryQualifiablePipelineItem
- type ResultMergeablePipelineItem
Constants ¶
const ( // BoolConfigurationOption reflects the boolean value type. BoolConfigurationOption = core.BoolConfigurationOption // IntConfigurationOption reflects the integer value type. IntConfigurationOption = core.IntConfigurationOption // StringConfigurationOption reflects the string value type. StringConfigurationOption = core.StringConfigurationOption // FloatConfigurationOption reflects a floating point value type. FloatConfigurationOption = core.FloatConfigurationOption // StringsConfigurationOption reflects the array of strings value type. StringsConfigurationOption = core.StringsConfigurationOption // PathConfigurationOption reflects a filesystem path value type. PathConfigurationOption = core.PathConfigurationOption // MessageFinalize is the status text reported before calling LeafPipelineItem.Finalize()-s. MessageFinalize = core.MessageFinalize )
const ( // ConfigPipelineDAGPath is the name of the Pipeline configuration option (Pipeline.Initialize()) // which enables saving the items DAG to the specified file. ConfigPipelineDAGPath = core.ConfigPipelineDAGPath // ConfigPipelineDumpPlan is the name of the Pipeline configuration option (Pipeline.Initialize()) // which outputs the execution plan to stderr. ConfigPipelineDumpPlan = core.ConfigPipelineDumpPlan // ConfigPipelineDryRun is the name of the Pipeline configuration option (Pipeline.Initialize()) // which disables Configure() and Initialize() invocation on each PipelineItem during the // Pipeline initialization. // Subsequent Run() calls are going to fail. Useful with ConfigPipelineDAGPath=true. ConfigPipelineDryRun = core.ConfigPipelineDryRun // ConfigPipelineCommits is the name of the Pipeline configuration option (Pipeline.Initialize()) // which allows to specify the custom commit sequence. By default, Pipeline.Commits() is used. ConfigPipelineCommits = core.ConfigPipelineCommits // ConfigTickSize is the number of hours per 'tick'. ConfigTickSize = plumbing.ConfigTicksSinceStartTickSize // ConfigLogger is used to set the logger in all pipeline items. ConfigLogger = core.ConfigLogger )
const ( // DependencyCommit is the name of one of the three items in `deps` supplied to PipelineItem.Consume() // which always exists. It corresponds to the currently analyzed commit. DependencyCommit = core.DependencyCommit // DependencyIndex is the name of one of the three items in `deps` supplied to PipelineItem.Consume() // which always exists. It corresponds to the currently analyzed commit's index. DependencyIndex = core.DependencyIndex // DependencyIsMerge is the name of one of the three items in `deps` supplied to PipelineItem.Consume() // which always exists. It indicates whether the analyzed commit is a merge commit. // Checking the number of parents is not correct - we remove the back edges during the DAG simplification. DependencyIsMerge = core.DependencyIsMerge // DependencyAuthor is the name of the dependency provided by identity.PeopleDetector. DependencyAuthor = identity.DependencyAuthor // DependencyBlobCache identifies the dependency provided by BlobCache. DependencyBlobCache = plumbing.DependencyBlobCache // DependencyTick is the name of the dependency which TicksSinceStart provides - the number // of ticks since the first commit in the analysed sequence. DependencyTick = plumbing.DependencyTick // DependencyFileDiff is the name of the dependency provided by FileDiff. DependencyFileDiff = plumbing.DependencyFileDiff // DependencyTreeChanges is the name of the dependency provided by TreeDiff. DependencyTreeChanges = plumbing.DependencyTreeChanges // FactCommitsByTick contains the mapping between tick indices and the corresponding commits. FactCommitsByTick = plumbing.FactCommitsByTick // FactIdentityDetectorReversedPeopleDict is the name of the fact which is inserted in // identity.PeopleDetector.Configure(). It corresponds to identity.PeopleDetector.ReversedPeopleDict - // the mapping from the author indices to the main signature. FactIdentityDetectorReversedPeopleDict = identity.FactIdentityDetectorReversedPeopleDict // FactIdentityResolver identifies the typed author identity resolver. FactIdentityResolver = core.FactIdentityResolver // FactLineHistoryResolver identifies the typed file identity resolver. FactLineHistoryResolver = core.FactLineHistoryResolver )
const RepositoryPathSeparator = core.RepositoryPathSeparator
RepositoryPathSeparator separates the repository from the path in a qualified path key.
Variables ¶
var ( // ErrNoCommits indicates that an explicit commit input or execution plan is empty. ErrNoCommits = core.ErrNoCommits // ErrNoReferences indicates that a repository does not contain a usable commit reference. ErrNoReferences = core.ErrNoReferences // ErrInvalidCommit indicates that explicit input contains a nil or zero-hash commit. ErrInvalidCommit = core.ErrInvalidCommit // ErrDuplicateCommits indicates that explicit input repeats a commit hash. ErrDuplicateCommits = core.ErrDuplicateCommits // ErrDisconnectedCommits indicates that explicit input has disconnected components. ErrDisconnectedCommits = core.ErrDisconnectedCommits // ErrInvalidFactType indicates that a configuration or shared fact has an unexpected type. ErrInvalidFactType = core.ErrInvalidFactType // ErrFactMissing indicates that a required fact is absent. ErrFactMissing = core.ErrFactMissing )
var BinaryGitHash = "<unknown>"
BinaryGitHash is the Git hash of the Hercules binary file which is executing.
var BinaryVersion = detectBinaryVersion()
BinaryVersion is Hercules' API version. It matches the package name.
var Registry = core.Registry
Registry contains all known pipeline item types.
Functions ¶
func EnablePathFlagTypeMasquerade ¶
func EnablePathFlagTypeMasquerade()
EnablePathFlagTypeMasquerade changes the type of all "path" command line arguments from "string" to "path". This operation cannot be canceled and is intended to be used for better --help output.
func LoadCommitsFromFile ¶
LoadCommitsFromFile reads the file by the specified FS path and generates the sequence of commits by interpreting each line as a Git commit hash.
func PathifyFlagValue ¶
PathifyFlagValue changes the type of a string command line argument to "path".
func QualifyRepositoryPath ¶
QualifyRepositoryPath prefixes a repository-local path with the repository which contains it. Implementations of RepositoryQualifiablePipelineItem must build their keys with it rather than concatenating the separator themselves.
func RequiredFactValue ¶
RequiredFactValue reads a required fact with an exact type check.
func SafeYamlString ¶
SafeYamlString escapes the string so that it can be reliably used in YAML.
Types ¶
type CachedBlob ¶
type CachedBlob = plumbing.CachedBlob
CachedBlob allows to explicitly cache the binary data associated with the Blob object. Such structs are returned by DependencyBlobCache.
type CommitComponent ¶
type CommitComponent = core.CommitComponent
CommitComponent describes one connected component in explicit commit input.
type CommonAnalysisResult ¶
type CommonAnalysisResult = core.CommonAnalysisResult
CommonAnalysisResult holds the information which is always extracted at Pipeline.Run().
func MetadataToCommonAnalysisResult ¶
func MetadataToCommonAnalysisResult(meta *core.Metadata) *CommonAnalysisResult
MetadataToCommonAnalysisResult copies the data from a Protobuf message.
type ConfigurationOption ¶
type ConfigurationOption = core.ConfigurationOption
ConfigurationOption allows for the unified, retrospective way to setup PipelineItem-s.
type ConfigurationOptionType ¶
type ConfigurationOptionType = core.ConfigurationOptionType
ConfigurationOptionType represents the possible types of a ConfigurationOption's value.
type DisconnectedCommitsError ¶
type DisconnectedCommitsError = core.DisconnectedCommitsError
DisconnectedCommitsError describes disconnected explicit commit input.
type DisposablePipelineItem ¶
type DisposablePipelineItem = core.DisposablePipelineItem
DisposablePipelineItem owns resources which are released after a pipeline run.
type DuplicateCommitError ¶
type DuplicateCommitError = core.DuplicateCommitError
DuplicateCommitError describes a repeated hash in explicit commit input.
type FactTypeError ¶
type FactTypeError = core.FactTypeError
FactTypeError describes a type mismatch in a configuration or shared fact.
type FeaturedPipelineItem ¶
type FeaturedPipelineItem = core.FeaturedPipelineItem
FeaturedPipelineItem enables switching the automatic insertion of pipeline items on or off.
type FileDiffData ¶
type FileDiffData = plumbing.FileDiffData
FileDiffData is the type of the dependency provided by plumbing.FileDiff.
type FileIdResolver ¶
type FileIdResolver = core.FileIdResolver
FileIdResolver provides typed access to configured file identities.
type FlagConfiguration ¶
type FlagConfiguration = core.FlagConfiguration
FlagConfiguration retains typed flag storage until it is snapshotted after parsing.
type HibernateablePipelineItem ¶
type HibernateablePipelineItem = core.HibernateablePipelineItem
HibernateablePipelineItem can compact and restore branch-local run state.
type IdentityResolver ¶
type IdentityResolver = core.IdentityResolver
IdentityResolver provides typed access to configured author identities.
type LeafPipelineItem ¶
type LeafPipelineItem = core.LeafPipelineItem
LeafPipelineItem corresponds to the top level pipeline items which produce the end results.
type NoopMerger ¶
type NoopMerger = core.NoopMerger
NoopMerger provides an empty Merge() method suitable for PipelineItem.
type OneShotMergeProcessor ¶
type OneShotMergeProcessor = core.OneShotMergeProcessor
OneShotMergeProcessor provides the convenience method to consume merges only once.
type Pipeline ¶
Pipeline is the core Hercules entity which carries several PipelineItems and executes them. See the extended example of how a Pipeline works in doc.go.
func NewPipeline ¶
func NewPipeline(repository *git.Repository) *Pipeline
NewPipeline initializes a new instance of Pipeline struct.
type PipelineItem ¶
type PipelineItem = core.PipelineItem
PipelineItem is the interface for all the units in the Git commits analysis pipeline.
func ForkCopyPipelineItem ¶
func ForkCopyPipelineItem(origin PipelineItem, n int) []PipelineItem
ForkCopyPipelineItem clones items by copying them by value from the origin.
func ForkSamePipelineItem ¶
func ForkSamePipelineItem(origin PipelineItem, n int) []PipelineItem
ForkSamePipelineItem clones items by referencing the same origin.
type PipelineItemRegistry ¶
type PipelineItemRegistry = core.PipelineItemRegistry
PipelineItemRegistry contains all the known PipelineItem-s.
type RepositoryQualifiablePipelineItem ¶
type RepositoryQualifiablePipelineItem = core.RepositoryQualifiablePipelineItem
RepositoryQualifiablePipelineItem produces results keyed by repository-local paths.
type ResultMergeablePipelineItem ¶
type ResultMergeablePipelineItem = core.ResultMergeablePipelineItem
ResultMergeablePipelineItem specifies the methods to combine several analysis results together.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
hercules
command
|
|
|
hercules-action
command
|
|
|
labours
command
|
|
|
schema-guard
command
schema-guard compares two PB schema snapshots (internal/pb/pb.schema.json) and enforces the compatibility policy from docs/SCHEMAS.md: every schema change needs a docs/SCHEMA_CHANGELOG.md entry, and breaking changes additionally need a pb.SchemaVersion bump.
|
schema-guard compares two PB schema snapshots (internal/pb/pb.schema.json) and enforces the compatibility policy from docs/SCHEMAS.md: every schema change needs a docs/SCHEMA_CHANGELOG.md entry, and breaking changes additionally need a pb.SchemaVersion bump. |
|
contrib
|
|
|
_plugin_example
command
|
|
|
analysisio
Package analysisio contains shared validation and bounded-input helpers for serialized Hercules analysis results.
|
Package analysisio contains shared validation and bounded-input helpers for serialized Hercules analysis results. |
|
pb/schema
Package schema parses internal/pb/pb.proto into a comparable snapshot and classifies schema changes as compatible or breaking according to the policy in docs/SCHEMAS.md.
|
Package schema parses internal/pb/pb.proto into a comparable snapshot and classifies schema changes as compatible or breaking according to the policy in docs/SCHEMAS.md. |
|
plumbing/imports/lang
Package lang implements per-language import extraction over a pure-Go tree-sitter runtime (github.com/odvcencio/gotreesitter).
|
Package lang implements per-language import extraction over a pure-Go tree-sitter runtime (github.com/odvcencio/gotreesitter). |
|
render
Package render exposes the labours rendering pipeline as an in-process API: it turns a hercules analysis result (YAML or protobuf) into rendered chart files, mirroring the behavior of the standalone labours CLI.
|
Package render exposes the labours rendering pipeline as an in-process API: it turns a hercules analysis result (YAML or protobuf) into rendered chart files, mirroring the behavior of the standalone labours CLI. |
|
render/outputpath
Package outputpath plans collision-resistant renderer output paths.
|
Package outputpath plans collision-resistant renderer output paths. |
|
tickgrid
Package tickgrid holds the rule that turns wall-clock time into hercules' tick grid.
|
Package tickgrid holds the rule that turns wall-clock time into hercules' tick grid. |
|
test
|
|








