config

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package config provides configuration utilities for GitHub API clients.

Index

Constants

View Source
const (
	DefaultBranch    = "main"
	DefaultBaseURL   = "https://api.github.com/"
	DefaultUploadURL = "https://uploads.github.com/"
)

Default values for GitHub configuration.

View Source
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

View Source
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 Default

func Default() Config

Default returns a Config with default values set.

func FromEnv

func FromEnv() Config

FromEnv creates a Config from environment variables using default names.

func FromEnvWithConfig

func FromEnvWithConfig(envCfg EnvConfig) Config

FromEnvWithConfig creates a Config from environment variables with custom names.

func FromEnvWithFallback

func FromEnvWithFallback(primary, fallback EnvConfig) Config

FromEnvWithFallback creates a Config from environment variables, checking primary env var names first, then fallback names.

func FromMap

func FromMap(m map[string]string) Config

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

func (c *Config) IsEnterprise() bool

IsEnterprise returns true if the config is for GitHub Enterprise.

func (*Config) MustNewClient

func (c *Config) MustNewClient(ctx context.Context) *github.Client

MustNewClient creates a GitHub client from the configuration. It panics if the config is invalid or client creation fails.

func (*Config) NewClient

func (c *Config) NewClient(ctx context.Context) (*github.Client, error)

NewClient creates a GitHub client from the configuration. The config must be validated before calling this function.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks if the configuration has all required fields.

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.

Jump to

Keyboard shortcuts

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