Documentation
¶
Overview ¶
Package github queries GitHub through the user's gh authentication.
Index ¶
- func IsClientError(err error) bool
- func ParsePRRef(s string) (string, int, error)
- func Transient(err error) bool
- type Client
- func (c *Client) AddLabel(ctx context.Context, repo string, number int, label string) error
- func (c *Client) Approve(ctx context.Context, repo string, number int, commitID, body string) error
- func (c *Client) GetPR(ctx context.Context, repo string, number int) (PRDetail, error)
- func (c *Client) HasReview(ctx context.Context, repo string, number int, marker string) (bool, error)
- func (c *Client) PostReview(ctx context.Context, repo string, number int, p ReviewPost) (PostResult, error)
- func (c *Client) SearchPRs(ctx context.Context, query string, limit int) ([]PR, int, error)
- func (c *Client) WithREST(r REST) *Client
- type GraphQL
- type PR
- type PRDetail
- type PartialError
- type PostResult
- type REST
- type ReviewComment
- type ReviewPost
- type SearchBlockedError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsClientError ¶
IsClientError reports a definite 4xx rejection: the request did not take effect. Anything else (5xx, timeout, network) may have reached GitHub.
func ParsePRRef ¶
ParsePRRef accepts a GitHub PR URL or owner/name#number.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewDefault ¶
NewDefault builds a Client from the user's gh auth configuration.
func (*Client) AddLabel ¶ added in v0.3.0
AddLabel adds label to a PR, keeping its other labels. GitHub creates the label in the repository if it doesn't exist.
func (*Client) Approve ¶
Approve submits an APPROVE review on commitID. Unlike PostReview it never falls back: if GitHub refuses (for example, your own pull request), the approval simply failed.
func (*Client) HasReview ¶
func (c *Client) HasReview(ctx context.Context, repo string, number int, marker string) (bool, error)
HasReview reports whether any of the PR's reviews contains marker. Ghost uses it to avoid re-posting a review or approval whose request timed out, so it reads every page (reviews are listed oldest first).
func (*Client) PostReview ¶
func (c *Client) PostReview(ctx context.Context, repo string, number int, p ReviewPost) (PostResult, error)
PostReview submits a review. GitHub answers 422 both when you request changes on (or approve) your own PR and when an inline comment is outside the diff. For the own-PR case it retries as a plain COMMENT, keeping the inline comments; for other 422s it retries with the comments folded into the body, then, if needed, as a COMMENT.
func (*Client) SearchPRs ¶
SearchPRs runs a GitHub search query and returns up to limit matching pull requests (1–100; out-of-range values are clamped, 0 means 50) and the total number of matches. Non-PR results (issues) are dropped. If GitHub withholds some results, the visible PRs are returned along with a *PartialError; if a search matches nothing because of access (e.g. SAML SSO), an empty list is returned with a *SearchBlockedError.
type GraphQL ¶
type GraphQL interface {
DoWithContext(ctx context.Context, query string, variables map[string]interface{}, response interface{}) error
}
GraphQL is the subset of go-gh's GraphQLClient that Client uses.
type PR ¶
type PR struct {
Repo string
Number int
State string // OPEN, CLOSED or MERGED
Title string
URL string
Author string
Body string
BaseRef string
HeadRef string
HeadSHA string
IsDraft bool
ReviewDecision string
CIState string
Additions int
Deletions int
ChangedFiles int
UpdatedAt time.Time
Labels []string
}
type PartialError ¶
PartialError reports PRs a search matched but GitHub would not return, for example PRs in organizations that enforce SAML for the user's token.
func (*PartialError) Error ¶
func (e *PartialError) Error() string
type PostResult ¶
type PostResult struct {
Folded bool // inline comments moved into the body after GitHub rejected them
FoldReason string // GitHub's reason for rejecting them
Downgraded bool // event changed to COMMENT
}
PostResult says which fallbacks PostReview needed.
type REST ¶
type REST interface {
DoWithContext(ctx context.Context, method, path string, body io.Reader, response interface{}) error
}
REST is the subset of go-gh's RESTClient that Client uses.
type ReviewComment ¶
type ReviewPost ¶
type ReviewPost struct {
CommitID string `json:"commit_id"`
Event string `json:"event"` // COMMENT, REQUEST_CHANGES or APPROVE
Body string `json:"body"`
Comments []ReviewComment `json:"comments,omitempty"`
// Unattached are comments on lines outside the PR's diff, which GitHub
// won't accept inline; PostReview lists them in the body instead.
Unattached []ReviewComment `json:"-"`
}
type SearchBlockedError ¶ added in v0.4.1
type SearchBlockedError struct {
Reason string
SAML bool // the token isn't authorized for an organization's SSO
}
SearchBlockedError explains why a search returned nothing: GitHub's GraphQL search silently drops what the token can't see (an organization enforcing SAML single sign-on, a repository that doesn't exist or isn't visible), while its REST search reports it.
func (*SearchBlockedError) Error ¶ added in v0.4.1
func (e *SearchBlockedError) Error() string