github

package
v0.1.19 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package github is a minimal GitHub REST client scoped to what whodar ingests: repositories, contributors, pull requests, CODEOWNERS, and users. The token is held only in memory, never serialized, and never logged.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("github: not found")

ErrNotFound indicates the requested resource does not exist.

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

ErrRateLimited indicates the API rate limit was exhausted.

View Source
var ErrStatus = errors.New("github: unexpected status")

ErrStatus indicates an unexpected HTTP status.

Functions

This section is empty.

Types

type Account

type Account struct {
	// Login is the user's handle.
	Login string `json:"login"`
	// Name is the user's display name.
	Name string `json:"name"`
	// Email is the user's public email, often empty.
	Email string `json:"email"`
}

Account is a user's public profile subset.

type Client

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

Client calls the GitHub REST API.

func New

func New(token string, opts ...Option) *Client

New returns a Client for token. It panics on an empty token; callers validate token presence before constructing the client.

func (*Client) Account

func (c *Client) Account(ctx context.Context, login string) (Account, error)

Account returns a user's public profile.

func (*Client) Contributors

func (c *Client) Contributors(ctx context.Context, owner, repo string) ([]Contributor, error)

Contributors returns up to 100 contributors, most commits first.

func (*Client) FileContents

func (c *Client) FileContents(ctx context.Context, owner, repo, path string) ([]byte, error)

FileContents returns the decoded contents of a file, or ErrNotFound if it is absent.

func (*Client) Issues

func (c *Client) Issues(ctx context.Context, owner, repo string) ([]Issue, error)

Issues returns up to 100 recently updated issues of any state. The result includes pull requests, which the caller can filter with IsPullRequest.

func (*Client) OrgRepos

func (c *Client) OrgRepos(ctx context.Context, org string) ([]Repo, error)

OrgRepos returns up to 100 recently updated repositories in an org.

func (*Client) PullRequests

func (c *Client) PullRequests(ctx context.Context, owner, repo string) ([]PullRequest, error)

PullRequests returns up to 100 recently updated pull requests of any state.

func (*Client) Repo

func (c *Client) Repo(ctx context.Context, owner, repo string) (Repo, error)

Repo returns a repository's metadata.

type Contributor

type Contributor struct {
	// Login is the contributor's handle.
	Login string `json:"login"`
	// Contributions is the contributor's commit count.
	Contributions int `json:"contributions"`
}

Contributor is a repository contributor.

type Doer

type Doer interface {
	// Do performs the request and returns the response.
	Do(req *http.Request) (*http.Response, error)
}

Doer performs an HTTP request. *http.Client satisfies it; tests inject a stub.

type Issue

type Issue struct {
	// Title is the issue title.
	Title string `json:"title"`
	// User is the author.
	User account `json:"user"`
	// Assignees are users assigned to the issue.
	Assignees []account `json:"assignees"`
	// Labels are the applied labels.
	Labels []label `json:"labels"`
	// PullRequest is present when the issue is actually a pull request.
	PullRequest json.RawMessage `json:"pull_request"`
	// UpdatedAt is when the issue last changed.
	UpdatedAt time.Time `json:"updated_at"`
}

Issue is the subset of an issue whodar reads. The GitHub issues endpoint also returns pull requests; IsPullRequest distinguishes them.

func (Issue) AssigneeLogins

func (i Issue) AssigneeLogins() []string

AssigneeLogins returns the assignees' logins.

func (Issue) Author

func (i Issue) Author() string

Author returns the issue author's login.

func (Issue) IsPullRequest

func (i Issue) IsPullRequest() bool

IsPullRequest reports whether this issue is really a pull request.

func (Issue) LabelNames

func (i Issue) LabelNames() []string

LabelNames returns the label names.

type Option

type Option func(*Client)

Option configures a Client.

func WithBaseURL

func WithBaseURL(u string) Option

WithBaseURL overrides the API base URL.

func WithHTTPClient

func WithHTTPClient(d Doer) Option

WithHTTPClient sets the HTTP doer.

type PullRequest

type PullRequest struct {
	// Title is the pull request title.
	Title string `json:"title"`
	// User is the author.
	User account `json:"user"`
	// Labels are the applied labels.
	Labels []label `json:"labels"`
	// RequestedReviewers are users asked to review.
	RequestedReviewers []account `json:"requested_reviewers"`
	// Assignees are users assigned to the pull request.
	Assignees []account `json:"assignees"`
	// UpdatedAt is when the pull request last changed.
	UpdatedAt time.Time `json:"updated_at"`
}

PullRequest is the subset of a pull request whodar reads.

func (PullRequest) AssigneeLogins

func (p PullRequest) AssigneeLogins() []string

AssigneeLogins returns the assignees' logins.

func (PullRequest) Author

func (p PullRequest) Author() string

Author returns the pull request author's login.

func (PullRequest) LabelNames

func (p PullRequest) LabelNames() []string

LabelNames returns the label names.

func (PullRequest) Reviewers

func (p PullRequest) Reviewers() []string

Reviewers returns the requested reviewers' logins.

type Repo

type Repo struct {
	// Name is the repository name.
	Name string `json:"name"`
	// FullName is the owner/name path.
	FullName string `json:"full_name"`
	// Description is the repository description.
	Description string `json:"description"`
	// Topics are the repository's topic tags.
	Topics []string `json:"topics"`
}

Repo is a repository's indexable metadata.

Jump to

Keyboard shortcuts

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