ghtoken

package
v0.0.0-...-68956d0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package ghtoken resolves a GitHub API token from the environment or, as a fallback, from the locally installed GitHub CLI (`gh`).

Resolution order:

  1. GITHUB_TOKEN env var (legacy, CI, scripts).
  2. GH_TOKEN env var (gh CLI's own override).
  3. `gh auth token` if `gh` is on PATH AND the user is authenticated.

This means a developer who has `gh auth login`'d once never has to set GITHUB_TOKEN by hand — releases, asset uploads, and remote repo creation all "just work".

All resolution is best-effort: when no source yields a token, an empty string + a typed reason are returned so callers can render a user-friendly message instead of a stack trace.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoToken = errors.New("no GitHub token available (set GITHUB_TOKEN or run `gh auth login`)")

ErrNoToken is returned by Resolve when neither env vars nor the gh CLI yield a usable token. Wrapped so callers can branch on errors.Is without losing the human-readable detail.

Functions

This section is empty.

Types

type Source

type Source string

Source identifies which mechanism produced a token. Used for colorful "✓ Using token from <source>" log lines.

const (
	SourceEnvGitHubToken Source = "GITHUB_TOKEN env var"
	SourceEnvGHToken     Source = "GH_TOKEN env var"
	SourceGhCLI          Source = "GitHub CLI (gh auth token)"
	SourceNone           Source = ""
)

func Resolve

func Resolve() (string, Source, error)

Resolve returns (token, source, err). On success err is nil and source identifies where the token came from. On failure token is "" and err wraps ErrNoToken with a one-line reason.

Jump to

Keyboard shortcuts

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