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 ¶
- func FetchUnresolvedThreadCount(ctx context.Context, worktreePath string, prNumber int) (int, error)
- func GetRepoOwnerAndName(ctx context.Context, worktreePath string) (owner, repo string, err error)
- func Merge(ctx context.Context, worktreePath string, prNumber int, strategy string) error
- func ParseRepoURL(url string) (owner, repo string, err error)
- type CheckRun
- type CreateParams
- type MergeabilityInputs
- type OpenPR
- type PR
- type PRStatus
- type Review
- type ReviewAuthor
- type ReviewRequest
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 ¶
GetRepoOwnerAndName extracts the owner and repository name from git remote origin.
func Merge ¶
Merge merges a PR using the gh CLI with the specified strategy. Valid strategies: "squash", "merge", "rebase". Defaults to "squash" if empty.
func ParseRepoURL ¶
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 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.
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"`
}
PRStatus represents the GitHub state of a PR.
func CheckStatus ¶
CheckStatus gets the current status of a PR via gh pr view.
func CheckStatusLight ¶
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 ¶
CIsPassing returns true if all CI checks have passed.
func (*PRStatus) HasApproval ¶
HasApproval returns true if at least one review is APPROVED.
func (*PRStatus) HasPendingReviewRequests ¶
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) NeedsChanges ¶
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.