Documentation
¶
Overview ¶
Package config provides configuration utilities for GitHub API clients.
Index ¶
Constants ¶
const ( DefaultBranch = "main" DefaultBaseURL = "https://api.github.com/" DefaultUploadURL = "https://uploads.github.com/" )
Default values for GitHub configuration.
const ( EnvOwner = "GITHUB_OWNER" EnvRepo = "GITHUB_REPO" EnvBranch = "GITHUB_BRANCH" EnvToken = "GITHUB_TOKEN" //nolint:gosec // This is an env var name, not a credential EnvBaseURL = "GITHUB_API_URL" EnvUploadURL = "GITHUB_UPLOAD_URL" )
Standard environment variable names.
Variables ¶
var ( ErrOwnerRequired = errors.New("owner is required") ErrRepoRequired = errors.New("repo is required") ErrTokenRequired = errors.New("token is required") )
Config errors.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Owner is the repository owner (user or organization). Required.
Owner string
// Repo is the repository name. Required.
Repo string
// Branch is the branch to operate on. Default: "main".
Branch string
// Token is the GitHub personal access token. Required.
// Needs "repo" scope for private repos, or "public_repo" for public repos.
Token string
// BaseURL is the GitHub API base URL. Default: "https://api.github.com/".
// Set this for GitHub Enterprise (e.g., "https://github.example.com/api/v3/").
BaseURL string
// UploadURL is the GitHub upload URL. Default: "https://uploads.github.com/".
// Set this for GitHub Enterprise.
UploadURL string
}
Config holds configuration for GitHub API operations.
func FromEnv ¶
func FromEnv() Config
FromEnv creates a Config from environment variables using default names.
func FromEnvWithConfig ¶
FromEnvWithConfig creates a Config from environment variables with custom names.
func FromEnvWithFallback ¶
FromEnvWithFallback creates a Config from environment variables, checking primary env var names first, then fallback names.
func FromMap ¶
FromMap creates a Config from a string map. Supported keys:
- owner: repository owner (required)
- repo: repository name (required)
- branch: branch name (default: "main")
- token: GitHub personal access token (required)
- base_url: GitHub API base URL (for GitHub Enterprise)
- upload_url: GitHub upload URL (for GitHub Enterprise)
func (*Config) ApplyDefaults ¶
func (c *Config) ApplyDefaults()
ApplyDefaults fills in default values for empty fields.
func (*Config) IsEnterprise ¶
IsEnterprise returns true if the config is for GitHub Enterprise.
func (*Config) MustNewClient ¶
MustNewClient creates a GitHub client from the configuration. It panics if the config is invalid or client creation fails.
type EnvConfig ¶
type EnvConfig struct {
Owner string
Repo string
Branch string
Token string
BaseURL string
UploadURL string
}
EnvConfig holds environment variable names for configuration. Use this to customize which environment variables are used.
func DefaultEnvConfig ¶
func DefaultEnvConfig() EnvConfig
DefaultEnvConfig returns the default environment variable names.