Documentation
¶
Overview ¶
SPDX-License-Identifier: MIT
SPDX-License-Identifier: MIT Package model holds the domain types shared across commit-query providers. It is a leaf package with no internal dependencies so provider clients and renderers can depend on it without creating import cycles.
Index ¶
Constants ¶
const ( WindowDateBasisCommitter = "committer" WindowDateBasisAuthor = "author" )
Window date basis values for ActivityResult.WindowDateBasis. GitHub's list-commits since/until filter on the committer date, which diverges from the author date after a rebase, cherry-pick, or amend; the result states which date bounded the window rather than leaving it implicit.
const ( // BaseSourceParentOfEarliest is the ordinary case: the comparison base is // the first parent of the earliest in-window commit. BaseSourceParentOfEarliest = "parent-of-earliest" // BaseSourceRepositoryRoot means the earliest in-window commit is the // repository's root commit, so there is no parent to compare against. The // comparison runs from that root commit itself, which makes its contents // the base state: the files it introduced are NOT reported as changes in // the window. BaseSHA is empty in this case, and a disclosure states the // limitation. BaseSourceRepositoryRoot = "repository-root" )
Base sources for Boundaries.BaseSource.
const ( StatusAhead = "ahead" StatusIdentical = "identical" StatusDiverged = "diverged" StatusBehind = "behind" )
Comparison statuses reported by the provider for a boundary comparison.
const ( // BasisObserved means per-commit file data was actually fetched and lists // the path. Certain. BasisObserved = "observed" // BasisInferred means a declared rule produced the association; Rule names // which one. BasisInferred = "inferred" )
Correlation bases. A correlation MUST NOT carry BasisObserved unless ActivityCommit.Enriched is true for every SHA it names.
const ( // RulePathMention fires when the commit message body contains the path // verbatim. Strong. RulePathMention = "path-mention" // RuleScopeMatch fires when a Conventional Commit scope matches a leading // path segment. Weak: a scope names a component, not a path, and the two // only usually coincide. RuleScopeMatch = "scope-match" )
Correlation rules, recorded in Correlation.Rule for inferred bases.
const ( // DisclosureBudgetBounded: the request ceiling stopped the query. DisclosureBudgetBounded = "budget-bounded" // DisclosureQuotaExhausted: the provider rate limit stopped the query. DisclosureQuotaExhausted = "quota-exhausted" // DisclosureProviderCapped: the comparison hit the provider's file cap. DisclosureProviderCapped = "provider-capped" // DisclosurePatchTruncated: patch text exceeded MaxDiffBytes. DisclosurePatchTruncated = "patch-truncated" // DisclosureAncestryDiverged: the boundaries do not share ancestry. DisclosureAncestryDiverged = "ancestry-diverged" // DisclosureNetComparisonBlindspot is unconditional whenever a change set // is produced. DisclosureNetComparisonBlindspot = "net-comparison-blindspot" // DisclosureReferenceScoped is unconditional whenever a change set is // produced. DisclosureReferenceScoped = "reference-scoped" // DisclosureAuthorFilterNotApplied: an author filter narrowed the commit // list but cannot narrow the change set. DisclosureAuthorFilterNotApplied = "author-filter-not-applied" // DisclosureEnrichmentPartial: the enrichment subset delivered was smaller // than the one requested. DisclosureEnrichmentPartial = "enrichment-partial" )
Disclosure kinds. The two marked unconditional below are emitted whenever a change set is produced, including on a completely clean result: a boundary comparison always carries the blind spots, so stating them only when something went wrong would overstate the ordinary case.
const ActivitySchemaVersion = "sting.activity.skaphos.io/v1"
ActivitySchemaVersion pins the ActivityResult contract, independently of SchemaVersion which pins Result. Bump it on any breaking change to ActivityResult or the types it contains. The two versions are deliberately separate: a repository-activity change must not force downstream consumers that only read Result (e.g. a Wake evidence adapter) to re-pin.
const DefaultMaxDiffBytes = 60000
DefaultMaxDiffBytes is the default per-commit patch-text budget used when a query requests full diffs but does not set an explicit limit.
const DefaultMaxRequests = 500
DefaultMaxRequests bounds the provider requests a single query may consume. It is a fixed constant by design: deriving it from remaining quota would make the same request return different results on different runs, breaking the determinism the evidence contract depends on.
const SchemaVersion = "sting.skaphos.io/v2"
SchemaVersion identifies the sting Result contract. It is emitted on every Result so downstream consumers (e.g. a Wake evidence adapter) can pin the shape they map from and detect drift. Bump it on any breaking change to Result or Commit.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActivityCommit ¶ added in v1.1.0
type ActivityCommit struct {
SHA string `json:"sha"`
Repo string `json:"repo"`
Author string `json:"author,omitempty"`
AuthorName string `json:"author_name"`
Email string `json:"email,omitempty"`
URL string `json:"url"`
// Message is the full commit message body, not just the summary.
Message string `json:"message"`
// AuthorDate is the git author date; CommitterDate is the git committer
// date. They diverge after a rebase, cherry-pick, or amend, and GitHub
// bounds the window by the latter.
AuthorDate time.Time `json:"author_date"`
CommitterDate time.Time `json:"committer_date"`
// ParentSHAs lists the commit's parents; the first element is the first
// parent, which is what boundary resolution follows.
ParentSHAs []string `json:"parent_shas,omitempty"`
// Enriched is true only when per-commit detail was actually fetched. It is
// the precondition for any observed correlation naming this commit.
Enriched bool `json:"enriched,omitempty"`
// Files is populated only when Enriched.
Files []File `json:"files,omitempty"`
}
ActivityCommit is a commit in an activity window. It is deliberately distinct from Commit rather than a reuse: it carries the parent SHAs and committer date that boundary resolution needs, and Commit is pinned by SchemaVersion so it must not gain fields.
func (ActivityCommit) Summary ¶ added in v1.1.0
func (c ActivityCommit) Summary() string
Summary is the first line of the commit message.
type ActivityQuery ¶ added in v1.1.0
type ActivityQuery struct {
// Provider is the source control provider. Only ProviderGitHub is
// supported; anything else is rejected at resolve time.
Provider Provider
// Repo is the "owner/name" target.
Repo string
// Ref is the branch or tag to examine. Empty means the repository's
// default branch.
Ref string
// Since and Until bound the window, normalized to UTC.
Since time.Time
Until time.Time
// Author optionally narrows the commit listing. The change set is not
// author-filtered — a boundary comparison has no notion of authorship —
// and a disclosure says so whenever both are present.
Author string
// IncludeDiffs requests bounded patch text in the change set.
IncludeDiffs bool
// MaxDiffBytes caps patch text; 0 uses DefaultMaxDiffBytes.
MaxDiffBytes int
// EnrichCommits is the size of the opt-in per-commit detail subset. It
// costs one request per commit and is what enables observed (rather than
// inferred) path attribution. 0 disables enrichment.
EnrichCommits int
// MaxRequests caps the provider requests this query may consume. 0
// disables the ceiling; it defaults to DefaultMaxRequests.
MaxRequests int
// EstimateOnly reports projected cost and stops, gathering no evidence.
EstimateOnly bool
}
ActivityQuery is the resolved, normalized repository-activity request. It is produced once by config.ResolveActivity and never mutated downstream, so the window is normalized at exactly one boundary.
type ActivityResult ¶ added in v1.1.0
type ActivityResult struct {
// SchemaVersion pins the ActivityResult contract; it is always
// ActivitySchemaVersion and never the zero value.
SchemaVersion string `json:"schema_version"`
GeneratedAt time.Time `json:"generated_at"`
Provider Provider `json:"provider"`
Repo string `json:"repo"`
// Ref is the reference actually compared, never empty in output.
Ref string `json:"ref"`
Since time.Time `json:"since"`
Until time.Time `json:"until"`
// WindowDateBasis names which commit date bounded the window: "committer"
// or "author". GitHub filters on the committer date.
WindowDateBasis string `json:"window_date_basis"`
Boundaries Boundaries `json:"boundaries"`
Count int `json:"count"`
Commits []ActivityCommit `json:"commits"`
ChangeSet ChangeSet `json:"change_set"`
Correlations []Correlation `json:"correlations,omitempty"`
// Cost is always populated, including on every early-return path: a query
// that stopped early must still report what it spent.
Cost CostReport `json:"cost"`
// Disclosures record everything that bounded or degraded the result, plus
// the two unconditional blind-spot statements that accompany any change
// set.
Disclosures []Disclosure `json:"disclosures,omitempty"`
}
ActivityResult is a repository's activity over a window: the commits, the aggregate change set derived from comparing the window's boundary states, the correlations between them, and what the whole thing cost. Every field exists so the result can be re-derived and audited.
type Boundaries ¶ added in v1.1.0
type Boundaries struct {
// BaseSHA is the parent of the earliest in-window commit. Empty when the
// earliest in-window commit is the repository root.
BaseSHA string `json:"base_sha"`
// HeadSHA is the latest in-window commit.
HeadSHA string `json:"head_sha"`
// BaseSource records how the base was chosen: BaseSourceParentOfEarliest
// or BaseSourceRepositoryRoot. Resolution is by ancestry, never by
// timestamp proximity.
BaseSource string `json:"base_source"`
// Status is the provider's comparison status: ahead, identical, diverged,
// or behind.
Status string `json:"status"`
// case the change set is suppressed rather than rendered.
SharedRoot bool `json:"shared_ancestry"`
}
Boundaries are the two commits a change set was derived from.
type ChangeSet ¶ added in v1.1.0
type ChangeSet struct {
// Paths is sorted lexicographically so identical upstream state yields
// byte-identical output; provider ordering is not guaranteed stable.
Paths []ChangedPath `json:"paths"`
TotalAdditions int `json:"total_additions"`
TotalDeletions int `json:"total_deletions"`
// Truncated is true when the provider's file cap clipped the comparison.
Truncated bool `json:"truncated,omitempty"`
}
ChangeSet is the aggregate per-path delta between the window's boundaries.
type ChangedPath ¶ added in v1.1.0
type ChangedPath struct {
Path string `json:"path"`
PreviousPath string `json:"previous_path,omitempty"`
Status string `json:"status"`
Additions int `json:"additions"`
Deletions int `json:"deletions"`
Patch string `json:"patch,omitempty"`
PatchTruncated bool `json:"patch_truncated,omitempty"`
}
ChangedPath is one path's net change across the window.
type Commit ¶
type Commit struct {
SHA string `json:"sha"`
Repo string `json:"repo"` // "owner/repo"
Author string `json:"author,omitempty"` // GitHub login, if known
AuthorName string `json:"author_name"` // git author name
Email string `json:"email,omitempty"` // git author email
Date time.Time `json:"date"` // git author date
Message string `json:"message"` // full commit message
URL string `json:"url"` // html_url
// Source records how the commit was discovered so a match is auditable:
// "search" (commit search index), "repo" (default-branch listing), or
// "pull/<n>" (open pull-request branch). Empty for provider paths that do
// not tag a source (e.g. GitLab).
Source string `json:"source,omitempty"`
Additions int `json:"additions,omitempty"`
Deletions int `json:"deletions,omitempty"`
Changes int `json:"changes,omitempty"`
Files []File `json:"files,omitempty"`
}
Commit is a normalized commit record independent of the GitHub API shape.
type Correlation ¶ added in v1.1.0
type Correlation struct {
Path string `json:"path"`
// SHAs is sorted; empty means the path is unattributed.
SHAs []string `json:"shas,omitempty"`
// Basis is BasisObserved or BasisInferred.
Basis string `json:"basis"`
// Rule names the rule that produced an inferred basis.
Rule string `json:"rule,omitempty"`
}
Correlation links a changed path to the commits that plausibly produced it, labeled with how the link was established so a consumer can tell observation from inference and filter accordingly.
type CostReport ¶ added in v1.1.0
type CostReport struct {
// Estimated is the projected request count; 0 when no estimate was run.
Estimated int `json:"estimated"`
Consumed int `json:"consumed"`
// Ceiling is the configured request cap; 0 means disabled.
Ceiling int `json:"ceiling"`
QuotaRemaining int `json:"quota_remaining"`
QuotaLimit int `json:"quota_limit"`
QuotaResetsAt time.Time `json:"quota_resets_at,omitempty"`
}
CostReport accounts for what a query consumed and what quota remains. It is always populated, including on failure paths.
type Disclosure ¶ added in v1.1.0
type Disclosure struct {
Kind string `json:"kind"`
Reason string `json:"reason"`
NextAction string `json:"next_action,omitempty"`
}
Disclosure states something that bounded or degraded a result, with the reason and, where one exists, the next action. A failure or a limit with no stated reason is a defect.
type File ¶ added in v0.0.3
type File struct {
Path string `json:"path"`
PreviousPath string `json:"previous_path,omitempty"`
Status string `json:"status,omitempty"`
Additions int `json:"additions,omitempty"`
Deletions int `json:"deletions,omitempty"`
Changes int `json:"changes,omitempty"`
Patch string `json:"patch,omitempty"`
PatchTruncated bool `json:"patch_truncated,omitempty"`
}
File is a normalized file-level change record for a commit.
type Provider ¶
type Provider string
Provider identifies the source control provider a query targets.
type Query ¶
type Query struct {
// Provider is the source control provider to query.
Provider Provider
// Author is the provider author identifier whose commits are wanted. For
// GitHub this is a login or an email; in the search scope an email is
// matched with the author-email: qualifier and a login with author:. For
// GitLab this is matched against the commit author string.
Author string
// Since and Until bound the commit author date, inclusive. A zero Until
// means "now".
Since time.Time
Until time.Time
// Scope selects the discovery strategy.
Scope Scope
// Repos is the list of "owner/repo" targets for ScopeRepos.
Repos []string
// Org is the organization login for ScopeOrg.
Org string
// IncludeStats requests per-commit additions/deletions. This costs one
// extra API call per commit, so it is off by default.
IncludeStats bool
// IncludeFiles requests per-file change summaries. Providers usually fetch
// this from the same detail endpoint as stats.
IncludeFiles bool
// IncludeDiffs requests patch text for changed files. This implies
// IncludeFiles and is bounded by MaxDiffBytes.
IncludeDiffs bool
// MaxDiffBytes caps patch text per commit when IncludeDiffs is true.
MaxDiffBytes int
// MaxCommits caps the number of commits returned (0 = no cap).
MaxCommits int
// IncludePullRequests augments repos/org discovery with commits found on
// open pull-request branches. These commits are not yet on a default branch,
// so commit search and branch listing miss them; enabling this enumerates
// open PRs per repo and merges author-matching commits as evidence. It costs
// extra API calls (one PR list + one commit list per PR), so it is off by
// default. GitHub only; ignored for GitLab.
IncludePullRequests bool
// MaxRequests caps the provider API requests this query may consume
// (0 = no cap). Reaching the cap yields the partial results gathered so far
// rather than an abort.
//
// Query is a request type, not part of the serialized evidence contract, so
// adding a field here does not bump SchemaVersion.
MaxRequests int
}
Query describes a single commit-retrieval request.
type Result ¶
type Result struct {
// SchemaVersion pins the Result contract (see the package SchemaVersion
// constant). GeneratedAt records when the query ran, giving the result
// evidence-style provenance.
SchemaVersion string `json:"schema_version"`
GeneratedAt time.Time `json:"generated_at"`
Provider Provider `json:"provider,omitempty"`
Author string `json:"author"`
Scope Scope `json:"scope"`
Since time.Time `json:"since"`
Until time.Time `json:"until"`
Count int `json:"count"`
Commits []Commit `json:"commits"`
Truncated bool `json:"truncated,omitempty"` // true if MaxCommits clipped results
// Skipped lists repositories an org-scope scan could not list and skipped so
// that one bad repo (e.g. an empty repo, or one the token cannot read) does
// not abort the whole scan. Empty/omitted when nothing was skipped.
Skipped []SkippedRepo `json:"skipped,omitempty"`
}
Result is the outcome of a Query: the matching commits plus the parameters that produced them, suitable for direct serialization.
type Scope ¶
type Scope string
Scope selects how commits are discovered for an author.
const ( // ScopeSearch uses GitHub's global commit search index (author across all // indexed public repositories). Broad but limited to indexed/public repos. ScopeSearch Scope = "search" // ScopeRepos lists commits within an explicit set of "owner/repo" targets. ScopeRepos Scope = "repos" // ScopeOrg enumerates an organization's repositories and lists commits in each. ScopeOrg Scope = "org" )
type SkippedRepo ¶ added in v0.0.5
SkippedRepo records a repository that an org-scope scan could not list and chose to skip rather than abort the whole scan. Reason is a short, human-readable cause (e.g. "empty repository", "not found"). Surfacing skips keeps a partial result auditable instead of silently dropping the repo.