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 ¶
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 ¶
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).
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 ¶
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.