Documentation
¶
Overview ¶
Package event provides detection and parsing of events from raw Copilot hook input. This centralizes all the complex logic for determining what type of event occurred (git commit, git push, file edit, etc.) and extracting relevant context.
Index ¶
- func ExtractCommitMessage(command string) string
- func ExtractGitAddFiles(command string) []string
- func ExtractPushRef(command string, currentBranch string) string
- func IsGitAddCommand(command string) bool
- func IsGitCommitCommand(command string) bool
- func IsGitPushCommand(command string) bool
- type Detector
- type GitContext
- type GitProvider
- type MockGitProvider
- func (m *MockGitProvider) GetAheadBehind(cwd string) (ahead, behind int)
- func (m *MockGitProvider) GetAuthor(cwd string) string
- func (m *MockGitProvider) GetBranch(cwd string) string
- func (m *MockGitProvider) GetPendingFiles(cwd string, command string) []schema.FileStatus
- func (m *MockGitProvider) GetRemote(cwd string) string
- func (m *MockGitProvider) GetStagedFiles(cwd string) []schema.FileStatus
- type RawHookInput
- type RealGitProvider
- func (g *RealGitProvider) GetAheadBehind(cwd string) (ahead, behind int)
- func (g *RealGitProvider) GetAuthor(cwd string) string
- func (g *RealGitProvider) GetBranch(cwd string) string
- func (g *RealGitProvider) GetPendingFiles(cwd string, command string) []schema.FileStatus
- func (g *RealGitProvider) GetRemote(cwd string) string
- func (g *RealGitProvider) GetStagedFiles(cwd string) []schema.FileStatus
- type ToolArgs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractCommitMessage ¶
ExtractCommitMessage extracts the commit message from a git commit command
func ExtractGitAddFiles ¶
ExtractGitAddFiles extracts file patterns from a git add command
func ExtractPushRef ¶
ExtractPushRef determines the ref being pushed
func IsGitAddCommand ¶
IsGitAddCommand checks if a shell command contains a git add
func IsGitCommitCommand ¶
IsGitCommitCommand checks if a shell command contains a git commit
func IsGitPushCommand ¶
IsGitPushCommand checks if a shell command contains a git push
Types ¶
type Detector ¶
type Detector struct {
// contains filtered or unexported fields
}
Detector detects and builds events from raw hook input
func NewDetector ¶
func NewDetector(gitProvider GitProvider) *Detector
NewDetector creates a new event detector
type GitContext ¶
type GitContext struct {
Branch string
Author string
StagedFiles []schema.FileStatus
PendingFiles []schema.FileStatus // Files from git add that aren't staged yet
Remote string
Ahead int
Behind int
}
GitContext provides git repository context gathered at runtime
type GitProvider ¶
type GitProvider interface {
GetBranch(cwd string) string
GetAuthor(cwd string) string
GetStagedFiles(cwd string) []schema.FileStatus
GetPendingFiles(cwd string, command string) []schema.FileStatus
GetRemote(cwd string) string
GetAheadBehind(cwd string) (ahead, behind int)
}
GitProvider interface for gathering git context (allows mocking in tests)
type MockGitProvider ¶
type MockGitProvider struct {
Branch string
Author string
StagedFiles []schema.FileStatus
PendingFiles []schema.FileStatus
Remote string
Ahead int
Behind int
}
MockGitProvider provides predetermined values for testing
func (*MockGitProvider) GetAheadBehind ¶
func (m *MockGitProvider) GetAheadBehind(cwd string) (ahead, behind int)
func (*MockGitProvider) GetAuthor ¶
func (m *MockGitProvider) GetAuthor(cwd string) string
func (*MockGitProvider) GetBranch ¶
func (m *MockGitProvider) GetBranch(cwd string) string
func (*MockGitProvider) GetPendingFiles ¶
func (m *MockGitProvider) GetPendingFiles(cwd string, command string) []schema.FileStatus
func (*MockGitProvider) GetRemote ¶
func (m *MockGitProvider) GetRemote(cwd string) string
func (*MockGitProvider) GetStagedFiles ¶
func (m *MockGitProvider) GetStagedFiles(cwd string) []schema.FileStatus
type RawHookInput ¶
type RawHookInput struct {
ToolName string `json:"toolName"`
ToolArgs json.RawMessage `json:"toolArgs"`
Cwd string `json:"cwd"`
}
RawHookInput represents the raw input from a Copilot hook
type RealGitProvider ¶
type RealGitProvider struct{}
RealGitProvider executes actual git commands to gather context
func (*RealGitProvider) GetAheadBehind ¶
func (g *RealGitProvider) GetAheadBehind(cwd string) (ahead, behind int)
GetAheadBehind returns how many commits ahead/behind the remote
func (*RealGitProvider) GetAuthor ¶
func (g *RealGitProvider) GetAuthor(cwd string) string
GetAuthor returns the git user email
func (*RealGitProvider) GetBranch ¶
func (g *RealGitProvider) GetBranch(cwd string) string
GetBranch returns the current git branch
func (*RealGitProvider) GetPendingFiles ¶
func (g *RealGitProvider) GetPendingFiles(cwd string, command string) []schema.FileStatus
GetPendingFiles returns files that would be affected by a git add command This handles the case where "git add . && git commit" is run - the files aren't staged yet when the hook fires
func (*RealGitProvider) GetRemote ¶
func (g *RealGitProvider) GetRemote(cwd string) string
GetRemote returns the default remote (usually "origin")
func (*RealGitProvider) GetStagedFiles ¶
func (g *RealGitProvider) GetStagedFiles(cwd string) []schema.FileStatus
GetStagedFiles returns files currently staged for commit