git

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlameFile added in v1.2.0

func BlameFile(ctx context.Context, ref, filePath string) (map[int]BlameLine, error)

BlameFile runs git blame on a file at a specific ref and returns blame info keyed by line number (1-indexed).

func FetchRefs

func FetchRefs(base, head, headRefOid string) error

FetchRefs ensures that the local git repository has the latest commits for the base and head branches of the pull request. If headRefOid is provided and matches the local origin/<head> ref, the fetch is skipped since the local repo is already up-to-date.

func GetChromaDiffWithContext added in v1.2.0

func GetChromaDiffWithContext(base, head, file string, contextLines int, theme DiffTheme, width int) (string, error)

GetChromaDiffWithContext renders a syntax-highlighted diff using chroma instead of the external delta binary. This is an experimental alternative renderer enabled via --chroma flag.

func GetLocalRefHash

func GetLocalRefHash(ref string) string

GetLocalRefHash resolves a remote-tracking ref (e.g. "origin/main") to its commit hash, returning an empty string if the ref doesn't exist locally.

func GetRawDiff

func GetRawDiff(base, head, file string) (string, error)

GetRawDiff runs a git diff between the base and head branch for a specific file.

func GetRawDiffWithContext

func GetRawDiffWithContext(base, head, file string, contextLines int) (string, error)

GetRawDiffWithContext runs a git diff with configurable context lines.

func GetStyledDiff

func GetStyledDiff(base, head, file string, theme DiffTheme) (string, error)

GetStyledDiff runs a git diff and pipes it to delta to get ANSI-styled output.

func GetStyledDiffWithContext

func GetStyledDiffWithContext(base, head, file string, contextLines int, theme DiffTheme) (string, error)

GetStyledDiffWithContext runs a styled git diff with configurable context lines. The theme parameter controls all colors used by the delta subprocess.

func HasActiveRuns added in v1.3.0

func HasActiveRuns(runs []WorkflowRun) bool

HasActiveRuns returns true if any run is still queued or in progress.

func HashDiff

func HashDiff(diff string) string

HashDiff generates a SHA-256 hash of the provided diff string. This is used for invalidating locally cached state if the diff changes.

func PostPRComment added in v1.3.0

func PostPRComment(prNumber, body string) error

PostPRComment posts a general (non-line-specific) comment on a PR.

func RepoRoot added in v1.3.0

func RepoRoot() (string, error)

RepoRoot returns the absolute path to the root of the current git repository.

func SubmitReview

func SubmitReview(prNumber, verdict, body string) error

SubmitReview submits a formal GitHub review (approve, request_changes, or comment). verdict must be one of: "APPROVE", "REQUEST_CHANGES", "COMMENT".

func SubmitReviewWithFindings added in v1.3.0

func SubmitReviewWithFindings(prNumber, commitSHA, body string, comments []ReviewFindingComment) error

SubmitReviewWithFindings creates a GitHub PR review with inline comments. Uses the GitHub REST API: POST repos/{owner}/{repo}/pulls/{pr}/reviews

Types

type ActionStatus added in v1.3.0

type ActionStatus int

ActionStatus represents the aggregate status across all workflow runs.

const (
	ActionStatusNone       ActionStatus = iota // no runs found
	ActionStatusPassed                         // all completed successfully
	ActionStatusFailed                         // at least one failed
	ActionStatusInProgress                     // at least one in progress or queued
)

func AggregateActionStatus added in v1.3.0

func AggregateActionStatus(runs []WorkflowRun) ActionStatus

AggregateActionStatus computes the overall status from a list of runs.

type BlameLine added in v1.2.0

type BlameLine struct {
	Author string
	Date   string // YYYY-MM-DD
}

BlameLine holds blame information for a single source line.

type DiffTheme added in v1.2.0

type DiffTheme struct {
	SyntaxTheme       string // delta --syntax-theme value
	ChromaSyntaxStyle string // chroma style name (e.g. "monokai", "dracula")
	AddedBg           string // e.g. "#122f1c"
	AddedEmphBg       string
	RemovedBg         string
	RemovedEmphBg     string
	AccentMauve       string // hunk header text
	AccentBlue        string // file header text
	AccentGreen       string // line number plus
	AccentRed         string // line number minus
	AccentPeach       string // hunk line number, commit style
	SurfaceColor      string // hunk header box, line number zero
	SubtleColor       string // file decoration, overlay
}

DiffTheme holds colors for the styled diff renderer. Populated from the active UI theme so delta output matches.

func DefaultDiffTheme added in v1.2.0

func DefaultDiffTheme() DiffTheme

DefaultDiffTheme returns the Catppuccin Mocha theme colors (legacy default).

type PRAuthor

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

PRAuthor represents the author of a pull request.

type PRFile

type PRFile struct {
	Path      string `json:"path"`
	Additions int    `json:"additions"`
	Deletions int    `json:"deletions"`
}

PRFile represents a file changed in the pull request

type PRListItem

