infrastructure

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 18 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DefaultGitTag               = "0.1.0"
	MaxAcceptableInitialCommits = 5
)

Variables

View Source
var (
	ErrNoAuthMethodFound  = errors.New("no authentication method found")
	ErrAuthNotImplemented = errors.New("authentication method not implemented")
	ErrNoRemoteURL        = errors.New("no remote URL found for repository")
	ErrNoTagsFound        = errors.New("no tags found in Git history")
)

Functions

func CheckBranchExists

func CheckBranchExists(repo *git.Repository, branchName string) (bool, error)

CheckBranchExists checks if a given Git branch exists (local or remote). Exported for use by autobump (github.com/rios0rios0/autobump).

func CheckoutBranch

func CheckoutBranch(w *git.Worktree, branchName string) error

CheckoutBranch switches to the given branch. Exported for use by autobump (github.com/rios0rios0/autobump).

func CommitChanges

func CommitChanges(
	repo *git.Repository,
	workTree *git.Worktree,
	commitMessage string,
	signer globalEntities.CommitSigner,
	name string,
	email string,
) (plumbing.Hash, error)

CommitChanges commits the changes in the given worktree with optional signing. The repo parameter is required when using a CommitSigner that produces post-commit signatures (e.g. SSH). Exported for use by autobump (github.com/rios0rios0/autobump).

func CreateAndSwitchBranch

func CreateAndSwitchBranch(
	repo *git.Repository,
	workTree *git.Worktree,
	branchName string,
	hash plumbing.Hash,
) error

CreateAndSwitchBranch creates a new branch and switches to it. Exported for use by autobump (github.com/rios0rios0/autobump).

func GetAmountCommits

func GetAmountCommits(repo *git.Repository) (int, error)

GetAmountCommits returns the number of commits in the repository.

func GetLatestTag

func GetLatestTag(repo *git.Repository) (*globalEntities.LatestTag, error)

GetLatestTag finds the latest tag in the Git history. Exported for use by autobump (github.com/rios0rios0/autobump).

func GetRemoteRepoURL

func GetRemoteRepoURL(repo *git.Repository) (string, error)

GetRemoteRepoURL returns the URL of the remote repository. Exported for use by autobump (github.com/rios0rios0/autobump).

func OpenRepo

func OpenRepo(projectPath string) (*git.Repository, error)

OpenRepo opens a git repository at the given path. Exported for use by autobump (github.com/rios0rios0/autobump).

func PushChangesSSH

func PushChangesSSH(repo *git.Repository, refSpec config.RefSpec) error

PushChangesSSH pushes the changes to the remote repository over SSH.

func PushWithTransportDetection added in v0.3.0

func PushWithTransportDetection(
	repo *git.Repository,
	refSpec config.RefSpec,
	authMethods []transport.AuthMethod,
) error

PushWithTransportDetection pushes the given refSpec to the origin remote, auto-detecting the transport (SSH or HTTPS) from the remote URL.

For SSH remotes (git@ or ssh://), the push uses system SSH keys and the authMethods parameter is ignored.

For HTTPS/HTTP remotes, authMethods are tried in order until one succeeds. An empty authMethods slice returns an error for HTTPS remotes.

Exported for use by autobump (github.com/rios0rios0/autobump) and autoupdate (github.com/rios0rios0/autoupdate).

func StageAll

func StageAll(workTree *git.Worktree) error

StageAll adds all changes in the working tree to the index, equivalent to `git add -A`. It stages new, modified, and deleted files. Exported for use by autoupdate (github.com/rios0rios0/autoupdate).

func WorktreeIsClean

func WorktreeIsClean(workTree *git.Worktree) (bool, error)

WorktreeIsClean returns true when the working tree has no uncommitted changes (staged or unstaged). This is the go-git equivalent of `git status --porcelain` returning empty output. Exported for use by autoupdate (github.com/rios0rios0/autoupdate).

Types

type GitOperations

type GitOperations struct {
	// contains filtered or unexported fields
}

GitOperations encapsulates git operations with an adapter finder for service type resolution.

func NewGitOperations

func NewGitOperations(finder gitEntities.AdapterFinder) *GitOperations

NewGitOperations creates a new GitOperations with the given adapter finder.

func (*GitOperations) CloneRepo

func (o *GitOperations) CloneRepo(
	url, dir string,
	authMethods []transport.AuthMethod,
) (*git.Repository, error)

CloneRepo clones a remote repository into the given directory. It prepares the clone URL via the adapter finder (if one matches the URL) and tries each provided authentication method until one succeeds.

func (*GitOperations) GetAuthMethods

func (o *GitOperations) GetAuthMethods(
	service globalEntities.ServiceType,
	username string,
) ([]transport.AuthMethod, error)

GetAuthMethods returns the authentication methods for the given service type. It delegates to the appropriate adapter based on the service type. Exported for use by autobump (github.com/rios0rios0/autobump).

func (*GitOperations) GetRemoteServiceType

func (o *GitOperations) GetRemoteServiceType(repo *git.Repository) (globalEntities.ServiceType, error)

GetRemoteServiceType returns the type of the remote service (e.g. GitHub, GitLab). Exported for use by autobump (github.com/rios0rios0/autobump).

func (*GitOperations) GetServiceTypeByURL

func (o *GitOperations) GetServiceTypeByURL(remoteURL string) globalEntities.ServiceType

GetServiceTypeByURL returns the type of the remote service by URL. Exported for use by autobump (github.com/rios0rios0/autobump).

func (*GitOperations) PushChangesHTTPS

func (o *GitOperations) PushChangesHTTPS(
	repo *git.Repository,
	username string,
	refSpec config.RefSpec,
) error

PushChangesHTTPS pushes the changes to the remote repository over HTTPS. It tries each authentication method returned by the adapter until one succeeds.

type PullRequestURLInfo

type PullRequestURLInfo struct {
	ServiceType  globalEntities.ServiceType
	Organization string
	Project      string // Azure DevOps only; empty for GitHub/GitLab
	RepoName     string
	PRID         int
}

PullRequestURLInfo holds the parsed components of a pull request URL.

func ParsePullRequestURL

func ParsePullRequestURL(rawURL string) (*PullRequestURLInfo, error)

ParsePullRequestURL extracts provider, organization, project, repository, and PR ID from a PR URL. Supported formats:

type RemoteURLInfo

type RemoteURLInfo struct {
	ServiceType  globalEntities.ServiceType
	Organization string
	Project      string // Azure DevOps only; empty for GitHub/GitLab
	RepoName     string
}

RemoteURLInfo holds the parsed components of a Git remote URL.

func ParseRemoteURL

func ParseRemoteURL(rawURL string) (*RemoteURLInfo, error)

ParseRemoteURL extracts provider, organization, project, and repository name from a Git remote URL. Supported formats:

type UserConfig

type UserConfig struct {
	Name          string
	Email         string
	SigningKey    string
	SigningFormat string
}

UserConfig holds user-specific git configuration values read from local and global git config. Exported for use by autobump (github.com/rios0rios0/autobump) and autoupdate (github.com/rios0rios0/autoupdate) as the canonical way to read user identity and signing settings before committing.

func ReadUserConfig

func ReadUserConfig(repo *git.Repository) (*UserConfig, error)

ReadUserConfig reads user name, email, signing key, and signing format from the repository's local config, falling back to the global ~/.gitconfig. Exported for use by autobump (github.com/rios0rios0/autobump) and autoupdate (github.com/rios0rios0/autoupdate).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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