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

github

package
v0.7.218 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTokenNotFound = errors.New("api token not found")

ErrTokenNotFound indicates no GitHub token was found in env or config.

Functions

func IsResolutionError

func IsResolutionError(err error) bool

IsResolutionError checks if an error is a repo resolution error.

Types

type Author

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

Author holds a GitHub user login.

type Client

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

Client is a GitHub GraphQL API client.

func New

func New(cfg Config) (*Client, error)

func (*Client) CheckRateLimit

func (c *Client) CheckRateLimit(ctx context.Context) error

CheckRateLimit queries the current rate limit status.

func (*Client) CreatePullRequest added in v0.7.212

func (c *Client) CreatePullRequest(ctx context.Context, owner, repo string, in NewPullRequest) (*PullRequest, error)

CreatePullRequest opens a pull request on owner/repo. A refusal carries the reason GitHub gave, such as a pull request for the branch already existing, and one for a token that cannot open pull requests says what it lacks.

func (*Client) DefaultBranch added in v0.7.212

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

DefaultBranch is the branch owner/repo's pull requests target by default.

func (*Client) FetchOrgRepos

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

FetchOrgRepos returns repository names for the given org. If filterRepos is non-empty, those names are returned directly without querying.

func (*Client) FetchPRForBranch added in v0.7.186

func (c *Client) FetchPRForBranch(ctx context.Context, owner, repo, branch string) (*PRStatusInfo, error)

FetchPRForBranch returns the open PR for the given branch, or nil if none exists. Returns nil, nil when the repo has no open PR for that branch.

func (*Client) FetchReviewActivity

func (c *Client) FetchReviewActivity(ctx context.Context, org, repo string, since time.Time) (*FetchReviewActivityResult, error)

FetchReviewActivity fetches review activity for a single repo. Returns an error containing "Could not resolve" for repos that don't exist.

func (*Client) OpenPullRequestForBranch added in v0.7.212

func (c *Client) OpenPullRequestForBranch(ctx context.Context, owner, repo, branch string) (*PullRequest, error)

OpenPullRequestForBranch is the open pull request whose head is branch on owner/repo, or nil when there is none. It answers the question a refused CreatePullRequest leaves: whether the branch already has one, which a branch pushed a second time does.

func (*Client) ValidateOrg

func (c *Client) ValidateOrg(ctx context.Context, org string) error

ValidateOrg checks that the org is accessible.

type CommentNode

type CommentNode struct {
	Author    *Author `json:"author"`
	Body      string  `json:"body"`
	DiffHunk  string  `json:"diffHunk"`
	CreatedAt string  `json:"createdAt"`
}

CommentNode is a single review thread comment.

type Config added in v0.7.29

type Config struct {
	Token     string
	BaseURL   string
	LogStatus func(string)
}

type FetchReviewActivityResult

type FetchReviewActivityResult struct {
	Activity map[string]*UserActivity
	Details  []ReviewCommentDetail
}

FetchReviewActivityResult holds the results of fetching review activity.

type NewPullRequest added in v0.7.212

type NewPullRequest struct {
	// Base is the branch the change is for and Head the branch that has it.
	// Both must exist on the repository.
	Base, Head string
	Title      string
	Body       string
	Draft      bool
}

NewPullRequest is a pull request to open.

type OrgReposData

type OrgReposData struct {
	Organization struct {
		Repositories struct {
			PageInfo PageInfo   `json:"pageInfo"`
			Nodes    []RepoNode `json:"nodes"`
		} `json:"repositories"`
	} `json:"organization"`
	RateLimit RateLimit `json:"rateLimit"`
}

OrgReposData is the unwrapped data from the org repos query.

type PRCheckStatus added in v0.7.186

type PRCheckStatus struct {
	Name       string `json:"name"`
	Status     string `json:"status"`     // QUEUED, IN_PROGRESS, COMPLETED
	Conclusion string `json:"conclusion"` // SUCCESS, FAILURE, NEUTRAL, CANCELLED, etc.
}

PRCheckStatus describes one CI check on a PR commit.

type PRCommentInfo added in v0.7.186

type PRCommentInfo struct {
	Author    string    `json:"author"`
	Body      string    `json:"body"`
	CreatedAt time.Time `json:"created_at"`
	Resolved  bool      `json:"resolved,omitempty"`
}

