Config contains unparsed configuration data and metadata about where it was found.
type Config struct { Content []byte // Source contains the repository and ref in "owner/name@ref" format. The // ref component ("@ref") is optional and may not be present. Source string Path string IsRemote bool }
func (c Config) IsUndefined() bool
IsUndefined returns true if the Config's content is empty and there is no metadata giving a source.
Loader loads configuration for repositories.
type Loader struct {
// contains filtered or unexported fields
}
func NewLoader(paths []string, opts ...Option) *Loader
NewLoader creates a Loader that loads configuration from paths.
func (ld *Loader) LoadConfig(ctx context.Context, client *github.Client, owner, repo, ref string) (Config, error)
LoadConfig loads configuration for the repository owner/repo. It first tries the Loader's paths in order, following remote references if they exist. If no configuration exists at any path in the repository, it tries to load default configuration defined by owner for all repositories. If no default configuration exists, it returns an undefined Config and a nil error.
If error is non-nil, the Source and Path fields of the returned Config tell which file LoadConfig was processing when it encountered the error.
type Option func(*Loader)
func WithOwnerDefault(name string, paths []string) Option
WithOwnerDefault sets the owner repository and paths to check when a repository does not define its own configuration. By default, the repository name is ".github" and the paths are those passed to the loader with the ".github/" prefix removed. Set an empty repository name to disable owner defaults.
func WithRemoteRefParser(parser RemoteRefParser) Option
WithRemoteRefParser sets the parser for encoded RemoteRefs. The default parser uses YAML. Set a nil parser to disable remote references.
RemoteRef identifies a configuration file in a different repository.
type RemoteRef struct { // The repository in "owner/name" format. Required. Remote string `yaml:"remote" json:"remote"` // The path to the config file in the repository. If empty, use the first // path configured in the loader. Path string `yaml:"path" json:"path"` // The reference (branch, tag, or SHA) to read in the repository. If empty, // use the default branch of the repository. Ref string `yaml:"ref" json:"ref"` }
func YAMLRemoteRefParser(path string, b []byte) (*RemoteRef, error)
YAMLRemoteRefParser parses b as a YAML-encoded RemoteRef. It assumes all parsing errors mean the content is not a RemoteRef.
func (r RemoteRef) SplitRemote() (owner, repo string, err error)
RemoteRefParser attempts to parse a RemoteRef from bytes. The parser should return nil with a nil error if b does not encode a RemoteRef and nil with a non-nil error if b encodes an invalid RemoteRef.
type RemoteRefParser func(path string, b []byte) (*RemoteRef, error)