github

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: GPL-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package github provides types for GitHub repository data.

Example (MockExecutor)

Example test showing the mockExecutor in action

mock := &mockExecutor{
	lookPathRes: "/usr/bin/gh",
	executeFunc: func(name string, args ...string) ([]byte, error) {
		return []byte(`[{"name":"test","nameWithOwner":"owner/test","pushedAt":"2024-01-01T00:00:00Z"}]`), nil
	},
}
client := NewClient("", mock)
repos, _ := client.ListRepos(context.Background())
fmt.Printf("Found %d repos\n", len(repos))
Output:
Found 1 repos

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrGhNotInstalled   = errors.New("gh CLI not found. Install from https://cli.github.com")
	ErrNotAuthenticated = errors.New("Not logged in. Run `gh auth login` first.")
	ErrMissingScope     = errors.New("Missing delete_repo scope. Run `gh auth refresh -s delete_repo`.")
)

Sentinel errors for common failure cases.

Functions

This section is empty.

Types

type Client

type Client struct {
	Owner string
	// contains filtered or unexported fields
}

Client handles interactions with GitHub via the gh CLI.

func NewClient

func NewClient(owner string, executor CommandExecutor) *Client

NewClient creates a new GitHub client for the specified owner. If owner is empty, operations target the authenticated user. If executor is nil, the default exec-based executor is used.

func (*Client) CheckAuth

func (c *Client) CheckAuth(ctx context.Context) error

CheckAuth verifies that the gh CLI is installed and the user is authenticated.

func (*Client) DeleteRepos

func (c *Client) DeleteRepos(ctx context.Context, repos []Repo, onProgress DeleteProgressFn) []DeleteResult

DeleteRepos deletes the specified repositories sequentially with a 1-second throttle between requests to comply with GitHub's rate limits. It includes automatic retry logic with exponential backoff for rate-limited requests (HTTP 429).

func (*Client) ListRepos

func (c *Client) ListRepos(ctx context.Context) ([]Repo, error)

ListRepos fetches repositories for the configured owner using the gh CLI. If Owner is empty, it lists repositories for the authenticated user. Results are sorted by PushedAt in ascending order (oldest first).

type CommandExecutor

type CommandExecutor interface {
	Execute(ctx context.Context, name string, args ...string) ([]byte, error)
	LookPath(name string) (string, error)
}

CommandExecutor abstracts command execution for testability.

type DeleteProgressFn

type DeleteProgressFn func(repo Repo, result DeleteResult, current int, total int)

DeleteProgressFn is a callback for tracking deletion progress.

type DeleteResult

type DeleteResult struct {
	Repo     Repo
	Success  bool
	Error    error
	Duration time.Duration
}

DeleteResult represents the outcome of a repository deletion attempt.

type Repo

type Repo struct {
	Name           string    `json:"name"`
	NameWithOwner  string    `json:"nameWithOwner"`
	Description    string    `json:"description"`
	PushedAt       time.Time `json:"pushedAt"`
	Visibility     string    `json:"visibility"`
	IsArchived     bool      `json:"isArchived"`
	IsFork         bool      `json:"isFork"`
	StargazerCount int       `json:"stargazerCount"`
	ForkCount      int       `json:"forkCount"`
}

Repo represents a GitHub repository with fields matching gh CLI output.

type RepoList

type RepoList []Repo

RepoList is a collection of repositories.

Jump to

Keyboard shortcuts

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