Documentation
¶
Index ¶
- func FileExists(repoDir, filePath string) bool
- func ReadFile(repoDir, filePath string) ([]byte, error)
- func WriteFile(repoDir, filePath string, content []byte) error
- type MockOperations
- func (m *MockOperations) AddFile(path string) error
- func (m *MockOperations) BranchExists(name, remote string) (bool, error)
- func (m *MockOperations) Commit(message string) error
- func (m *MockOperations) CreateBranch(name string) error
- func (m *MockOperations) CreatePR(base, head, title, body string, draft bool) (string, error)
- func (m *MockOperations) GetCurrentBranch() (string, error)
- func (m *MockOperations) GetDefaultBranch() (string, error)
- func (m *MockOperations) IsWorkingTreeClean() (bool, error)
- func (m *MockOperations) Push(remote, branch string) error
- func (m *MockOperations) SwitchBranch(name string) error
- func (m *MockOperations) Validate(expectedBranch string) error
- type Operations
- type RealOperations
- func (r *RealOperations) AddFile(path string) error
- func (r *RealOperations) BranchExists(name, remote string) (bool, error)
- func (r *RealOperations) Commit(message string) error
- func (r *RealOperations) CreateBranch(name string) error
- func (r *RealOperations) CreatePR(base, head, title, body string, draft bool) (string, error)
- func (r *RealOperations) GetCurrentBranch() (string, error)
- func (r *RealOperations) GetDefaultBranch() (string, error)
- func (r *RealOperations) IsWorkingTreeClean() (bool, error)
- func (r *RealOperations) Push(remote, branch string) error
- func (r *RealOperations) SwitchBranch(name string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FileExists ¶
FileExists checks if a file exists in the repository.
Types ¶
type MockOperations ¶
type MockOperations struct {
DefaultBranch string
CurrentBranch string
IsClean bool
BranchExistsMap map[string]bool // Map of branch names to whether they exist
CreatedBranches []string
SwitchedBranches []string
AddedFiles []string
Commits []string
Pushes []struct{ Remote, Branch string }
CreatedPRs []struct {
Base, Head, Title, Body string
Draft bool
}
PRURLToReturn string
// Error fields for simulating failures
DefaultBranchErr error
CurrentBranchErr error
IsCleanErr error
BranchExistsErr error
CreateBranchErr error
SwitchBranchErr error
AddFileErr error
CommitErr error
PushErr error
CreatePRErr error
}
MockOperations is a mock implementation of Operations for testing.
func NewMockOperations ¶
func NewMockOperations() *MockOperations
NewMockOperations creates a new MockOperations with default successful behavior.
func (*MockOperations) AddFile ¶
func (m *MockOperations) AddFile(path string) error
AddFile records the added file.
func (*MockOperations) BranchExists ¶
func (m *MockOperations) BranchExists(name, remote string) (bool, error)
BranchExists returns whether a branch exists in the mock.
func (*MockOperations) Commit ¶
func (m *MockOperations) Commit(message string) error
Commit records the commit.
func (*MockOperations) CreateBranch ¶
func (m *MockOperations) CreateBranch(name string) error
CreateBranch records the created branch.
func (*MockOperations) CreatePR ¶
func (m *MockOperations) CreatePR(base, head, title, body string, draft bool) (string, error)
CreatePR records the PR creation.
func (*MockOperations) GetCurrentBranch ¶
func (m *MockOperations) GetCurrentBranch() (string, error)
GetCurrentBranch returns the mock current branch.
func (*MockOperations) GetDefaultBranch ¶
func (m *MockOperations) GetDefaultBranch() (string, error)
GetDefaultBranch returns the mock default branch.
func (*MockOperations) IsWorkingTreeClean ¶
func (m *MockOperations) IsWorkingTreeClean() (bool, error)
IsWorkingTreeClean returns the mock clean status.
func (*MockOperations) Push ¶
func (m *MockOperations) Push(remote, branch string) error
Push records the push.
func (*MockOperations) SwitchBranch ¶
func (m *MockOperations) SwitchBranch(name string) error
SwitchBranch records the branch switch.
func (*MockOperations) Validate ¶
func (m *MockOperations) Validate(expectedBranch string) error
Validate checks that all expected operations were performed.
type Operations ¶
type Operations interface {
// GetDefaultBranch returns the default branch name for the repository.
GetDefaultBranch() (string, error)
// GetCurrentBranch returns the current branch name.
GetCurrentBranch() (string, error)
// IsWorkingTreeClean checks if the working tree is clean (no uncommitted changes).
IsWorkingTreeClean() (bool, error)
// BranchExists checks if a branch exists locally or on remote.
BranchExists(name, remote string) (bool, error)
// CreateBranch creates and switches to a new branch.
CreateBranch(name string) error
// SwitchBranch switches to an existing branch.
SwitchBranch(name string) error
// AddFile stages a file for commit.
AddFile(path string) error
// Commit commits staged changes with the given message.
Commit(message string) error
// Push pushes the current branch to the specified remote.
Push(remote, branch string) error
// CreatePR creates a pull request using GitHub CLI.
CreatePR(base, head, title, body string, draft bool) (string, error)
}
Operations defines the interface for git and GitHub CLI operations. This allows for mocking in tests.
type RealOperations ¶
type RealOperations struct {
// RepoDir is the repository directory to operate on.
RepoDir string
}
RealOperations implements Operations using actual git and gh commands.
func NewRealOperations ¶
func NewRealOperations(repoDir string) *RealOperations
NewRealOperations creates a new RealOperations instance for the given directory.
func (*RealOperations) AddFile ¶
func (r *RealOperations) AddFile(path string) error
AddFile stages a file for commit.
func (*RealOperations) BranchExists ¶
func (r *RealOperations) BranchExists(name, remote string) (bool, error)
BranchExists checks if a branch exists locally or on remote. Note: This checks using locally available refs. For remote branches, this requires that refs have been fetched. It will not perform a git fetch.
func (*RealOperations) Commit ¶
func (r *RealOperations) Commit(message string) error
Commit commits staged changes with the given message.
func (*RealOperations) CreateBranch ¶
func (r *RealOperations) CreateBranch(name string) error
CreateBranch creates and switches to a new branch.
func (*RealOperations) CreatePR ¶
func (r *RealOperations) CreatePR(base, head, title, body string, draft bool) (string, error)
CreatePR creates a pull request using GitHub CLI.
func (*RealOperations) GetCurrentBranch ¶
func (r *RealOperations) GetCurrentBranch() (string, error)
GetCurrentBranch returns the current branch name.
func (*RealOperations) GetDefaultBranch ¶
func (r *RealOperations) GetDefaultBranch() (string, error)
GetDefaultBranch returns the default branch name using GitHub CLI.
func (*RealOperations) IsWorkingTreeClean ¶
func (r *RealOperations) IsWorkingTreeClean() (bool, error)
IsWorkingTreeClean checks if the working tree is clean.
func (*RealOperations) Push ¶
func (r *RealOperations) Push(remote, branch string) error
Push pushes the current branch to the specified remote.
func (*RealOperations) SwitchBranch ¶
func (r *RealOperations) SwitchBranch(name string) error
SwitchBranch switches to an existing branch.