config

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultClientID = "d57cb8c4-630c-4168-8324-ec79935e18d4"

DefaultClientID is the default OAuth2 client ID included in most Gitea instances

View Source
const (
	// LockTimeout is the default timeout for acquiring the config file lock.
	LockTimeout = 5 * time.Second
)
View Source
const TokenRefreshThreshold = 5 * time.Minute

TokenRefreshThreshold is how far before expiry we should refresh OAuth tokens. This is used by config.Login.Client() for automatic token refresh.

Variables

This section is empty.

Functions

func AddLogin

func AddLogin(login *Login) error

AddLogin save a login to config

func DeleteLogin

func DeleteLogin(name string) error

DeleteLogin delete a login by name from config

func GetConfigPath

func GetConfigPath() string

GetConfigPath return path to tea config file

func SaveLoginTokens added in v0.12.0

func SaveLoginTokens(login *Login) error

SaveLoginTokens updates the token fields for an existing login. This is used after browser-based re-authentication to save new tokens.

func SetConfigForTesting added in v0.12.0

func SetConfigForTesting(cfg LocalConfig)

SetConfigForTesting replaces the in-memory config and marks it as loaded. This allows tests to inject config without relying on file-based loading.

func SetDefaultLogin

func SetDefaultLogin(name string) error

SetDefaultLogin set the default login by name (case insensitive)

Types

type FlagDefaults added in v0.9.0

type FlagDefaults struct {
	// Prefer a specific git remote to use for selecting a repository on gitea,
	// instead of relying on the remote associated with main/master/trunk branch.
	// The --remote flag still has precedence over this value.
	Remote string `yaml:"remote"`
}

FlagDefaults defines all flags that can be overridden with a default value via the config file

type LocalConfig

type LocalConfig struct {
	Logins []Login     `yaml:"logins"`
	Prefs  Preferences `yaml:"preferences"`
}

LocalConfig represents local configurations

type Login

type Login struct {
	Name    string `yaml:"name"`
	URL     string `yaml:"url"`
	Token   string `yaml:"token"`
	Default bool   `yaml:"default"`
	SSHHost string `yaml:"ssh_host"`
	// optional path to the private key
	SSHKey            string `yaml:"ssh_key"`
	Insecure          bool   `yaml:"insecure"`
	SSHCertPrincipal  string `yaml:"ssh_certificate_principal"`
	SSHAgent          bool   `yaml:"ssh_agent"`
	SSHKeyFingerprint string `yaml:"ssh_key_agent_pub"`
	SSHPassphrase     string `yaml:"-"`
	VersionCheck      bool   `yaml:"version_check"`
	// User is username from gitea
	User string `yaml:"user"`
	// Created is auto created unix timestamp
	Created int64 `yaml:"created"`
	// RefreshToken is used to renew the access token when it expires
	RefreshToken string `yaml:"refresh_token"`
	// TokenExpiry is when the token expires (unix timestamp)
	TokenExpiry int64 `yaml:"token_expiry"`
}

Login represents a login to a gitea server, you even could add multiple logins for one gitea server

func GetDefaultLogin

func GetDefaultLogin() (*Login, error)

GetDefaultLogin return the default login

func GetLoginByHost added in v0.9.0

func GetLoginByHost(host string) *Login

GetLoginByHost finds a login by it's server URL

func GetLoginByName

func GetLoginByName(name string) *Login

GetLoginByName get login by name (case insensitive)

func GetLoginByToken

func GetLoginByToken(token string) *Login

GetLoginByToken get login by token

func GetLogins

func GetLogins() ([]Login, error)

GetLogins return all login available by config

func GetLoginsByHost added in v0.12.0

func GetLoginsByHost(host string) []*Login

GetLoginsByHost returns all logins matching a host

func (*Login) Client

func (l *Login) Client(options ...gitea.ClientOption) *gitea.Client

Client returns a client to operate Gitea API. You may provide additional modifiers for the client like gitea.SetBasicAuth() for customization

func (*Login) GetSSHHost

func (l *Login) GetSSHHost() string

GetSSHHost returns SSH host name

func (*Login) RefreshOAuthToken added in v0.12.0

func (l *Login) RefreshOAuthToken() error

RefreshOAuthToken refreshes the OAuth access token using the refresh token. It updates the login with new token information and saves it to config. Uses double-checked locking to avoid unnecessary refresh calls when multiple processes race to refresh the same token.

func (*Login) RefreshOAuthTokenIfNeeded added in v0.12.0

func (l *Login) RefreshOAuthTokenIfNeeded() error

RefreshOAuthTokenIfNeeded refreshes the OAuth token if it's expired or near expiry. Returns nil without doing anything if no refresh is needed.

type Preferences added in v0.9.0

type Preferences struct {
	// Prefer using an external text editor over inline multiline prompts
	Editor       bool         `yaml:"editor"`
	FlagDefaults FlagDefaults `yaml:"flag_defaults"`
}

Preferences that are stored in and read from the config file

func GetPreferences added in v0.9.0

func GetPreferences() Preferences

GetPreferences returns preferences based on the config file

Jump to

Keyboard shortcuts

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