Documentation
¶
Index ¶
- Constants
- Variables
- func CheckGHAuth() error
- func CheckoutBranch(repoPath, branchName string) error
- func CleanupClone(owner, repo string) error
- func CloneRepository(owner, repo, targetPath string) error
- func ClosePR(owner, repo string, prNumber int) error
- func EnsureCloneDirectory() error
- func FetchBranch(repoPath, branchName string) error
- func FindExistingClone(owner, repo string) (string, bool)
- func GeneratePRPrompt(pr *PRInfo, includeDescription bool) string
- func GetClonePath(owner, repo string) string
- func GetPRDiff(owner, repo string, prNumber int) (string, error)
- func GetRemoteURL(repoPath string) (string, error)
- func IsForkRepo(ctx context.Context, owner, repo string) (bool, error)
- func IsGitHubRef(input string) bool
- func IsTerminal(priority PRPriority) bool
- func ListClonedRepos() ([]string, error)
- func MergePR(owner, repo string, prNumber int, method string) error
- func PostPRComment(owner, repo string, prNumber int, body string) error
- type CloneOptions
- type CloneResult
- type ETagCache
- type PRComment
- type PRInfo
- func GetPRForBranch(ctx context.Context, owner, repo, branch string) (*PRInfo, error)
- func GetPRInfo(owner, repo string, prNumber int) (*PRInfo, error)
- func GetPRInfoConditional(ctx context.Context, owner, repo string, prNumber int, cache *ETagCache) (*PRInfo, bool, error)
- func GetPRInfoCtx(ctx context.Context, owner, repo string, prNumber int) (*PRInfo, error)
- type PRPriority
- type ParsedGitHubRef
- type RefType
Constants ¶
const (
// DefaultCloneBase is the default base directory for cloned repositories
DefaultCloneBase = "~/.stapler-squad/repos"
)
Variables ¶
var ErrNoPR = errors.New("no pull request found for branch")
ErrNoPR is returned by GetPRForBranch when no pull request exists for the branch.
Functions ¶
func CheckGHAuth ¶
func CheckGHAuth() error
CheckGHAuth checks if GitHub CLI is installed and authenticated
func CheckoutBranch ¶
CheckoutBranch checks out a branch in an existing repository
func CleanupClone ¶
CleanupClone removes a cloned repository Use with caution - this deletes the entire repository directory
func CloneRepository ¶
CloneRepository clones a GitHub repository
func EnsureCloneDirectory ¶
func EnsureCloneDirectory() error
EnsureCloneDirectory ensures the base clone directory exists
func FetchBranch ¶
FetchBranch fetches a specific branch in an existing repository
func FindExistingClone ¶
FindExistingClone checks if a repository is already cloned Returns the path and true if found, empty string and false otherwise
func GeneratePRPrompt ¶
GeneratePRPrompt generates a context prompt from PR information This can be used to initialize a Claude Code session with PR context
func GetClonePath ¶
GetClonePath returns the path where a repository would be cloned Format: ~/.stapler-squad/repos/{owner}/{repo}
func GetRemoteURL ¶
GetRemoteURL returns the remote URL of a repository (used to determine owner/repo)
func IsForkRepo ¶ added in v1.12.0
IsForkRepo reports whether the given repo is a fork of another repository.
func IsGitHubRef ¶
IsGitHubRef checks if the input string looks like a GitHub URL or reference This is a quick check that doesn't validate the full format
func IsTerminal ¶ added in v1.12.0
func IsTerminal(priority PRPriority) bool
IsTerminal returns true if the priority indicates a terminal PR state. Terminal sessions should not be polled at normal frequency.
func ListClonedRepos ¶
ListClonedRepos returns a list of all cloned repositories
Types ¶
type CloneOptions ¶
type CloneOptions struct {
Owner string
Repo string
Branch string // Optional: specific branch to checkout after cloning
Shallow bool // Use shallow clone (--depth=1) for faster cloning
}
CloneOptions specifies options for cloning or accessing a repository
type CloneResult ¶
type CloneResult struct {
Path string // Full path to the repository
WasCloned bool // True if we just cloned it, false if it already existed
Branch string // Current branch name
}
CloneResult contains information about a cloned or existing repository
func GetOrCloneRepository ¶
func GetOrCloneRepository(opts CloneOptions) (*CloneResult, error)
GetOrCloneRepository ensures a repository is available locally It will clone it if not already present, or return the existing clone
type ETagCache ¶ added in v1.12.0
type ETagCache struct {
// contains filtered or unexported fields
}
ETagCache stores ETags and cached PRInfo responses per (owner, repo, prNumber). Using conditional requests (If-None-Match) allows GitHub to return 304 Not Modified responses that cost zero rate-limit quota when the PR has not changed.
func NewETagCache ¶ added in v1.12.0
func NewETagCache() *ETagCache
NewETagCache creates a new empty ETagCache.
type PRComment ¶
type PRComment struct {
ID int `json:"id"`
Author string `json:"author"`
Body string `json:"body"`
CreatedAt time.Time `json:"createdAt"`
Path string `json:"path,omitempty"` // For review comments
Line int `json:"line,omitempty"` // For review comments
IsReview bool `json:"isReview,omitempty"` // True if this is a review comment
}
PRComment represents a comment on a PR (either issue comment or review comment)
type PRInfo ¶
type PRInfo struct {
Number int `json:"number"`
Title string `json:"title"`
Body string `json:"body"`
HeadRef string `json:"headRefName"`
BaseRef string `json:"baseRefName"`
State string `json:"state"`
Author string `json:"author"`
Labels []string `json:"labels"`
HTMLURL string `json:"url"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
IsDraft bool `json:"isDraft"`
Mergeable string `json:"mergeable"`
Additions int `json:"additions"`
Deletions int `json:"deletions"`
ChangedFiles int `json:"changedFiles"`
// Review and CI status fields (populated by GetPRInfo with extended fields)
ReviewDecision string // "approved" / "changes_requested" / "review_required" / ""
ApprovedCount int // Count of current non-dismissed APPROVED reviews
ChangesRequestedCount int // Count of current non-dismissed CHANGES_REQUESTED reviews
CheckConclusion string // "success" / "failure" / "pending" / "action_required" / "neutral" / ""
CheckStatus string // "completed" / "in_progress" / ""
}
PRInfo contains metadata about a GitHub pull request
func GetPRForBranch ¶ added in v1.12.0
GetPRForBranch finds the GitHub PR associated with a branch. Returns nil (with nil error) if no PR exists for the branch.
func GetPRInfoConditional ¶ added in v1.12.0
func GetPRInfoConditional(ctx context.Context, owner, repo string, prNumber int, cache *ETagCache) (*PRInfo, bool, error)
GetPRInfoConditional fetches PR info using ETag conditional requests. Returns (info, changed, error).
- changed=false means 304 Not Modified; info contains the cached value.
- changed=true means 200 OK; info contains freshly fetched data.
- Both info and changed may be zero values when an error is returned.
type PRPriority ¶ added in v1.12.0
type PRPriority string
PRPriority is a derived single-enum priority computed from compound PR state.
const ( PRPriorityBlocking PRPriority = "blocking" // changes requested or CI failing PRPriorityReady PRPriority = "ready" // approved + CI passing PRPriorityPending PRPriority = "pending" // awaiting review or checks running PRPriorityDraft PRPriority = "draft" // PR is a draft PRPriorityComplete PRPriority = "complete" // PR is merged or closed PRPriorityNoPR PRPriority = "no_pr" // no PR found for branch PRPriorityAuthError PRPriority = "auth_error" // gh CLI not authenticated PRPriorityError PRPriority = "error" // transient error fetching status )
func DerivePRPriority ¶ added in v1.12.0
func DerivePRPriority(info *PRInfo) PRPriority
DerivePRPriority computes a single priority enum from compound PR state. Returns PRPriorityNoPR if info is nil.
type ParsedGitHubRef ¶
type ParsedGitHubRef struct {
Type RefType
Owner string
Repo string
PRNumber int // Only populated for RefTypePR
IssueNumber int // Only populated for RefTypeIssue
Branch string // Populated for RefTypeBranch, or PR head branch after fetching
CommitSHA string // Only populated for RefTypeCommit
FilePath string // Only populated for RefTypeFile (path within repo)
LineStart int // Only populated for RefTypeFile (optional line number)
LineEnd int // Only populated for RefTypeFile (optional end line for range)
BaseBranch string // Only populated for RefTypeCompare (the base of comparison)
HeadBranch string // Only populated for RefTypeCompare (the head being compared)
Tag string // Only populated for RefTypeRelease
OriginalURL string // The original input string
}
ParsedGitHubRef represents a parsed GitHub URL or reference
func ParseGitHubRef ¶
func ParseGitHubRef(input string) (*ParsedGitHubRef, error)
ParseGitHubRef parses a GitHub URL or shorthand reference into a ParsedGitHubRef Supported formats:
- https://github.com/owner/repo/pull/123
- https://github.com/owner/repo/tree/branch-name
- https://github.com/owner/repo/blob/branch/path/to/file.go
- https://github.com/owner/repo/blob/branch/file.go#L10 (with line number)
- https://github.com/owner/repo/blob/branch/file.go#L10-L20 (with line range)
- https://github.com/owner/repo/commit/abc123
- https://github.com/owner/repo/issues/42
- https://github.com/owner/repo/compare/main...feature
- https://github.com/owner/repo/releases/tag/v1.0.0
- https://github.com/owner/repo
- github.com/owner/repo
- git@github.com:owner/repo.git (SSH)
- ssh://git@github.com/owner/repo (SSH protocol)
- owner/repo:branch-name
- owner/repo
func (*ParsedGitHubRef) CloneURL ¶
func (p *ParsedGitHubRef) CloneURL() string
CloneURL returns the HTTPS clone URL for the repository
func (*ParsedGitHubRef) DisplayName ¶
func (p *ParsedGitHubRef) DisplayName() string
DisplayName returns a human-readable name for the reference
func (*ParsedGitHubRef) HTMLURL ¶
func (p *ParsedGitHubRef) HTMLURL() string
HTMLURL returns the human-readable GitHub URL
func (*ParsedGitHubRef) RepoFullName ¶
func (p *ParsedGitHubRef) RepoFullName() string
RepoFullName returns "owner/repo" format
func (*ParsedGitHubRef) SuggestedSessionName ¶
func (p *ParsedGitHubRef) SuggestedSessionName() string
SuggestedSessionName returns a suggested session name based on the reference