event

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 6 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractCommitMessage

func ExtractCommitMessage(command string) string

ExtractCommitMessage extracts the commit message from a git commit command

func ExtractGitAddFiles

func ExtractGitAddFiles(command string) []string

ExtractGitAddFiles extracts file patterns from a git add command

func ExtractPushRef

func ExtractPushRef(command string, currentBranch string) string

ExtractPushRef determines the ref being pushed

func IsGitAddCommand

func IsGitAddCommand(command string) bool

IsGitAddCommand checks if a shell command contains a git add

func IsGitCommitCommand

func IsGitCommitCommand(command string) bool

IsGitCommitCommand checks if a shell command contains a git commit

func IsGitPushCommand

func IsGitPushCommand(command string) bool

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

func (*Detector) Detect

func (d *Detector) Detect(raw *RawHookInput) (*schema.Event, error)

Detect determines the event type and builds the appropriate event structure

func (*Detector) DetectFromRawInput

func (d *Detector) DetectFromRawInput(input []byte) (*schema.Event, error)

DetectFromRawInput parses raw hook input and returns a structured event

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

type ToolArgs

type ToolArgs struct {
	Command  string `json:"command"`
	Script   string `json:"script"`
	Code     string `json:"code"`
	Path     string `json:"path"`
	FileText string `json:"file_text"`
	OldStr   string `json:"old_str"`
	NewStr   string `json:"new_str"`
}

ToolArgs represents parsed tool arguments

Jump to

Keyboard shortcuts

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