Documentation
¶
Overview ¶
Package gh is a small GitHub REST client built on the user's existing GitHub CLI authentication.
Index ¶
- func IsGone(err error) bool
- func IsNotFound(err error) bool
- func IsOffline(err error) bool
- func IsValidation(err error) bool
- func NormalizeRepo(repo string) (string, error)
- func RepoName(repo string) string
- func UserMessage(err error) string
- func ValidRepo(repo string) bool
- type Client
- func (c *Client) AddAssignees(ctx context.Context, repo string, number int, logins []string) error
- func (c *Client) AddLabels(ctx context.Context, repo string, number int, labels []string) error
- func (c *Client) CreateComment(ctx context.Context, repo string, number int, body string) (Comment, error)
- func (c *Client) CreateIssue(ctx context.Context, repo string, payload NewIssue) (Issue, error)
- func (c *Client) CreateLabel(ctx context.Context, repo string, label Label) error
- func (c *Client) GetIssue(ctx context.Context, repo string, number int) (Issue, error)
- func (c *Client) Host() string
- func (c *Client) IssueURL(repo string, number int) string
- func (c *Client) LatestRelease(ctx context.Context, repo string) (Release, error)
- func (c *Client) ListComments(ctx context.Context, repo string, number int) ([]Comment, error)
- func (c *Client) ListIssues(ctx context.Context, repo string, since time.Time, etag string) (IssuePage, error)
- func (c *Client) ListLabels(ctx context.Context, repo string) ([]Label, error)
- func (c *Client) ListUserRepos(ctx context.Context, limit int) ([]RepoSummary, error)
- func (c *Client) RemoveAssignees(ctx context.Context, repo string, number int, logins []string) error
- func (c *Client) RemoveLabel(ctx context.Context, repo string, number int, label string) error
- func (c *Client) UpdateIssue(ctx context.Context, repo string, number int, patch IssuePatch) (Issue, error)
- func (c *Client) Viewer(ctx context.Context) (string, error)
- type Comment
- type Error
- type ErrorKind
- type Issue
- type IssuePage
- type IssuePatch
- type Label
- type NewIssue
- type Release
- type RepoSummary
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsNotFound ¶
func IsOffline ¶
IsOffline reports whether err means GitHub could not be reached, so the request is worth retrying later unchanged.
func IsValidation ¶
func NormalizeRepo ¶
NormalizeRepo trims whitespace and a leading github.com URL from repo and validates the result.
func UserMessage ¶
UserMessage turns err into a short sentence suitable for a status bar.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to the GitHub REST API.
func New ¶
New returns a client authenticated with the token `gh` uses (or GITHUB_TOKEN / GH_TOKEN). It fails with an ErrAuth error when no token is available.
func NewWithHTTP ¶
NewWithHTTP returns a client that sends requests with hc to base, which must end with a slash. Tests use it to point the client at a fake server.
func (*Client) AddAssignees ¶
AddAssignees assigns users to an issue.
func (*Client) AddLabels ¶
AddLabels adds labels to an issue. GitHub creates labels that don't exist yet.
func (*Client) CreateComment ¶
func (c *Client) CreateComment(ctx context.Context, repo string, number int, body string) (Comment, error)
CreateComment adds a comment to an issue.
func (*Client) CreateIssue ¶
CreateIssue opens a new issue.
func (*Client) CreateLabel ¶
CreateLabel defines a label in repo. A label that already exists is left unchanged and is not an error.
func (*Client) LatestRelease ¶ added in v0.3.0
LatestRelease returns the release GitHub marks as latest in repo.
func (*Client) ListComments ¶
ListComments returns all comments on an issue, oldest first.
func (*Client) ListIssues ¶
func (c *Client) ListIssues(ctx context.Context, repo string, since time.Time, etag string) (IssuePage, error)
ListIssues returns every issue (not pull request) in repo updated at or after since. When etag matches GitHub's current listing, NotModified is set and no issues are returned; such requests don't count against the rate limit.
func (*Client) ListLabels ¶
ListLabels returns every label defined in repo.
func (*Client) ListUserRepos ¶
ListUserRepos returns repositories the user owns, collaborates on, or can access through an organization, most recently pushed first. Archived repositories and repositories with issues disabled are skipped.
func (*Client) RemoveAssignees ¶
func (c *Client) RemoveAssignees(ctx context.Context, repo string, number int, logins []string) error
RemoveAssignees unassigns users from an issue.
func (*Client) RemoveLabel ¶
RemoveLabel removes a label from an issue. Removing a label the issue doesn't have is not an error.
func (*Client) UpdateIssue ¶
func (c *Client) UpdateIssue(ctx context.Context, repo string, number int, patch IssuePatch) (Issue, error)
UpdateIssue edits an issue's title, body, or state.
type Comment ¶
type Comment struct {
ID int64 `json:"id"`
Body string `json:"body"`
User User `json:"user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
HTMLURL string `json:"html_url"`
}
Comment is an issue comment.
type ErrorKind ¶
type ErrorKind int
ErrorKind groups GitHub failures by what the user can do about them.
type Issue ¶
type Issue struct {
Number int `json:"number"`
Title string `json:"title"`
Body string `json:"body"`
State string `json:"state"`
StateReason string `json:"state_reason"`
Labels []Label `json:"labels"`
Assignees []User `json:"assignees"`
User User `json:"user"`
Comments int `json:"comments"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
ClosedAt *time.Time `json:"closed_at"`
HTMLURL string `json:"html_url"`
PullRequest *struct{} `json:"pull_request,omitempty"`
}
Issue is a GitHub issue as returned by the REST API.
type IssuePatch ¶
type IssuePatch struct {
Title *string `json:"title,omitempty"`
Body *string `json:"body,omitempty"`
State *string `json:"state,omitempty"`
StateReason *string `json:"state_reason,omitempty"`
}
IssuePatch is the payload for UpdateIssue; nil fields are left unchanged.
type Label ¶
type Label struct {
Name string `json:"name"`
Color string `json:"color,omitempty"`
Description string `json:"description,omitempty"`
}
Label is a GitHub issue label.
type NewIssue ¶
type NewIssue struct {
Title string `json:"title"`
Body string `json:"body,omitempty"`
Labels []string `json:"labels,omitempty"`
Assignees []string `json:"assignees,omitempty"`
}
NewIssue is the payload for CreateIssue.
type Release ¶ added in v0.3.0
type Release struct {
TagName string `json:"tag_name"`
Name string `json:"name"`
Body string `json:"body"`
HTMLURL string `json:"html_url"`
}
Release is a published GitHub release.
type RepoSummary ¶
type RepoSummary struct {
FullName string `json:"full_name"`
Description string `json:"description"`
Private bool `json:"private"`
Archived bool `json:"archived"`
HasIssues bool `json:"has_issues"`
OpenIssues int `json:"open_issues_count"`
PushedAt time.Time `json:"pushed_at"`
}
RepoSummary describes a repository the user can access.