type PRListItem struct {
	Number int    `json:"number"`
	Title  string `json:"title"`
	Author struct {
		Login string `json:"login"`
	} `json:"author"`
	HeadRefName string `json:"headRefName"`
	State       string `json:"state"`
	CreatedAt   string `json:"createdAt"`
	UpdatedAt   string `json:"updatedAt"`
}

PRListItem is a lightweight PR summary returned by ListPRs.

func ListPRs

func ListPRs() ([]PRListItem, error)

ListPRs returns open pull requests for the current repository.

type PROwner

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

PROwner represents the owner of a repository.

type PRRepo

type PRRepo struct {
	Name  string  `json:"name"`
	Owner PROwner `json:"owner"`
}

PRRepo represents a repository reference from the GitHub CLI.

type PullRequest

type PullRequest struct {
	Number         int      `json:"number"`
	Title          string   `json:"title"`
	Body           string   `json:"body"`
	State          string   `json:"state"`
	BaseRefName    string   `json:"baseRefName"`
	HeadRefName    string   `json:"headRefName"`
	HeadRefOid     string   `json:"headRefOid"`
	Author         PRAuthor `json:"author"`
	HeadRepository PRRepo   `json:"headRepository"`
	ReviewDecision string   `json:"reviewDecision"`
	Files          []PRFile `json:"files"`
}

PullRequest represents the metadata of a pull request fetched from the GitHub CLI.

func FetchPR

func FetchPR(prNumber string) (*PullRequest, error)

FetchPR uses the GitHub CLI to retrieve PR metadata and file list.

type ReviewComment

type ReviewComment struct {
	ID          int    `json:"id"`
	InReplyToID int    `json:"in_reply_to_id"` // non-zero for threaded replies
	Path        string `json:"path"`
	Line        int    `json:"line"` // line number in the diff (new file side)
	Side        string `json:"side"` // "LEFT" or "RIGHT"
	Body        string `json:"body"`
	Author      string `json:"-"` // populated from user.login
	CreatedAt   string `json:"created_at"`
	UpdatedAt   string `json:"updated_at"`
}

ReviewComment represents a line-level review comment on a PR.

func CreateReviewComment

func CreateReviewComment(prNumber, commitSHA, path, body string, line int, side string) (*ReviewComment, error)

CreateReviewComment posts a new line-level review comment on a PR.

func FetchReviewComments

func FetchReviewComments(prNumber string) ([]ReviewComment, error)

FetchReviewComments retrieves all line-level review comments for a PR.

type ReviewFindingComment added in v1.3.0

type ReviewFindingComment struct {
	Path string `json:"path"`
	Line int    `json:"line"`
	Body string `json:"body"`
	Side string `json:"side"`
}

ReviewFindingComment is a single inline comment for a batch review submission.

type SkipReason

type SkipReason string

SkipReason describes why a file was excluded from AI review.

const (
	SkipBinary    SkipReason = "binary"
	SkipGenerated SkipReason = "generated"
	SkipLarge     SkipReason = "large"
)

func ShouldSkipForAI

func ShouldSkipForAI(path string, rawDiff string) (skip bool, reason SkipReason)

ShouldSkipForAI determines whether a file should be excluded from AI review. It checks (in order): git binary marker, extension blocklist, known generated/lock files, generated suffixes, and diff size threshold. Returns skip=true with a reason if the file should be skipped.

type WorkflowJob added in v1.3.0

type WorkflowJob struct {
	ID         int            `json:"id"`
	Name       string         `json:"name"`
	Status     string         `json:"status"`     // "queued", "in_progress", "completed"
	Conclusion string         `json:"conclusion"` // "success", "failure", "cancelled", "skipped"
	Steps      []WorkflowStep `json:"steps"`
}

WorkflowJob represents a single job within a workflow run.

func FetchWorkflowJobs added in v1.3.0

func FetchWorkflowJobs(runID int) ([]WorkflowJob, error)

FetchWorkflowJobs retrieves jobs for a specific workflow run. Uses: gh api repos/{owner}/{repo}/actions/runs/{id}/jobs

type WorkflowRun added in v1.3.0

type WorkflowRun struct {
	ID         int    `json:"id"`
	Name       string `json:"name"`
	Status     string `json:"status"`     // "queued", "in_progress", "completed"
	Conclusion string `json:"conclusion"` // "success", "failure", "cancelled", "skipped", "neutral"
	URL        string `json:"html_url"`
	CreatedAt  string `json:"created_at"`
	UpdatedAt  string `json:"updated_at"`
}

WorkflowRun represents a GitHub Actions workflow run.

func FetchWorkflowRuns added in v1.3.0

func FetchWorkflowRuns(headSHA string) ([]WorkflowRun, error)

FetchWorkflowRuns retrieves all workflow runs for the given head SHA. Uses: gh api repos/{owner}/{repo}/actions/runs?head_sha={sha}

type WorkflowStep added in v1.3.0

type WorkflowStep struct {
	Name       string `json:"name"`
	Status     string `json:"status"`     // "queued", "in_progress", "completed"
	Conclusion string `json:"conclusion"` // "success", "failure", "cancelled", "skipped"
	Number     int    `json:"number"`
}

WorkflowStep represents a single step within a workflow job.

Jump to

Keyboard shortcuts

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