config

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

SPDX-License-Identifier: MIT Package config defines the tool's settings and the flexible time-window parsing used to bound a query. Loading and source precedence (config file, environment, flags) is handled by viper in the CLI layer; this package stays dependency-light so the GitHub client and renderers can rely on it.

SPDX-License-Identifier: MIT

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Defaults

func Defaults() map[string]any

Defaults are the built-in configuration values, keyed by their canonical config key. The CLI seeds viper with these so they participate uniformly in precedence resolution.

func ParseTime

func ParseTime(s string) (time.Time, error)

ParseTime parses a since/until bound. It accepts RFC3339 timestamps and the date form "2006-01-02" (interpreted in UTC).

func ParseWindow

func ParseWindow(s string) (time.Duration, error)

ParseWindow turns a look-back string into a duration. It accepts Go durations ("48h", "30m") plus the day/week suffixes "d" and "w" (e.g. "7d", "2w").

Types

type Config

type Config struct {
	// Token is the GitHub personal access token sting authenticates with. It is
	// deliberately sting's own key (config-file "token" or env STING_TOKEN), kept
	// separate from the ambient GITHUB_TOKEN so a dedicated read-only PAT can be
	// the default without colliding with other tools' credentials.
	Token string `mapstructure:"token"`
	// BaseURL points at a GitHub Enterprise API root
	// ("https://ghe.example.com/api/v3/"). Empty means public github.com.
	BaseURL string `mapstructure:"base_url"`
	// DefaultScope is used when a query omits a scope.
	DefaultScope model.Scope `mapstructure:"default_scope"`
	// DefaultWindow is the look-back window when a query omits since/until.
	DefaultWindow string `mapstructure:"default_window"`
	// DefaultRepos seeds ScopeRepos queries that omit repos.
	DefaultRepos []string `mapstructure:"default_repos"`
	// DefaultOrg seeds ScopeOrg queries that omit org.
	DefaultOrg string `mapstructure:"default_org"`
	// DefaultFormat is the CLI render format ("markdown" or "json").
	DefaultFormat string `mapstructure:"default_format"`
	// PerPage is the API page size (1-100).
	PerPage int `mapstructure:"per_page"`
	// MaxCommits caps results per query (0 = unlimited).
	MaxCommits int `mapstructure:"max_commits"`
	// IncludeStats fetches per-commit line stats by default.
	IncludeStats bool `mapstructure:"include_stats"`
}

Config holds all tunable settings. The mapstructure keys are the canonical configuration keys: they are the YAML/JSON config-file keys, the viper keys bound to flags, and (uppercased, STING_-prefixed) the environment variables.

func Default

func Default() Config

Default returns the built-in configuration as a Config value.

func (Config) Resolve

func (cfg Config) Resolve(req Request, now time.Time) (model.Query, error)

Resolve turns a Request into a validated model.Query, applying defaults from cfg. The reference time now is injected for testability.

func (Config) Validate

func (cfg Config) Validate() error

Validate checks that the resolved configuration is internally consistent.

type Request

type Request struct {
	Author string
	Since  string // RFC3339 or YYYY-MM-DD; empty uses Window
	Until  string // RFC3339 or YYYY-MM-DD; empty means now
	Window string // look-back (e.g. "7d"); used only when Since is empty
	Scope  string // search|repos|org; empty uses default
	Repos  []string
	Org    string

	// IncludeStats overrides the default when non-nil.
	IncludeStats *bool
}

Request is the raw, mostly-string input from a CLI invocation or an MCP tool call. Empty fields fall back to configuration defaults during Resolve.

Jump to

Keyboard shortcuts

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