utils

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: Apache-2.0 Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	ProjectName        = "synchro"
	PackageName        = "github.com/jasondellaluce/" + ProjectName
	ProjectRepo        = "https://" + PackageName
	ProjectDescription = "Next-gen tooling for keeping in sync private forks of open source repositories"
)

Variables

View Source
var ErrSeqBreakout = errors.New("sequence iteration breakout")

ErrSeqBreakout represents the intentional breakout from a sequence iteration operation.

View Source
var (
	ProjectVersion = "0.0.0"
)

Functions

func CollectSequence

func CollectSequence[T interface{}](it Sequence[T]) ([]*T, error)

CollectSequence takes a sequence and iterates over all its elements up until all are consumed, collecting them in a slice. Returns a non-nil error in case of failure, and nil otherwise.

func ConsumeSequence

func ConsumeSequence[T interface{}](it Sequence[T], consume func(*T) error) error

ConsumeSequence takes a sequence and iterates over all its elements up until all are consumed, and invokes a consumption callbacks on them. If the consumer function returns a non-nil error, the iterations stops and th error is returned. Returns a non-nil error in case of failure, and nil otherwise.

func GetGithubClient

func GetGithubClient() *github.Client

func ReverseSlice

func ReverseSlice[S ~[]E, E any](s S)

func WithTempGitRemote

func WithTempGitRemote(git GitHelper, remote, url string, f func() error) error

func WithTempLocalBranch

func WithTempLocalBranch(git GitHelper, localBranch, remote, remoteBranch string, f func() (bool, error)) error

Types

type GitHelper

type GitHelper interface {
	// Essentials
	// Pull(remote, branch string)
	// Push(remote, branch string)
	// Reset()
	// ResetHard()
	// Add(file string)
	// AddAll()
	// Commit(msg string)
	// Checkout(branch string)
	// CheckoutRemote(branch string, remoteBranch string)
	// AddRemote(remote string)
	// RemoveRemote(remote string)
	// FetchRemote(remote string)
	// FetchPrune(remote string)
	// CherryPick(commit string)
	// CherryPickContinue()
	// CherryPickAbort()
	// DeleteBranch() string
	Do(commands ...string) error
	DoOutput(commands ...string) (string, error)
	HasLocalChanges(filters ...func(string) bool) (bool, error)
	ListUnmergedFiles() ([]string, error)
	GetCurrentBranch() (string, error)
	GetRemoteDefaultBranch(remote string) (string, error)
	BranchExistsInRemote(remote, branch string) (bool, error)
	GetRepoRootDir() (string, error)
	GetRemotes() (map[string]string, error)
	TagExists(tag string) (bool, error)
}

func NewGitHelper

func NewGitHelper() GitHelper

type GithubClientListFunc

type GithubClientListFunc[T interface{}] func(*github.ListOptions) ([]*T, *github.Response, error)

GithubClientListFunc is a generic functional wrapper for "list"-type API invocations of a GitHub client for which the list options are provided.

type Sequence

type Sequence[T interface{}] interface {
	//
	// Next returns the next element in the iterator, or nil in case the
	// sequence has no more elements.
	Next() *T
	//
	// Returns a non-nil error in case of failures when creating or using
	// the iterator, or nil otherwise.
	Error() error
}

Sequence represents an iterator for sequences that can be used for loop over all the elements available one by one in a stateful manner, up until the sequence is completely consumed.

func NewFilteredSequence

func NewFilteredSequence[T interface{}](it Sequence[T], filter func(*T) bool) Sequence[T]

NewFilteredSequence returns a new sequence that filters the elements of another sequence with a filtering function. The new sequence contains all elements for which the filtering function returns true.

func NewGithubSequence

func NewGithubSequence[T interface{}](f GithubClientListFunc[T]) Sequence[T]

NewGithubSequence creates a new sequence starting from a GithubClientListFunc

Jump to

Keyboard shortcuts

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