config

package
v1.1.13 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package config provides severity configuration loading from YAML files. It supports global, local repo, and remote config sources with defined precedence: narrower scope (more specific) overrides broader scope.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultConfigYAML

func DefaultConfigYAML() []byte

DefaultConfigYAML returns the default configuration YAML content matching the runtime default severity policy.

func GlobalPath

func GlobalPath(userConfigDir string) (string, error)

GlobalPath returns the global config file path for the given user config directory. Returns an error if userConfigDir is empty.

func RepoNarrowPath

func RepoNarrowPath(cwd string) (string, error)

RepoNarrowPath returns the path to .github/gh-pr-todo.yml at the root of the repository containing cwd. Returns an error if cwd is not inside a Git repository.

func RepoRootPath

func RepoRootPath(cwd string) (string, error)

RepoRootPath returns the path to .gh-pr-todo.yml at the root of the repository containing cwd. Returns an error if cwd is not inside a Git repository.

func WriteDefault

func WriteDefault(path string, force bool) error

WriteDefault writes the default config YAML to path. If force is false, it refuses to overwrite an existing file. Parent directories are created as needed.

Types

type Config

type Config struct {
	Severities map[string]todotype.Severity
	Ignored    map[string]bool
	Found      bool // true if at least one config file was found and parsed
}

Config holds parsed severity overrides and ignored types from configuration files.

func LoadGlobal

func LoadGlobal(userConfigDir string) (Config, error)

LoadGlobal loads the user-level global config file if it exists. Returns an empty/nil-map Config if the file does not exist.

func LoadLocal

func LoadLocal(cwd, userConfigDir string) (Config, error)

LoadLocal loads config from global, repo root, and repo .github paths with whole-file replacement: each existing file replaces the entire previous config. Precedence (later wins): global < repo root .gh-pr-todo.yml < repo .github/gh-pr-todo.yml. If any repo config exists, global content does not survive. Missing files are silently ignored; parse errors are returned.

func LoadRemote

func LoadRemote(fetcher RemoteConfigFetcher, repo, pr string) (Config, error)

LoadRemote loads config files from remote repository references. Precedence: PR head > PR base > default branch. Within each scope, .github/gh-pr-todo.yml replaces .gh-pr-todo.yml entirely.

func Parse

func Parse(data []byte, source string) (Config, error)

Parse parses YAML config data and validates severity values and ignore list. source is used in error messages to identify the file origin.

type File

type File struct {
	Severity map[string][]string `yaml:"severity"`
	Ignore   []string            `yaml:"ignore"`
}

File represents the YAML configuration file schema.

type RemoteConfigFetcher

type RemoteConfigFetcher interface {
	// FetchRemoteConfigRefs returns the relevant refs for remote config loading.
	FetchRemoteConfigRefs(repo, pr string) (RemoteConfigRefs, error)
	// FetchFileAtRef fetches a file from the given repo at a specific ref.
	// Returns (nil, false, nil) if the file is not found (404).
	FetchFileAtRef(repo, path, ref string) ([]byte, bool, error)
}

RemoteConfigFetcher is the interface for fetching remote config files from a GitHub repository.

type RemoteConfigRefs

type RemoteConfigRefs struct {
	DefaultBranchRef string // e.g. "main"
	DefaultRepo      string // e.g. "owner/repo"
	BaseBranchRef    string // e.g. "main" (empty if no PR)
	BaseRepo         string // e.g. "owner/repo" (empty if no PR)
	HeadRefOid       string // e.g. "abc123def" (empty if no PR)
	HeadRepo         string // e.g. "forkuser/repo" (empty if no PR)
}

RemoteConfigRefs holds repository references used for remote config loading.

Jump to

Keyboard shortcuts

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