ghpr

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package ghpr creates pull requests via the gh CLI.

After Warden approves, this package runs `gh pr create` to file a PR with the bead reference in the title and body.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FetchUnresolvedThreadCount

func FetchUnresolvedThreadCount(ctx context.Context, worktreePath string, prNumber int) (int, error)

FetchUnresolvedThreadCount uses the GraphQL API to count unresolved review threads. Paginates through all threads (100 per page) to ensure an accurate count on large PRs.

func GetRepoOwnerAndName

func GetRepoOwnerAndName(ctx context.Context, worktreePath string) (owner, repo string, err error)

GetRepoOwnerAndName extracts the owner and repository name from git remote origin.

func Merge

func Merge(ctx context.Context, worktreePath string, prNumber int, strategy string) error

Merge merges a PR using the gh CLI with the specified strategy. Valid strategies: "squash", "merge", "rebase". Defaults to "squash" if empty.

func ParseRepoURL

func ParseRepoURL(url string) (owner, repo string, err error)

ParseRepoURL parses a git remote URL into owner and repository name.

Types

type CheckRun

type CheckRun struct {
	Name       string `json:"name"`
	Status     string `json:"status"`
	Conclusion string `json:"conclusion"`
}

CheckRun represents a CI check on the PR.

type CreateParams

type CreateParams struct {
	// WorktreePath is the git worktree directory to run gh from.
	WorktreePath string
	// BeadID to reference in the PR.
	BeadID string
	// Title for the PR (auto-generated if empty).
	Title string
	// Body for the PR (auto-generated if empty).
	Body string
	// Branch is the feature branch name.
	Branch string
	// Base is the target branch (default: main).
	Base string
	// AnvilName for state tracking.
	AnvilName string
	// Draft creates a draft PR if true.
	Draft bool
	// DB for recording the PR.
	DB *state.DB

	// BeadTitle is the bead's human-readable title (used in the PR body).
	BeadTitle string
	// BeadDescription is the bead's problem/task description (used in the PR body).
	BeadDescription string
	// BeadType is the bead's issue type (bug, feature, task, etc.).
	BeadType string
	// ChangeSummary is a summary of what changed (from warden review or diff stat).
	ChangeSummary string
}

CreateParams holds the inputs for PR creation.

type MergeabilityInputs

type MergeabilityInputs struct {
	HasConflicts         bool
	HasUnresolvedThreads bool
	HasPendingReviews    bool
}

MergeabilityInputs holds the computed boolean inputs for UpdatePRMergeability, extracted from a PRStatus. This struct exists so the conversion logic can be unit-tested without invoking the gh CLI.

func MergeabilityFromStatus

func MergeabilityFromStatus(s *PRStatus) MergeabilityInputs

MergeabilityFromStatus converts a PRStatus into the boolean inputs needed by state.DB.UpdatePRMergeability.

type OpenPR

type OpenPR struct {
	Number int
	Title  string
	Branch string
	Body   string
}

OpenPR is a lightweight view of a GitHub PR used for reconciliation.

func ListOpen

func ListOpen(ctx context.Context, worktreePath string) ([]OpenPR, error)

ListOpen returns all open PRs in the repository for the given worktree path.

type PR

type PR struct {
	Number  int
	URL     string
	Title   string
	Branch  string
	Base    string
	BeadID  string
	Anvil   string
	Created time.Time
}

PR represents a created pull request.

func Create

func Create(ctx context.Context, p CreateParams) (*PR, error)

Create files a pull request using the gh CLI and records it in the state DB.

type PRStatus

type PRStatus struct {
	State             string          `json:"state"`
	StatusCheckRollup []CheckRun      `json:"statusCheckRollup"`
	Reviews           []Review        `json:"reviews"`
	ReviewRequests    []ReviewRequest `json:"reviewRequests"`
	Mergeable         string          `json:"mergeable"`
	UnresolvedThreads int             `json:"unresolvedThreads"`
	HeadRefName       string          `json:"headRefName"`
	URL               string          `json:"url"`
}

PRStatus represents the GitHub state of a PR.

func CheckStatus

func CheckStatus(ctx context.Context, worktreePath string, prNumber int) (*PRStatus, error)

CheckStatus gets the current status of a PR via gh pr view.

func CheckStatusLight

func CheckStatusLight(ctx context.Context, worktreePath string, prNumber int) (*PRStatus, error)

CheckStatusLight gets the review-request and mergeable state of a PR without fetching unresolved thread counts (which requires expensive GraphQL pagination). Use this when you only need reviewRequests/mergeable — e.g., right after PR creation.

func (*PRStatus) CIsPassing

func (s *PRStatus) CIsPassing() bool

CIsPassing returns true if all CI checks have passed.

func (*PRStatus) HasApproval

func (s *PRStatus) HasApproval() bool

HasApproval returns true if at least one review is APPROVED.

func (*PRStatus) HasPendingReviewRequests

func (s *PRStatus) HasPendingReviewRequests() bool

HasPendingReviewRequests returns true if there are outstanding review requests that have not yet been fulfilled (i.e., the reviewer hasn't submitted a review).

func (*PRStatus) IsClosed

func (s *PRStatus) IsClosed() bool

IsClosed returns true if the PR has been closed without merging.

func (*PRStatus) IsMerged

func (s *PRStatus) IsMerged() bool

IsMerged returns true if the PR has been merged.

func (*PRStatus) NeedsChanges

func (s *PRStatus) NeedsChanges() bool

NeedsChanges returns true if any review requests changes or there are unresolved threads.

type Review

type Review struct {
	Author ReviewAuthor `json:"author"`
	State  string       `json:"state"`
	Body   string       `json:"body"`
}

Review represents a PR review.

type ReviewAuthor

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

ReviewAuthor is the author object returned by the GitHub API.

type ReviewRequest

type ReviewRequest struct {
	Login string `json:"login"`
	Slug  string `json:"slug"`
	Name  string `json:"name"`
}

ReviewRequest represents a pending review request on a PR. GitHub returns either a user login or a team slug depending on the request type.

func FetchPendingReviewRequests added in v0.2.0

func FetchPendingReviewRequests(ctx context.Context, worktreePath string, prNumber int) ([]ReviewRequest, error)

FetchPendingReviewRequests uses GraphQL to check for pending review requests, including Bot reviewers (e.g., copilot-pull-request-reviewer) that the gh CLI's --json reviewRequests field does not serialize.

Jump to

Keyboard shortcuts

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