core

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2023 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultBuilder = func() *Builder {
	var b Builder
	err := yaml.Unmarshal([]byte(config.DefaultBuilder), &b)
	if err != nil {
		panic(err)
	}
	err = b.Validate()
	if err != nil {
		panic(err)
	}
	return &b
}()
View Source
var MuteJob bool

Functions

func ConvertToGroups added in v0.1.0

func ConvertToGroups(repos []*Repository) []string

func CreateTemplate added in v0.5.0

func CreateTemplate(name string, files []*TemplateFile) error

func DeleteSecret added in v0.6.0

func DeleteSecret(key string) error

func DeleteTemplate added in v0.5.0

func DeleteTemplate(name string) error

func GetJobPath added in v0.2.0

func GetJobPath(name string) (string, error)

func GetSecret added in v0.6.0

func GetSecret(key string, allowCreate bool) (string, error)

func GetTemplate added in v0.5.0

func GetTemplate(name string) (string, error)

func ListBuilderNames added in v0.2.0

func ListBuilderNames() ([]string, error)

func ListJobNames added in v0.2.0

func ListJobNames() ([]string, error)

func ListRemoteNames

func ListRemoteNames() ([]string, error)

func ListTemplates added in v0.5.0

func ListTemplates() ([]string, error)

func ListWorkflowNames added in v0.2.0

func ListWorkflowNames() ([]string, error)

func SetSecret added in v0.6.0

func SetSecret(key string) (string, error)

func SortRepositories added in v0.3.0

func SortRepositories(repos []*Repository)

func SplitGroup

func SplitGroup(name string) (string, string)

func UseTemplate added in v0.5.0

func UseTemplate(name, dst string) error

Types

type BuildFile added in v0.2.0

type BuildFile struct {
	Name    string `yaml:"name" validate:"required"`
	Content string `yaml:"content"`
	From    string `yaml:"from"`
}

type Builder added in v0.2.0

type Builder struct {
	Create    []*Job       `yaml:"create" validate:"dive"`
	Templates []string     `yaml:"templates"`
	Files     []*BuildFile `yaml:"files" validate:"unique=Name,dive"`
	Init      []*Job       `yaml:"init" validate:"dive"`
	// contains filtered or unexported fields
}

func GetBuilder added in v0.2.0

func GetBuilder(name string) (*Builder, error)

func (*Builder) Execute added in v0.2.0

func (b *Builder) Execute() error

func (*Builder) Prepare added in v0.2.0

func (b *Builder) Prepare(remote *Remote, repo *Repository) error

func (*Builder) Validate added in v0.2.0

func (b *Builder) Validate() error

type Job added in v0.2.0

type Job struct {
	Name string `yaml:"name" validate:"required"`
	Run  string `yaml:"run"`

	RequireEnv []string `yaml:"require_env"`
}

func (*Job) Cmd added in v0.2.0

func (job *Job) Cmd(root string, env osutil.Env, out *bytes.Buffer) (*exec.Cmd, error)

func (*Job) Execute added in v0.2.0

func (job *Job) Execute(root string, env osutil.Env) error

func (*Job) Say added in v0.2.0

func (job *Job) Say(msg string, args ...any)

func (*Job) Skip added in v0.2.0

func (job *Job) Skip(env osutil.Env) (string, bool)

type JobError added in v0.2.0

type JobError struct {
	Name string
	Path string
	Err  error
	// contains filtered or unexported fields
}

func (*JobError) Error added in v0.2.0

func (err *JobError) Error() string

func (*JobError) Out added in v0.2.0

func (err *JobError) Out() string

type JumpKeywordStorage added in v0.3.0

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

func NewJumpKeywordStorage added in v0.3.0

func NewJumpKeywordStorage() (*JumpKeywordStorage, error)

func (*JumpKeywordStorage) Add added in v0.3.0

func (s *JumpKeywordStorage) Add(kw string)

func (*JumpKeywordStorage) Close added in v0.3.0

func (s *JumpKeywordStorage) Close() error

func (*JumpKeywordStorage) List added in v0.3.0

func (s *JumpKeywordStorage) List() []string

type Remote

type Remote struct {
	Name string `toml:"-"`

	Host string `toml:"host" validate:"required"`

	Protocol string `toml:"protocol" validate:"enum_protocol"`

	User  string `toml:"user" validate:"required"`
	Email string `toml:"email" validate:"email"`

	Provider    string `toml:"provider" validate:"enum_provider"`
	Token       string `toml:"token"`
	TokenSecret bool   `toml:"token_secret"`
	API         string `toml:"api" validate:"omitempty,uri"`

	Groups []*RemoteGroup `toml:"groups" validate:"unique=Name,dive"`
}

func GetRemote

func GetRemote(name string) (*Remote, error)

func (*Remote) GetCloneURL

func (r *Remote) GetCloneURL(repo *Repository) (string, error)

