git

package
v0.36.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxRetries = 4               // 5 total attempts (0-4)
	DefaultBaseDelay  = 2 * time.Second // Base delay of 2 seconds
)

DefaultRetryConfig provides sensible defaults for GitHub API retries

View Source
const MainBranch = "main"
View Source
const OriginRemote = "origin"

Variables

View Source
var (
	ErrLocalChangesIsPresent = errors.New("local changes are present")
)

Functions

func CreateGitHubPR added in v0.25.2

func CreateGitHubPR(client *github.Client, title string, body string, branchName string, repoName string, organization string, dryRun bool) (*github.PullRequest, error)

func GetLocalRepoOrgAndName added in v0.27.1

func GetLocalRepoOrgAndName(localpath string) (string, string, error)

func IsGitHub404Error added in v0.35.1

func IsGitHub404Error(err error) bool

IsGitHub404Error checks if an error is likely a GitHub 404 error or Git repository not ready error

func IsGitHubPropagationError added in v0.35.1

func IsGitHubPropagationError(err error) bool

IsGitHubPropagationError checks if an error could be due to propagation delays (404 or 403 in repository operations)

func RetryGitHubAPI added in v0.35.1

func RetryGitHubAPI[T any](operation func() (T, *github.Response, error), maxRetries int, baseDelay time.Duration) (T, *github.Response, error)

RetryGitHubAPI retries a GitHub API operation with exponential backoff. This is specifically designed to handle propagation delays after repository creation.

func RetryGitHubOperation added in v0.35.1

func RetryGitHubOperation(operation func() error, maxRetries int, baseDelay time.Duration) error

RetryGitHubOperation retries a GitHub operation that returns only an error with exponential backoff.

Types

type AuthMethod

type AuthMethod interface {
	// contains filtered or unexported methods
}

func UrlTokenAuthMethod

func UrlTokenAuthMethod(token string) AuthMethod

type CheckoutOp

type CheckoutOp struct {
	BranchName      string
	CreateIfMissing bool
}

type CloneOp

type CloneOp struct {
	URL        string
	TargetPath string
	Auth       AuthMethod
}

type CommitOp

type CommitOp struct {
	Message    string
	AllowEmpty bool
	DryRun     bool
}

type GithubRepoFullId

type GithubRepoFullId struct {
	RepositoryFullname
	// contains filtered or unexported fields
}

func NewGithubRepoFullId

func NewGithubRepoFullId(repository *github.Repository) GithubRepoFullId

func (GithubRepoFullId) Id

func (i GithubRepoFullId) Id() int

type LocalRepository

type LocalRepository struct {
	DryRun bool
	// contains filtered or unexported fields
}

func CloneToLocalRepository

func CloneToLocalRepository(op CloneOp) (*LocalRepository, error)

func InitLocalRepository

func InitLocalRepository(path string, dryRun bool) (*LocalRepository, error)

func OpenAndResetRepositoryState

func OpenAndResetRepositoryState(path string, dryRun bool) (*LocalRepository, error)

func OpenLocalRepository

func OpenLocalRepository(path string, dryRun bool) (*LocalRepository, error)

func (*LocalRepository) AddAll

func (localRepo *LocalRepository) AddAll() error

func (*LocalRepository) AddFiles

func (localRepo *LocalRepository) AddFiles(paths ...string) error

func (*LocalRepository) CheckoutBranch

func (localRepo *LocalRepository) CheckoutBranch(op *CheckoutOp) error

func (*LocalRepository) Commit

func (localRepo *LocalRepository) Commit(op *CommitOp) error

func (*LocalRepository) CurrentBranch

func (localRepo *LocalRepository) CurrentBranch() (string, error)

func (*LocalRepository) GetRemoteRepoName added in v0.23.0

func (localRepo *LocalRepository) GetRemoteRepoName() (string, error)

func (*LocalRepository) HeadShortCommitHash added in v0.23.0

func (localRepo *LocalRepository) HeadShortCommitHash() (string, error)

HeadShortCommitHash returns short commit hash, currently no support for this feature in go-git lib (some discussions: https://github.com/src-d/go-git/issues/602)

func (*LocalRepository) IsLocalChangesPresent

func (localRepo *LocalRepository) IsLocalChangesPresent() (bool, error)

func (*LocalRepository) Path

func (localRepo *LocalRepository) Path() string

func (*LocalRepository) Pull

func (localRepo *LocalRepository) Pull(auth AuthMethod) (*PullResult, error)

func (*LocalRepository) Push

func (localRepo *LocalRepository) Push(op PushOp) error

func (*LocalRepository) Repository

func (localRepo *LocalRepository) Repository() *git.Repository

func (*LocalRepository) ResetState

func (localRepo *LocalRepository) ResetState() error

func (*LocalRepository) SetRemote

func (localRepo *LocalRepository) SetRemote(url string) error

func (*LocalRepository) Worktree

func (localRepo *LocalRepository) Worktree() *git.Worktree

type PullResult

type PullResult struct {
	IsUpdated bool
}

type PushOp added in v0.25.0

type PushOp struct {
	Auth       AuthMethod
	BranchName string
}

type RepositoryCloneErr added in v0.23.0

type RepositoryCloneErr struct {
	RepositoryErr
}

type RepositoryErr added in v0.23.0

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

func (RepositoryErr) Error added in v0.23.0

func (r RepositoryErr) Error() string

type RepositoryFullname

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

func DeriveRepositoryFullname

func DeriveRepositoryFullname(localRepo *LocalRepository) (RepositoryFullname, error)

func DeriveRepositoryFullnameFromUrl

func DeriveRepositoryFullnameFromUrl(githubRepoUrl string) (RepositoryFullname, error)

func (RepositoryFullname) ActionsHttpUrl

func (n RepositoryFullname) ActionsHttpUrl() string

func (RepositoryFullname) HttpUrl

func (n RepositoryFullname) HttpUrl() string

func (RepositoryFullname) Name

func (n RepositoryFullname) Name() string

func (RepositoryFullname) Organization

func (n RepositoryFullname) Organization() string

func (RepositoryFullname) String

func (n RepositoryFullname) String() string

Jump to

Keyboard shortcuts

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