github

package
v1.21.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreatePR

func CreatePR(head, base, title, body string, draft bool, labels []string) (string, error)

CreatePR creates a new pull request and returns the PR URL.

func GetDefaultMergeMethod added in v1.13.0

func GetDefaultMergeMethod() (string, error)

GetDefaultMergeMethod returns the preferred merge method for the repo. Picks the first enabled method in order: squash → merge → rebase.

func IsAvailable

func IsAvailable() bool

IsAvailable returns true if `gh` CLI is on PATH.

func MergePR added in v1.13.0

func MergePR(prNumber int, method string) error

MergePR merges a pull request using the given method (squash, merge, rebase).

func RepoSlug

func RepoSlug() (string, error)

RepoSlug returns the "owner/repo" string.

func ResetAvailability added in v1.6.0

func ResetAvailability()

ResetAvailability resets the cached gh availability check. Intended for testing only.

Types

type CISummary

type CISummary struct {
	Pass    int
	Fail    int
	Pending int
	Total   int
}

CISummary aggregates CI check counts.

type PR

type PR struct {
	Number         int              `json:"number"`
	HeadRefName    string           `json:"headRefName"`
	State          string           `json:"state"`
	ReviewRequests []ReviewRequest  `json:"reviewRequests"`
	LatestReviews  []Review         `json:"latestReviews"`
	StatusChecks   []StatusCheckRun `json:"statusCheckRollup"`
}

PR represents a GitHub pull request.

func FindPRForBranch

func FindPRForBranch(prs []PR, branch string) *PR

FindPRForBranch returns the first PR matching the branch name and state.

func GetPRForBranch

func GetPRForBranch(branch string) (*PR, error)

GetPRForBranch fetches the PR for a specific branch. Returns (nil, nil) if gh is not available or no PR exists.

func ListPRs

func ListPRs(state string) ([]PR, error)

ListPRs fetches PRs in a given state with full review/CI data.

func (*PR) GetCISummary

func (pr *PR) GetCISummary() CISummary

GetCISummary computes CI check state counts.

func (*PR) GetReviewSummary

func (pr *PR) GetReviewSummary() ReviewSummary

GetReviewSummary computes review state counts.

type PRDetail added in v1.19.0

type PRDetail struct {
	Number int    `json:"number"`
	Title  string `json:"title"`
	Body   string `json:"body"`
	Author struct {
		Login string `json:"login"`
	} `json:"author"`
	StatusChecks []StatusCheckRun `json:"statusCheckRollup"`
}

PRDetail is the rich PR info used by the dashboard detail panel. Fetched on demand — kept separate from the lighter `PR` returned by ListPRs.

func GetPRDetail added in v1.19.0

func GetPRDetail(number int) (*PRDetail, error)

GetPRDetail fetches title/body/author and named CI checks for one PR in a single gh call. Returns (nil, nil) when gh isn't installed.

type PRDetails

type PRDetails struct {
	Number      int       `json:"number"`
	Title       string    `json:"title"`
	Body        string    `json:"body"`
	BaseRefName string    `json:"baseRefName"`
	IsDraft     bool      `json:"isDraft"`
	Labels      []PRLabel `json:"labels"`
}

PRDetails holds full PR metadata for recreation after branch rename.

func GetPRDetails

func GetPRDetails(branch string) (*PRDetails, error)

GetPRDetails fetches full details for the open PR on a branch.

type PRInfo added in v1.8.0

type PRInfo struct {
	Number      int    `json:"number"`
	Title       string `json:"title"`
	HeadRefName string `json:"headRefName"`
	State       string `json:"state"`
}

PRInfo holds lightweight PR metadata for checkout.

func GetPRByNumber added in v1.8.0

func GetPRByNumber(number int) (*PRInfo, error)

GetPRByNumber fetches PR metadata by number.

type PRLabel

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

PRLabel represents a label on a PR.

type Review

type Review struct {
	Author struct {
		Login string `json:"login"`
	} `json:"author"`
	State string `json:"state"` // APPROVED, CHANGES_REQUESTED, COMMENTED
}

Review represents a completed review.

type ReviewItem added in v1.3.0

type ReviewItem struct {
	Login string
	State string // "approved", "changes_requested", "pending"
}

ReviewItem represents a unified review entry (completed or pending).

type ReviewRequest

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

ReviewRequest represents a pending review request.

type ReviewSummary

type ReviewSummary struct {
	Approved int
	Changes  int
	Pending  int
}

ReviewSummary aggregates review counts.

type StatusCheckRun

type StatusCheckRun struct {
	Name       string `json:"name"`
	State      string `json:"state"`      // SUCCESS, FAILURE, PENDING, etc.
	Conclusion string `json:"conclusion"` // SUCCESS, FAILURE, SKIPPED, TIMED_OUT, CANCELLED, ""
}

StatusCheckRun represents a CI check.

func (StatusCheckRun) Result added in v1.9.2

func (c StatusCheckRun) Result() string

Result classifies a CI check as "pass", "fail", or "pending".

type WatchStatus

type WatchStatus struct {
	Number           int              `json:"number"`
	Title            string           `json:"title"`
	State            string           `json:"state"` // OPEN, CLOSED, MERGED
	HeadRefName      string           `json:"headRefName"`
	MergeStateStatus string           `json:"mergeStateStatus"` // CLEAN, BLOCKED, BEHIND, DRAFT, DIRTY, UNKNOWN
	Mergeable        string           `json:"mergeable"`        // MERGEABLE, CONFLICTING, UNKNOWN
	ReviewDecision   string           `json:"reviewDecision"`   // APPROVED, CHANGES_REQUESTED, REVIEW_REQUIRED, ""
	ReviewRequests   []ReviewRequest  `json:"reviewRequests"`
	LatestReviews    []Review         `json:"latestReviews"`
	StatusChecks     []StatusCheckRun `json:"statusCheckRollup"`
}

WatchStatus holds detailed PR state from `gh pr view`, including fields not available from `gh pr list` (mergeStateStatus, mergeable).

func GetWatchStatus

func GetWatchStatus(branch string) (*WatchStatus, error)

GetWatchStatus fetches detailed PR status for a branch using `gh pr view`.

func (*WatchStatus) ChecksByStatus added in v1.3.0

func (ws *WatchStatus) ChecksByStatus() (pass, fail, pending []StatusCheckRun)

ChecksByStatus returns checks sorted into pass, fail, and pending buckets. Checks with empty names (GitHub summary checks) are excluded.

func (*WatchStatus) FailedCheckNames

func (ws *WatchStatus) FailedCheckNames() []string

FailedCheckNames returns the names of checks that failed.

func (*WatchStatus) GetCISummary

func (ws *WatchStatus) GetCISummary() CISummary

GetCISummary computes CI check state counts for a WatchStatus.

func (*WatchStatus) GetReviewSummary

func (ws *WatchStatus) GetReviewSummary() ReviewSummary

GetReviewSummary computes review state counts for a WatchStatus.

func (*WatchStatus) ReviewItems added in v1.3.0

func (ws *WatchStatus) ReviewItems() []ReviewItem

ReviewItems merges LatestReviews and ReviewRequests into a unified list. A pending re-review request supersedes any previous completed review (the old approval is stale after new commits are pushed).

Jump to

Keyboard shortcuts

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