Documentation
¶
Index ¶
- Variables
- type Commit
- type DiffFile
- type DiffResult
- type Hunk
- type Line
- type Manager
- func (m *Manager) ClonePath(host, owner, name string) string
- func (m *Manager) Diff(ctx context.Context, host, owner, name, mergeBase, headSHA string, ...) (*DiffResult, error)
- func (m *Manager) DiffFiles(ctx context.Context, host, owner, name, mergeBase, headSHA string) ([]DiffFile, error)
- func (m *Manager) EnsureClone(ctx context.Context, host, owner, name, remoteURL string) error
- func (m *Manager) ListCommits(ctx context.Context, host, owner, name, mergeBase, headSHA string) ([]Commit, error)
- func (m *Manager) MergeBase(ctx context.Context, host, owner, name, sha1, sha2 string) (string, error)
- func (m *Manager) ParentOf(ctx context.Context, host, owner, name, sha string) (string, error)
- func (m *Manager) RevParse(ctx context.Context, host, owner, name, ref string) (string, error)
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("git object not found")
ErrNotFound is returned when a git ref or object cannot be resolved.
Functions ¶
This section is empty.
Types ¶
type Commit ¶
type Commit struct {
SHA string
AuthorName string
AuthoredAt time.Time
Message string // first line only
}
Commit holds metadata for a single commit in a PR's history.
type DiffFile ¶
type DiffFile struct {
Path string `json:"path"`
OldPath string `json:"old_path"`
Status string `json:"status"` // added, modified, deleted, renamed, copied
IsBinary bool `json:"is_binary"`
IsWhitespaceOnly bool `json:"is_whitespace_only"`
Additions int `json:"additions"`
Deletions int `json:"deletions"`
Hunks []Hunk `json:"hunks"`
}
DiffFile represents one file in a diff.
func ParsePatch ¶
ParsePatch parses unified diff patch output and merges it with pre-populated file metadata from ParseRawZ. Files are correlated by output order (git emits them in the same order).
type DiffResult ¶
type DiffResult struct {
Stale bool `json:"stale"`
WhitespaceOnlyCount int `json:"whitespace_only_count"`
Files []DiffFile `json:"files"`
}
DiffResult is the structured output of a git diff operation.
type Hunk ¶
type Hunk struct {
OldStart int `json:"old_start"`
OldCount int `json:"old_count"`
NewStart int `json:"new_start"`
NewCount int `json:"new_count"`
Section string `json:"section,omitempty"`
Lines []Line `json:"lines"`
}
Hunk represents one contiguous section of changes in a file.
type Line ¶
type Line struct {
Type string `json:"type"` // context, add, delete
Content string `json:"content"`
OldNum int `json:"old_num,omitempty"`
NewNum int `json:"new_num,omitempty"`
NoNewline bool `json:"no_newline,omitempty"`
}
Line represents one line in a diff hunk.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages bare git clones for diff computation.
func New ¶
New creates a Manager that stores bare clones under baseDir. tokens maps each host (e.g., "github.com") to its auth token. A nil or empty map means all operations proceed without auth.
func (*Manager) ClonePath ¶
ClonePath returns the filesystem path for a repo's bare clone. Path is partitioned by host: {baseDir}/{host}/{owner}/{name}.git
func (*Manager) Diff ¶
func (m *Manager) Diff( ctx context.Context, host, owner, name, mergeBase, headSHA string, hideWhitespace bool, ) (*DiffResult, error)
Diff runs a two-dot git diff between mergeBase and headSHA and returns structured diff data. If hideWhitespace is true, passes -w to git diff.
func (*Manager) DiffFiles ¶
func (m *Manager) DiffFiles( ctx context.Context, host, owner, name, mergeBase, headSHA string, ) ([]DiffFile, error)
DiffFiles returns file metadata (path, status, renames) without patch content. It runs only git diff --raw, which is much faster than a full diff for large PRs.
func (*Manager) EnsureClone ¶
EnsureClone creates or fetches a bare clone for the given repo. remoteURL is the HTTPS clone URL (e.g., https://github.com/owner/name.git). On first call, clones the repo. On subsequent calls, fetches updates.
func (*Manager) ListCommits ¶
func (m *Manager) ListCommits( ctx context.Context, host, owner, name, mergeBase, headSHA string, ) ([]Commit, error)
ListCommits returns commits between mergeBase and headSHA, newest first, following only the first-parent chain. If mergeBase is the empty tree sentinel (parentless root), all commits up to headSHA are returned.
func (*Manager) MergeBase ¶
func (m *Manager) MergeBase( ctx context.Context, host, owner, name, sha1, sha2 string, ) (string, error)
MergeBase computes the merge base between two commits.