Help us shape the future of Go! Take the 2026 Go Developer Survey

github

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package github queries GitHub through the user's gh authentication.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsClientError

func IsClientError(err error) bool

IsClientError reports a definite 4xx rejection: the request did not take effect. Anything else (5xx, timeout, network) may have reached GitHub.

func ParsePRRef

func ParsePRRef(s string) (string, int, error)

ParsePRRef accepts a GitHub PR URL or owner/name#number.

Types

type Client

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

func New

func New(gql GraphQL) *Client

func NewDefault

func NewDefault() (*Client, error)

NewDefault builds a Client from the user's gh auth configuration.

func (*Client) AddLabel added in v0.3.0

func (c *Client) AddLabel(ctx context.Context, repo string, number int, label string) error

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

func (c *Client) Approve(ctx context.Context, repo string, number int, commitID, body string) error

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) GetPR

func (c *Client) GetPR(ctx context.Context, repo string, number int) (PRDetail, error)

GetPR fetches one pull request and its changed file paths.

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

func (c *Client) SearchPRs(ctx context.Context, query string, limit int) ([]PR, int, error)

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.

func (*Client) WithREST

func (c *Client) WithREST(r REST) *Client

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
}

func (PR) HasLabel added in v0.3.0

func (p PR) HasLabel(name string) bool

HasLabel reports whether the PR has the named label, ignoring case as GitHub does.

func (PR) Status

func (p PR) Status() status.Status

type PRDetail

type PRDetail struct {
	PR
	Files []string
}

PRDetail is a PR plus the paths it changes (first 100).

type PartialError

type PartialError struct {
	Hidden int
	Reason string
}

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
	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 ReviewComment struct {
	Path string `json:"path"`
	Line int    `json:"line"`
	Side string `json:"side"`
	Body string `json:"body"`
}

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"`
}

Jump to

Keyboard shortcuts

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