github

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrGitHubAuth = errors.New("github authentication failed")

ErrGitHubAuth indicates a 401/403 authentication or authorization failure.

View Source
var ErrGitHubRateLimited = errors.New("github rate limited")

ErrGitHubRateLimited indicates a 429 rate limit response.

Functions

func ParseGitHubRemote

func ParseGitHubRemote(remoteURL string) (owner, repo string, ok bool)

ParseGitHubRemote extracts owner and repo from a git remote URL. Supports:

Returns ("", "", false) for non-GitHub URLs.

Types

type Client

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

Client is a minimal GitHub REST API client for fetching PR data.

func NewClient

func NewClient(token string) *Client

NewClient creates a GitHub API client with the given personal access token.

func (*Client) ListIssueComments

func (c *Client) ListIssueComments(ctx context.Context, owner, repo string, number int) ([]Comment, error)

ListIssueComments fetches all general discussion comments on a pull request.

func (*Client) ListIssues

func (c *Client) ListIssues(ctx context.Context, owner, repo string, opts ListIssuesOptions) ([]Issue, *RateLimit, error)

ListIssues fetches issues for a repository with pagination. Filters out pull requests (GitHub API returns PRs as issues). When opts.Since is set, pagination stops when issues older than Since are encountered (requires Sort="updated", Direction="desc" to work correctly).

func (*Client) ListPRComments

func (c *Client) ListPRComments(ctx context.Context, owner, repo string, number int) ([]Comment, error)

ListPRComments fetches all review comments (file-level) on a pull request.

func (*Client) ListPullRequests

func (c *Client) ListPullRequests(ctx context.Context, owner, repo string, opts ListPRsOptions) ([]PullRequest, *RateLimit, error)

ListPullRequests fetches pull requests for a repository with pagination. When opts.Since is set, pagination stops when PRs older than Since are encountered (requires Sort="updated", Direction="desc" to work correctly).

type Comment

type Comment struct {
	ID        int64      `json:"id"`
	User      GitHubUser `json:"user"`
	Body      string     `json:"body"`
	Path      string     `json:"path,omitempty"`
	Line      *int       `json:"line,omitempty"`
	CreatedAt time.Time  `json:"created_at"`
}

Comment represents either a PR review comment or an issue comment. Path and Line are only populated for review comments (file-level).

type Fetcher

type Fetcher struct {
	// contains filtered or unexported fields
}

Fetcher wraps a Client to satisfy ledger.GitHubFetcher.

func NewFetcher

func NewFetcher(c *Client) *Fetcher

NewFetcher creates a GitHubFetcher from a Client.

func (*Fetcher) ListIssueComments

func (f *Fetcher) ListIssueComments(ctx context.Context, owner, repo string, number int) ([]ledger.FetchedComment, error)

func (*Fetcher) ListIssues

func (f *Fetcher) ListIssues(ctx context.Context, owner, repo string, opts ledger.ListIssuesOptions) ([]ledger.FetchedIssue, *ledger.FetchRateLimit, error)

func (*Fetcher) ListPRComments

func (f *Fetcher) ListPRComments(ctx context.Context, owner, repo string, number int) ([]ledger.FetchedComment, error)

func (*Fetcher) ListPullRequests

func (f *Fetcher) ListPullRequests(ctx context.Context, owner, repo string, opts ledger.ListPRsOptions) ([]ledger.FetchedPR, *ledger.FetchRateLimit, error)

type GitHubUser

type GitHubUser struct {
	Login string `json:"login"`
}

GitHubUser is a minimal GitHub user reference.

type Issue

type Issue struct {
	Number    int        `json:"number"`
	Title     string     `json:"title"`
	Body      string     `json:"body"`
	State     string     `json:"state"` // open, closed
	User      GitHubUser `json:"user"`
	Labels    []Label    `json:"labels"`
	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt time.Time  `json:"updated_at"`
	ClosedAt  *time.Time `json:"closed_at"`
	HTMLURL   string     `json:"html_url"`
	// PullRequest is non-nil when this "issue" is actually a PR.
	// Used to filter out PRs from issue listings.
	PullRequest *struct{} `json:"pull_request,omitempty"`
}

Issue represents a GitHub issue from the REST API. Note: GitHub's API returns PRs as issues too — filter by checking whether the "pull_request" field is present (excluded in our struct).

type Label

type Label struct {
	Name string `json:"name"`
}

Label is a GitHub issue/PR label.

type ListIssuesOptions

type ListIssuesOptions struct {
	State     string    // "all", "open", "closed" (default: "all")
	Sort      string    // "updated" (default)
	Direction string    // "desc" (default)
	Since     time.Time // stop pagination when issues are older than this
	PerPage   int       // max 100 (default: 100)
	Page      int       // starting page (default: 1)
}

ListIssuesOptions controls pagination and filtering for ListIssues.

type ListPRsOptions

type ListPRsOptions struct {
	State     string    // "all", "open", "closed" (default: "all")
	Sort      string    // "updated" (default)
	Direction string    // "desc" (default)
	Since     time.Time // stop pagination when PRs are older than this
	PerPage   int       // max 100 (default: 100)
	Page      int       // starting page (default: 1)
}

ListPRsOptions controls pagination and filtering for ListPullRequests.

type PullRequest

type PullRequest struct {
	Number    int        `json:"number"`
	Title     string     `json:"title"`
	Body      string     `json:"body"`
	State     string     `json:"state"` // open, closed
	User      GitHubUser `json:"user"`
	Labels    []Label    `json:"labels"`
	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt time.Time  `json:"updated_at"`
	MergedAt  *time.Time `json:"merged_at"`
	MergeSHA  string     `json:"merge_commit_sha"`
	HTMLURL   string     `json:"html_url"`
	Draft     bool       `json:"draft"`
}

PullRequest represents a GitHub pull request from the REST API.

type RateLimit

type RateLimit struct {
	Remaining int
	Limit     int
	Reset     time.Time
}

RateLimit captures GitHub API rate limit state from response headers.

Jump to

Keyboard shortcuts

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