github

package
v1.20.1 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultCloneBase is the default base directory for cloned repositories
	DefaultCloneBase = "~/.stapler-squad/repos"
)

Variables

View Source
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

func CheckoutBranch(repoPath, branchName string) error

CheckoutBranch checks out a branch in an existing repository

func CleanupClone

func CleanupClone(owner, repo string) error

CleanupClone removes a cloned repository Use with caution - this deletes the entire repository directory

func CloneRepository

func CloneRepository(owner, repo, targetPath string) error

CloneRepository clones a GitHub repository

func ClosePR

func ClosePR(owner, repo string, prNumber int) error

ClosePR closes a pull request without merging

func EnsureCloneDirectory

func EnsureCloneDirectory() error

EnsureCloneDirectory ensures the base clone directory exists

func FetchBranch

func FetchBranch(repoPath, branchName string) error

FetchBranch fetches a specific branch in an existing repository

func FindExistingClone

func FindExistingClone(owner, repo string) (string, bool)

FindExistingClone checks if a repository is already cloned Returns the path and true if found, empty string and false otherwise

func GeneratePRPrompt

func GeneratePRPrompt(pr *PRInfo, includeDescription bool) string

GeneratePRPrompt generates a context prompt from PR information This can be used to initialize a Claude Code session with PR context

func GetClonePath

func GetClonePath(owner, repo string) string

GetClonePath returns the path where a repository would be cloned Format: ~/.stapler-squad/repos/{owner}/{repo}

func GetPRDiff

func GetPRDiff(owner, repo string, prNumber int) (string, error)

GetPRDiff fetches the diff for a pull request

func GetRemoteURL

func GetRemoteURL(repoPath string) (string, error)

GetRemoteURL returns the remote URL of a repository (used to determine owner/repo)

func IsForkRepo added in v1.12.0

func IsForkRepo(ctx context.Context, owner, repo string) (bool, error)

IsForkRepo reports whether the given repo is a fork of another repository.

func IsGitHubRef

func IsGitHubRef(input string) bool

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

func ListClonedRepos() ([]string, error)

ListClonedRepos returns a list of all cloned repositories

func MergePR

func MergePR(owner, repo string, prNumber int, method string) error

MergePR merges a pull request method can be: "merge", "squash", or "rebase"

func PostPRComment

func PostPRComment(owner, repo string, prNumber int, body string) error

PostPRComment posts a comment on a pull request

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)

func GetPRComments

func GetPRComments(owner, repo string, prNumber int) ([]PRComment, error)

GetPRComments fetches all comments on a pull request

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

func GetPRForBranch(ctx context.Context, owner, repo, branch string) (*PRInfo, error)

GetPRForBranch finds the GitHub PR associated with a branch. Returns nil (with nil error) if no PR exists for the branch.

func GetPRInfo

func GetPRInfo(owner, repo string, prNumber int) (*PRInfo, error)

GetPRInfo fetches metadata for a pull request including review and CI status.

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.

func GetPRInfoCtx added in v1.12.0

func GetPRInfoCtx(ctx context.Context, owner, repo string, prNumber int) (*PRInfo, error)

GetPRInfoCtx fetches metadata for a pull request with context support. Includes review decisions and CI/check status.

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 (*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

type RefType

type RefType int

RefType represents the type of GitHub reference parsed from a URL or shorthand

const (
	RefTypePR RefType = iota
	RefTypeBranch
	RefTypeRepo
	RefTypeFile    // File/blob URL
	RefTypeCommit  // Commit URL
	RefTypeIssue   // Issue URL
	RefTypeCompare // Compare URL (branch comparison)
	RefTypeRelease // Release/tag URL
)

func (RefType) String

func (t RefType) String() string

Jump to

Keyboard shortcuts

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