func (*Remote) GetUserEmail

func (r *Remote) GetUserEmail(repo *Repository) (string, string)

type RemoteGroup

type RemoteGroup struct {
	Name string `toml:"name" validate:"required"`

	Protocol string `toml:"protocol" validate:"omitempty,enum_protocol"`

	User  string `toml:"user"`
	Email string `toml:"email" validate:"omitempty,email"`
}

type Repository

type Repository struct {
	Path string

	Name   string
	Remote string

	LastAccess int64
	Access     uint64
	// contains filtered or unexported fields
}

func AttachRepository

func AttachRepository(remote *Remote, name, path string) (*Repository, error)

func DiscoverLocalRepositories added in v0.2.0

func DiscoverLocalRepositories(rootDir string) ([]*Repository, error)

func NewLocalRepository added in v0.2.0

func NewLocalRepository(rootDir, name string) (*Repository, error)

func SelectLocalRepository added in v0.6.0

func SelectLocalRepository(rootDir, name string) (*Repository, error)

func WorkspaceRepository added in v0.2.0

func WorkspaceRepository(remote *Remote, name string) (*Repository, error)

func (*Repository) Base

func (repo *Repository) Base() string

func (*Repository) Dir added in v0.2.0

func (repo *Repository) Dir() string

func (*Repository) EnsureDir added in v0.2.0

func (repo *Repository) EnsureDir() (string, error)

func (*Repository) FullName

func (repo *Repository) FullName() string

func (*Repository) Group

func (repo *Repository) Group() string

func (*Repository) MarkAccess added in v0.3.0

func (repo *Repository) MarkAccess()

func (*Repository) Score added in v0.3.0

func (repo *Repository) Score() uint64

calculate score for a repo. The algorithm comes from:

https://github.com/ajeetdsouza/zoxide/wiki/Algorithm

Each repo is assigned a access count, starting with 1 the first time it is accessed. Every repo access increases the access count by 1. When a query is made, we calculate score based on the last time the repo was accessed:

  • Last access within the last hour: score = access * 16
  • Last access within the last day: score = access * 8
  • Last access within the last week: score = access * 2
  • Last access more that one week: score = access

func (*Repository) SetEnv added in v0.2.0

func (repo *Repository) SetEnv(remote *Remote, env osutil.Env) error

type RepositoryStorage

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

func NewRepositoryStorage

func NewRepositoryStorage() (*RepositoryStorage, error)

func (*RepositoryStorage) Add

func (s *RepositoryStorage) Add(repo *Repository) error

func (*RepositoryStorage) Close

func (s *RepositoryStorage) Close() error

func (*RepositoryStorage) Delete

func (s *RepositoryStorage) Delete(repo *Repository)

func (*RepositoryStorage) DeleteAll added in v0.5.0

func (s *RepositoryStorage) DeleteAll(repo *Repository) error

func (*RepositoryStorage) GetByName

func (s *RepositoryStorage) GetByName(remote, name string) *Repository

func (*RepositoryStorage) GetByPath

func (s *RepositoryStorage) GetByPath(path string) (*Repository, error)

func (*RepositoryStorage) GetCurrent added in v0.5.0

func (s *RepositoryStorage) GetCurrent() (*Repository, error)

func (*RepositoryStorage) GetLocal added in v0.5.0

func (s *RepositoryStorage) GetLocal(remote *Remote, name string) (*Repository, error)

func (*RepositoryStorage) List

func (s *RepositoryStorage) List(remote string) []*Repository

func (*RepositoryStorage) ReadOnly

func (s *RepositoryStorage) ReadOnly()

type Secret added in v0.6.0

type Secret struct {
	Value string `yaml:"value"`
	Salt  string `yaml:"salt"`
}

type Secrets added in v0.6.0

type Secrets map[string]*Secret

type TemplateFile added in v0.5.0

type TemplateFile struct {
	Name string

	Read io.ReadCloser
	Mode os.FileMode
}

func FindTemplateFiles added in v0.5.0

func FindTemplateFiles(root string) ([]*TemplateFile, error)

func (*TemplateFile) WriteTo added in v0.5.0

func (file *TemplateFile) WriteTo(dstRoot string) error

type Workflow added in v0.2.0

type Workflow struct {
	Select *WorkflowSelect `yaml:"select"`

	Jobs []*Job `yaml:"jobs" validate:"required,dive"`
}

func GetWorkflow added in v0.2.0

func GetWorkflow(name string) (*Workflow, error)

type WorkflowMatchItem added in v0.2.0

type WorkflowMatchItem struct {
	Path string
	Env  osutil.Env

	Repo *Repository
}

type WorkflowSelect added in v0.2.0

type WorkflowSelect struct {
	Repos []string `yaml:"repos"`
	Dirs  []string `yaml:"dirs"`
}

func (*WorkflowSelect) Match added in v0.2.0

Jump to

Keyboard shortcuts

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