git

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package git provides git-context enrichment and remote-forge integration. See ../REFACTOR_PLAN.md.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectProvider

func DetectProvider(projectDir string) (string, string, string)

DetectProvider parses .git/config or uses gh to detect provider/owner/repo.

func FormatCIStatus

func FormatCIStatus(status *CIStatus) string

FormatCIStatus formats a CIStatus for terminal display.

func FormatIssues

func FormatIssues(issues []GitIssue) string

FormatIssues formats a slice of issues for terminal display.

func FormatPRs

func FormatPRs(prs []PullRequest) string

FormatPRs formats a slice of pull requests for terminal display.

Types

type BlameLine

type BlameLine struct {
	LineNo int
	Author string
	Date   time.Time
	Commit string
}

BlameLine represents blame info for a single line.

type CICheck

type CICheck struct {
	Name     string
	Status   string
	Duration time.Duration
	URL      string
}

CICheck represents a single CI check/job.

type CIStatus

type CIStatus struct {
	State  string // "success", "failure", "pending"
	Checks []CICheck
	URL    string
}

CIStatus represents the overall CI/CD status for a branch.

type CommitInfo

type CommitInfo struct {
	Hash         string
	Author       string
	Date         time.Time
	Message      string
	FilesChanged int
}

CommitInfo represents a single git commit.

type Context

type Context = GitContext

Context wraps a local git repo and exposes file/commit/blame queries.

func NewContext

func NewContext(repoDir string) *Context

NewContext returns a git Context bound to the given working directory.

type FileInfo

type FileInfo = GitFileInfo

FileInfo summarises a tracked file's git metadata.

type GitContext

type GitContext struct {
	RepoDir string
	// contains filtered or unexported fields
}

GitContext provides git-aware context enrichment for files and sessions.

func NewGitContext

func NewGitContext(repoDir string) *GitContext

NewGitContext creates a new GitContext for the given repo directory.

func (*GitContext) BuildContextForFile

func (gc *GitContext) BuildContextForFile(path string) string

BuildContextForFile gathers all git context for a file and formats it as a readable string.

func (*GitContext) BuildContextForSession

func (gc *GitContext) BuildContextForSession() string

BuildContextForSession returns overall repository context.

func (*GitContext) GetBlame

func (gc *GitContext) GetBlame(path string, startLine, endLine int) ([]BlameLine, error)

GetBlame returns blame info for lines startLine to endLine of the given file.

func (*GitContext) GetBranch

func (gc *GitContext) GetBranch() (string, error)

GetBranch returns the current branch name.

func (*GitContext) GetDiffSummary

func (gc *GitContext) GetDiffSummary() (string, error)

GetDiffSummary summarizes current uncommitted changes.

func (*GitContext) GetFileInfo

func (gc *GitContext) GetFileInfo(path string) (*GitFileInfo, error)

GetFileInfo returns git metadata for a file, using cache if available.

func (*GitContext) GetRecentChanges

func (gc *GitContext) GetRecentChanges(days int) ([]CommitInfo, error)

GetRecentChanges returns commits from the last N days.

func (*GitContext) GetRelatedFiles

func (gc *GitContext) GetRelatedFiles(path string) ([]string, error)

GetRelatedFiles finds files frequently modified together with the given file.

func (*GitContext) GetUncommitted

func (gc *GitContext) GetUncommitted() ([]string, error)

GetUncommitted returns a list of modified or staged files.

func (*GitContext) IsRecentlyModified

func (gc *GitContext) IsRecentlyModified(path string, within time.Duration) bool

IsRecentlyModified checks if the file was modified within the given duration.

type GitFileInfo

type GitFileInfo struct {
	Path          string
	LastAuthor    string
	LastCommitMsg string
	LastModified  time.Time
	CommitCount   int
	Contributors  []string
	RecentCommits []CommitInfo
	Blame         []BlameLine
}

GitFileInfo holds git metadata about a specific file.

type GitIssue

type GitIssue struct {
	Number    int
	Title     string
	Body      string
	Labels    []string
	State     string
	Author    string
	CreatedAt time.Time
	URL       string
}

GitIssue represents a git provider issue.

type GitProvider

type GitProvider struct {
	Type    string // "github", "gitlab", "bitbucket"
	Token   string
	Owner   string
	Repo    string
	BaseURL string
	// contains filtered or unexported fields
}

GitProvider integrates with GitHub/GitLab/Bitbucket APIs for issue management, PR creation, and CI status checking via CLI tools.

func NewGitProvider

func NewGitProvider(providerType, token, owner, repo string) *GitProvider

NewGitProvider creates a new GitProvider with the given configuration.

func (*GitProvider) CreateIssue

func (gp *GitProvider) CreateIssue(title, body string, labels []string) (*GitIssue, error)

CreateIssue creates a new issue with the given title, body, and labels.

func (*GitProvider) CreatePR

func (gp *GitProvider) CreatePR(title, body, branch, baseBranch string) (*PullRequest, error)

CreatePR creates a new pull request.

func (*GitProvider) GetCIStatus

func (gp *GitProvider) GetCIStatus(branch string) (*CIStatus, error)

GetCIStatus returns the CI status for the given branch.

func (*GitProvider) GetIssue

func (gp *GitProvider) GetIssue(number int) (*GitIssue, error)

GetIssue returns a single issue by number.

func (*GitProvider) GetReviewComments

func (gp *GitProvider) GetReviewComments(prNumber int) ([]string, error)

GetReviewComments returns review comments for a PR.

func (*GitProvider) ListIssues

func (gp *GitProvider) ListIssues(state string, limit int) ([]GitIssue, error)

ListIssues returns issues matching the given state and limit.

func (*GitProvider) ListPRs

func (gp *GitProvider) ListPRs(state string, limit int) ([]PullRequest, error)

ListPRs returns pull requests matching the given state and limit.

type Issue

type Issue = GitIssue

Issue is a remote-forge issue record.

type Provider

type Provider = GitProvider

Provider talks to a remote forge (GitHub, GitLab, ...) for issues, PRs, CI.

func NewProvider

func NewProvider(providerType, token, owner, repo string) *Provider

NewProvider returns a forge provider client.

type PullRequest

type PullRequest struct {
	Number     int
	Title      string
	Body       string
	Branch     string
	BaseBranch string
	State      string
	Draft      bool
	Labels     []string
	URL        string
	Mergeable  bool
}

PullRequest represents a pull/merge request.

Jump to

Keyboard shortcuts

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