github

package
v1.8.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

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

Variables

This section is empty.

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 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 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 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"`
}

PRInfo contains metadata about a GitHub pull request

func GetPRInfo

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

GetPRInfo fetches metadata for a pull request

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