PRCommentInfo is one review thread comment on a PR.

type PRNode

type PRNode struct {
	Number    int     `json:"number"`
	Title     string  `json:"title"`
	URL       string  `json:"url"`
	State     string  `json:"state"`
	UpdatedAt string  `json:"updatedAt"`
	Author    *Author `json:"author"`
	Reviews   struct {
		Nodes []ReviewNode `json:"nodes"`
	} `json:"reviews"`
	ReviewThreads struct {
		Nodes []struct {
			Comments struct {
				Nodes []CommentNode `json:"nodes"`
			} `json:"comments"`
		} `json:"nodes"`
	} `json:"reviewThreads"`
}

PRNode is a single pull request from the review activity query.

type PRStatusInfo added in v0.7.186

type PRStatusInfo struct {
	Number            int             `json:"number"`
	Title             string          `json:"title"`
	URL               string          `json:"url"`
	UpdatedAt         time.Time       `json:"updated_at,omitempty"`
	OverallCheckState string          `json:"overall_check_state,omitempty"` // SUCCESS, FAILURE, PENDING, etc.
	Checks            []PRCheckStatus `json:"checks,omitempty"`
	Comments          []PRCommentInfo `json:"comments,omitempty"`
	ChangesRequested  bool            `json:"changes_requested,omitempty"`
}

PRStatusInfo is the daemon's view of one open PR, as returned by FetchPRForBranch.

type PageInfo

type PageInfo struct {
	HasNextPage bool    `json:"hasNextPage"`
	EndCursor   *string `json:"endCursor"`
}

PageInfo holds GraphQL pagination info.

type PullRequest added in v0.7.212

type PullRequest struct {
	Number int
	URL    string
}

PullRequest is a pull request that was opened.

type RateLimit

type RateLimit struct {
	Remaining int    `json:"remaining"`
	ResetAt   string `json:"resetAt"`
}

RateLimit holds GitHub GraphQL rate limit info.

type RepoNode

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

RepoNode is a single repository from the org repos query.

type RepoPRsData

type RepoPRsData struct {
	Repository *struct {
		PullRequests struct {
			PageInfo PageInfo `json:"pageInfo"`
			Nodes    []PRNode `json:"nodes"`
		} `json:"pullRequests"`
	} `json:"repository"`
	RateLimit RateLimit `json:"rateLimit"`
}

RepoPRsData is the unwrapped data from the review activity query.

type RetryError added in v0.7.29

type RetryError struct {
	Retries     int
	ServerError bool // true when GitHub returned HTML error pages (500/503)
	Err         error
}

RetryError indicates that a GitHub API request failed after exhausting retries.

func (*RetryError) Error added in v0.7.29

func (e *RetryError) Error() string

func (*RetryError) Unwrap added in v0.7.29

func (e *RetryError) Unwrap() error

type ReviewCommentDetail

type ReviewCommentDetail struct {
	Reviewer  string                `json:"reviewer"`
	Body      string                `json:"body"`
	DiffHunk  string                `json:"diffHunk"`
	CreatedAt string                `json:"createdAt"`
	PR        ReviewCommentDetailPR `json:"pr"`
}

ReviewCommentDetail is an enriched comment with PR metadata.

type ReviewCommentDetailPR

type ReviewCommentDetailPR struct {
	Repo   string `json:"repo"`
	Number int    `json:"number"`
	Title  string `json:"title"`
	Author string `json:"author"`
	URL    string `json:"url"`
	State  string `json:"state"`
}

ReviewCommentDetailPR holds PR metadata for a comment.

type ReviewNode

type ReviewNode struct {
	Author    *Author `json:"author"`
	State     string  `json:"state"`
	CreatedAt string  `json:"createdAt"`
}

ReviewNode is a single review on a PR.

type StatusError added in v0.7.29

type StatusError = hc.StatusError

StatusError is an alias for the shared httpcl.StatusError type.

type UserActivity

type UserActivity struct {
	Login            string
	TotalActivity    int
	ReviewsGiven     int
	Approvals        int
	ChangesRequested int
	ReviewComments   int
	ReposActiveIn    map[string]bool
}

UserActivity tracks review activity counts for a single user.

Jump to

Keyboard shortcuts

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