appconfig

package
v0.47.2 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: Apache-2.0 Imports: 10 Imported by: 7

Documentation

Overview

Package appconfig loads repository configuration for GitHub apps. It supports loading directly from a file in a repository, loading from remote references, and loading an organization-level default. The config itself can be in any format.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

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
}

Config contains unparsed configuration data and metadata about where it was found.

func (Config) IsUndefined

func (c Config) IsUndefined() bool

IsUndefined returns true if the Config's content is empty and there is no metadata giving a source.

type Loader

type Loader struct {
	// contains filtered or unexported fields
}

Loader loads configuration for repositories.

func NewLoader

func NewLoader(paths []string, opts ...Option) *Loader

NewLoader creates a Loader that loads configuration from paths.

func (*Loader) LoadConfig

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

type Option func(*Loader)

func WithOwnerDefault

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 WithPrivateRemotes added in v0.47.2

func WithPrivateRemotes(clientCreator githubapp.ClientCreator, installations githubapp.InstallationsService) Option

WithPrivateRemotes enables loading remote configuration from private repositories owned by a different user or organization. It uses the app's installation on the remote repository to fetch the referenced file. If the app is not installed on that repository, or an installation client cannot be created, the loader logs the failure and falls back to the original client so public remote repositories remain supported.

WARNING: Enabling this option can expose configuration file content and repository existence to users who otherwise may not be able to access them. Enable it only when the app is installed on GitHub organizations where all users are trusted, or when the caller otherwise prevents unintentional information disclosure.

This loader does not cache installation lookups or clients. Callers that load configuration frequently should pass caching implementations, such as githubapp.NewCachingInstallationsService and githubapp.NewCachingClientCreator.

func WithRemoteRefParser

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.

type RemoteRef

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"`
}

RemoteRef identifies a configuration file in a different repository.

func YAMLRemoteRefParser

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 (RemoteRef) SplitRemote

func (r RemoteRef) SplitRemote() (owner, repo string, err error)

type RemoteRefParser

type RemoteRefParser func(path string, b []byte) (*RemoteRef, 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.

Jump to

Keyboard shortcuts

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