github

package
v0.27.1 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package github provides the interactive GitHub setup initialiser.

It registers a setup [Initialiser] (and the `init github` command via NewCmdInitGitHub) that configures GitHub authentication — a token recorded via an env-var reference, the OS keychain, or a literal in config — and optionally discovers, generates, and uploads an SSH key. Runtime token resolution lives in pkg/vcs; this package handles first-run setup, not API client construction.

Index

Constants

This section is empty.

Variables

View Source
var GitHubHost = "github.com"

Functions

func ConfigureSSHKey

func ConfigureSSHKey(props *props.Props, cfg config.Containable, opts ...ConfigureSSHKeyOption) (string, string, error)

ConfigureSSHKey runs the interactive SSH key configuration flow.

func NewCmdInitGitHub

func NewCmdInitGitHub(p *props.Props) *cobra.Command

NewCmdInitGitHub creates the `init github` subcommand.

func RunGitHubInit

func RunGitHubInit(p *props.Props, cfg config.Containable) error

RunGitHubInit forcibly runs both login and SSH configuration regardless of current state. This is used by the explicit `init github` command.

func RunInitCmd

func RunInitCmd(p *props.Props, dir string) error

RunInitCmd executes the GitHub configuration and writes the results to the config file.

Types

type AuthFormOption

type AuthFormOption func(*authFormConfig)

AuthFormOption configures form creators for the GitHub auth wizard. Used by tests to inject deterministic form-answering creators without driving a real TTY.

func WithAuthForm

func WithAuthForm(
	creator func(*GitHubAuthConfig) []*huh.Form,
	displayOnceCreator func(envVarName, token string) *huh.Form,
) AuthFormOption

WithAuthForm injects custom form creators into [configureAuth] for testability. The creator returns forms in order:

[0] storage-mode selector
[1] env-var name input
[2] "fetch token now?" confirm
[3] display-once token view (takes envVarName, token)

Returning fewer forms is allowed — the runner skips stages whose slot is nil or absent. The display-once creator has a different signature because it needs the captured token passed in.

type ConfigureSSHKeyOption

type ConfigureSSHKeyOption func(*configureSSHKeyConfig)

ConfigureSSHKeyOption is a functional option for ConfigureSSHKey.

func WithGenerateKeyOptions

func WithGenerateKeyOptions(opts ...GenerateKeyOption) ConfigureSSHKeyOption

WithGenerateKeyOptions passes options through to the key generation step.

func WithSSHKeyPathForm

func WithSSHKeyPathForm(creator func(*string) *huh.Form) ConfigureSSHKeyOption

WithSSHKeyPathForm overrides the SSH key path input form (for testing).

func WithSSHKeySelectForm

func WithSSHKeySelectForm(creator func(*string, []huh.Option[string]) *huh.Form) ConfigureSSHKeyOption

WithSSHKeySelectForm overrides the SSH key selection form (for testing).

type GenerateKeyOption

type GenerateKeyOption func(*generateKeyConfig)

GenerateKeyOption is a functional option for SSH key generation.

func WithGitHubClientFactory

func WithGitHubClientFactory(factory func(config.Containable) (githubvcs.GitHubClient, error)) GenerateKeyOption

WithGitHubClientFactory overrides the GitHub client constructor used when uploading SSH keys. Tests pass a fake; production callers omit to get the default.

func WithPassphraseForm

func WithPassphraseForm(creator func(*string) *huh.Form) GenerateKeyOption

WithPassphraseForm overrides the passphrase input form (for testing).

func WithUploadConfirmForm

func WithUploadConfirmForm(creator func(*bool) *huh.Form) GenerateKeyOption

WithUploadConfirmForm overrides the upload confirmation form (for testing).

type GitHubAuthConfig

type GitHubAuthConfig struct {
	// StorageMode is set by the storage-mode selector. Defaults to
	// [credentials.ModeEnvVar] when the form presents the choice.
	StorageMode credentials.Mode

	// EnvVarName is the env var NAME recorded under github.auth.env
	// in env-var mode. Ignored in keychain/literal modes.
	EnvVarName string

	// FetchToken is true when the user wants the wizard to run OAuth
	// (or the manual fallback) on their behalf. Only relevant in
	// env-var mode — keychain/literal always need a token.
	FetchToken bool

	// Token is the captured token from OAuth / manual entry. Cleared
	// after it has been written (or displayed for env-var mode) so
	// it does not linger in the AuthConfig longer than necessary.
	Token string
}

GitHubAuthConfig captures the wizard's output from each stage. All fields are populated incrementally so test-injected form creators can override any subset and the runner still produces a coherent config.

type GitHubInitialiser

type GitHubInitialiser struct {
	SkipLogin bool
	SkipKey   bool
	// contains filtered or unexported fields
}

GitHubInitialiser handles both GitHub authentication and SSH key configuration.

func NewGitHubInitialiser

func NewGitHubInitialiser(p *props.Props, skipLogin, skipKey bool, opts ...InitialiserOption) *GitHubInitialiser

NewGitHubInitialiser creates a new GitHubInitialiser and mounts its assets.

func (*GitHubInitialiser) Configure

func (g *GitHubInitialiser) Configure(props *props.Props, cfg config.Containable) error

Configure runs the interactive login and/or SSH configuration.

func (*GitHubInitialiser) IsConfigured

func (g *GitHubInitialiser) IsConfigured(cfg config.Containable) bool

IsConfigured returns true if unskipped components are already present in the config.

func (*GitHubInitialiser) Name

func (g *GitHubInitialiser) Name() string

type InitialiserOption

type InitialiserOption func(*GitHubInitialiser)

InitialiserOption configures a GitHubInitialiser.

func WithGHLogin

func WithGHLogin(fn func(string) (string, error)) InitialiserOption

WithGHLogin overrides the GitHub CLI login function used for authentication. Tests pass a fake; production callers omit to get the default.

func WithGitHubAuthForms

func WithGitHubAuthForms(opts ...AuthFormOption) InitialiserOption

WithGitHubAuthForms propagates [AuthFormOption]s down into configureAuth. Tests use this to inject deterministic form creators via WithAuthForm.

Jump to

Keyboard shortcuts

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