github

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReviewKindNew      = "new"
	ReviewKindRereview = "rereview"
)

Review request kinds, set on ReviewRequest.Kind by GetReviewRequests.

Variables

This section is empty.

Functions

func GetCurrentUser

func GetCurrentUser(ctx context.Context) (string, error)

GetCurrentUser returns the authenticated GitHub user's login.

func RepoFullName

func RepoFullName(cfg *config.Config, short string) string

RepoFullName maps short repo name to full GitHub path using config.

func RepoShortName

func RepoShortName(cfg *config.Config, full string) string

RepoShortName maps full GitHub path to short repo name using config.

Types

type ApprovedPR

type ApprovedPR struct {
	Number         int        `json:"number"`
	Title          string     `json:"title"`
	Author         AuthorInfo `json:"author"`
	Repository     RepoInfo   `json:"repository"`
	CreatedAt      string     `json:"createdAt"`
	URL            string     `json:"url"`
	ReviewDecision string     `json:"reviewDecision"`
}

ApprovedPR represents a user's approved but unmerged PR.

func GetApprovedUnmerged

func GetApprovedUnmerged(ctx context.Context, repoFilter string, ignoreDrafts bool) ([]ApprovedPR, error)

GetApprovedUnmerged fetches the user's own PRs that are approved but not yet merged. When ignoreDrafts is true, draft PRs are excluded at the GitHub search layer.

type AuthorInfo

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

AuthorInfo holds author login info.

type Client

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

Client wraps go-github with auth from `gh auth token`.

func NewClient

func NewClient(ctx context.Context) (*Client, error)

NewClient creates a GitHub client using the token from `gh auth token`.

func (*Client) GetPRAuthor

func (c *Client) GetPRAuthor(ctx context.Context, fullRepo string, prNumber int) (string, error)

GetPRAuthor returns the login of the PR author.

func (*Client) GetPRDetails

func (c *Client) GetPRDetails(ctx context.Context, fullRepo string, prNumber int) (*PRDetails, error)

GetPRDetails fetches details for a specific PR.

func (*Client) GetPRFiles

func (c *Client) GetPRFiles(ctx context.Context, fullRepo string, prNumber int) ([]string, error)

GetPRFiles returns the list of changed file paths for a PR.

func (*Client) GetPRState

func (c *Client) GetPRState(ctx context.Context, fullRepo string, prNumber int) (string, error)

GetPRState returns the state of a PR: OPEN, CLOSED, or MERGED.

func (*Client) GetPRStateByBranch

func (c *Client) GetPRStateByBranch(ctx context.Context, fullRepo, branch string) (string, int, error)

GetPRStateByBranch looks up PRs by head branch name and returns the state ("MERGED", "CLOSED", "OPEN") and PR number of the first match. Returns ("", 0, nil) if no PR found for that branch.

func (*Client) GetPRTitle

func (c *Client) GetPRTitle(ctx context.Context, fullRepo string, prNumber int) (string, error)

GetPRTitle returns the title of a PR.

func (*Client) GetReviewStatus

func (c *Client) GetReviewStatus(ctx context.Context, fullRepo string, prNumber int) (string, error)

GetReviewStatus returns the user's latest review state on a PR.

func (*Client) GitHub

func (c *Client) GitHub() *gh.Client

GitHub returns the underlying go-github client.

func (*Client) IsRequestedReviewer added in v0.5.0

func (c *Client) IsRequestedReviewer(ctx context.Context, fullRepo string, prNumber int, login string) (bool, error)

IsRequestedReviewer checks if the given user login is a requested reviewer on a PR.

type MyPR added in v0.11.0

type MyPR struct {
	Number         int      `json:"number"`
	Title          string   `json:"title"`
	Repository     RepoInfo `json:"repository"`
	CreatedAt      string   `json:"createdAt"`
	URL            string   `json:"url"`
	IsDraft        bool     `json:"isDraft"`
	ReviewDecision string   `json:"reviewDecision"`
	Mergeable      string   `json:"mergeable"`
	// BaseRefName and HeadRefName let callers detect stacked PRs: PR A
	// depends on PR B when A's BaseRefName equals B's HeadRefName.
	BaseRefName    string `json:"baseRefName"`
	HeadRefName    string `json:"headRefName"`
	ReviewRequests struct {
		TotalCount int `json:"totalCount"`
	} `json:"reviewRequests"`
	Commits struct {
		Nodes []struct {
			Commit struct {
				StatusCheckRollup struct {
					State string `json:"state"`
				} `json:"statusCheckRollup"`
			} `json:"commit"`
		} `json:"nodes"`
	} `json:"commits"`
}

MyPR represents one of the current user's open pull requests, enriched with review and CI status for `zen board`'s status classification.

func GetMyOpenPRs added in v0.11.0

func GetMyOpenPRs(ctx context.Context, repoFilter string) ([]MyPR, error)

GetMyOpenPRs fetches the user's own open PRs, enriched with draft state, review decision, mergeability, pending review requests, and the latest commit's CI check rollup — enough to classify each into a status bucket (ready to merge, failing CI, changes requested, in review, in flight, draft).

func (MyPR) CheckState added in v0.11.0

func (p MyPR) CheckState() string

CheckState returns the latest commit's CI status-check rollup state (e.g. "SUCCESS", "FAILURE", "PENDING"), or "" if no checks are reported.

func (MyPR) HasReviewRequests added in v0.11.0

func (p MyPR) HasReviewRequests() bool

HasReviewRequests reports whether any reviewers are currently requested.

type PRDetails

type PRDetails struct {
	Number      int    `json:"number"`
	Title       string `json:"title"`
	Author      string `json:"author"`
	State       string `json:"state"`
	HeadRefName string `json:"head_ref_name"`
	BaseRefName string `json:"base_ref_name"`
	Body        string `json:"body"`
	CreatedAt   string `json:"created_at"`
	URL         string `json:"url"`
	IsFork      bool   `json:"is_fork"`
}

PRDetails holds basic PR information.

type RepoInfo

type RepoInfo struct {
	Name          string `json:"name"`
	NameWithOwner string `json:"nameWithOwner"`
}

RepoInfo holds repository identification.

type ReviewRequest

type ReviewRequest struct {
	Number     int        `json:"number"`
	Title      string     `json:"title"`
	Author     AuthorInfo `json:"author"`
	Repository RepoInfo   `json:"repository"`
	CreatedAt  string     `json:"createdAt"`
	URL        string     `json:"url"`
	// Kind is "new" or "rereview", set by GetReviewRequests to record which
	// of its two queries matched. Not part of the GitHub API response.
	Kind string `json:"-"`
}

ReviewRequest represents a PR review request.

func GetReviewRequests

func GetReviewRequests(ctx context.Context, repoFilter string, ignoreDrafts bool) ([]ReviewRequest, error)

GetReviewRequests fetches PRs where the user is a requested reviewer, including re-reviews. Uses GraphQL via `gh api graphql`. When ignoreDrafts is true, draft PRs are filtered out at the GitHub search layer.

func ListOpenPRs

func ListOpenPRs(ctx context.Context, fullRepo string, limit int, ignoreDrafts bool) ([]ReviewRequest, error)

ListOpenPRs lists open PRs for a repository using `gh pr list`. When ignoreDrafts is true, drafts are excluded via `--draft=false`.

Jump to

Keyboard shortcuts

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