excav

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRepositoryNames

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

func RegisterListener

func RegisterListener(listener api.EventListener)

Types

type Bulk

type Bulk struct {
	ID string
	// contains filtered or unexported fields
}

func NewBulk

func NewBulk(cfg *Configuration) *Bulk

funcion create new empty bulk, folder of this bulk and set it as current.

func OpenBulk

func OpenBulk(cfg *Configuration) (*Bulk, error)

func (*Bulk) AddRepositories

func (b *Bulk) AddRepositories(repos []*Repository, globalParams Params, commitMsg string, branch string)

func (*Bulk) AddRepository

func (b *Bulk) AddRepository(repo *Repository, globalParams Params, mergeRequestDescr string, branch string)

func (*Bulk) Apply

func (b *Bulk) Apply(repoName string, p *Patch, message string)

Apply patch to only given repository in bulk

func (*Bulk) Close

func (b *Bulk) Close() error

Close save the state

func (*Bulk) Discard

func (b *Bulk) Discard() error

Discarding the Bulk. That means:

  • delete bulk dir content
  • delette branches if they're created

func (*Bulk) ForEach

func (b *Bulk) ForEach(f func(ctx *PatchContext) error) error

ForEach iterate over contexts and call f function for every context. If f returns some error (not null), the iteration immediately stop and forward this error to you

func (*Bulk) Get

func (b *Bulk) Get(repoName string) *PatchContext

func (*Bulk) Len

func (b *Bulk) Len() int

Len returns you number of patch contexts

func (*Bulk) PushAll

func (b *Bulk) PushAll()

type Configuration

type Configuration struct {
	// path to workspace where are repositories cloned. Default is {currentdir}/.excav
	WorkspaceDir string `yaml:"workspace"`

	// The GitLab host (e.g. https://gitlab.com)
	GitLabHost string `yaml:"gitlab"`

	// Private access token which is generated by GitLab.
	// see https://gitlab.com/profile/personal_access_tokens
	GitLabToken string `yaml:"gitlab_token"`

	// The GitHub host (e.g. https://github.com)
	GitHubHost string `yaml:"github"`

	// The GitHub API host (e.g. https://api.github.com). Usually API is available in
	// different hostname starting with api.*
	GitHubApiHost string `yaml:"github_api"`

	// User for GitHub
	GitHubUser string `yaml:"github_user"`

	// Personal access token which is generated by GitHub
	// see https://github.com/settings/tokens
	GitHubToken string `yaml:"github_token"`
}

Configuration is loaded from ~/.config/excav/config.yaml file

func LoadConfiguration

func LoadConfiguration() (*Configuration, error)

Default loading of configuration. The order of loading is:

- first we try load config.yaml in current working directory - then try load config.yaml from `{USER_HOME}/.config/excav/config.yaml' - (not implemented) load from env. variables (TODO)

func ReadYamlConfig

func ReadYamlConfig(configFile string) (*Configuration, error)

func TestConfiguration

func TestConfiguration() (*Configuration, error)

create configuration used by tests. This configuration relly on tetmporary workspace;

func (*Configuration) GetCurrentBulk

func (cfg *Configuration) GetCurrentBulk() string

function returns you ID of current bulk The current bulk is written in ${WORKSPACE}/currert file

func (*Configuration) GetCurrentBulkDir

func (cfg *Configuration) GetCurrentBulkDir() Directory

function returns you directory of current bulk

func (*Configuration) GetProviderApiHost

func (cfg *Configuration) GetProviderApiHost() string

func (*Configuration) GetProviderHost

func (cfg *Configuration) GetProviderHost() string

func (*Configuration) GetProviderToken

func (cfg *Configuration) GetProviderToken() string

func (*Configuration) GetProviderType

func (cfg *Configuration) GetProviderType() string

func (*Configuration) GetProviderUser added in v0.4.0

func (cfg *Configuration) GetProviderUser() string

func (*Configuration) SaveToYaml

func (cfg *Configuration) SaveToYaml(file string) error

SaveToYaml save the config into given file. If file exists, it will be overridden. Ensure the parent directories exists, otherwise saving fail.

func (*Configuration) SetCurrentBulk

func (cfg *Configuration) SetCurrentBulk(bulkID string) error

function set defaul bulk. That means exav will work with this bulk by default.

The bulk ID is written into {WORKSPACE}/current file.

func (*Configuration) String

func (cfg *Configuration) String() string

type Directory

type Directory string

Directory represents path to directory and provide basic operations for directories

func CurrentDirectory

func CurrentDirectory() Directory

func TempDirectory

func TempDirectory() Directory

func (Directory) Clear

func (d Directory) Clear()

The function removes all content but directory stay untouched. This function is bit different as Remove

func (Directory) File

func (d Directory) File(name string) string

returns absolute path to file in directory. The file may not exist, it's just join of names

func (Directory) FindBySuffix

func (d Directory) FindBySuffix(suffix string, found func(string))

FindBySuffix go through directory and call 'found' function for every file that suffix is matching.

Any low-level error is ignored and function continue without breaking.

func (Directory) IsEmpty

func (d Directory) IsEmpty() bool

func (Directory) IsNotExist

func (d Directory) IsNotExist() bool

func (Directory) IsNotSet

func (d Directory) IsNotSet() bool

func (Directory) Mkdir

func (d Directory) Mkdir()

Ensure the directory is present in your system.

func (Directory) Remove

func (d Directory) Remove()

Remove the directory and all subdirectories and files recursively

func (Directory) String

func (d Directory) String() string

func (Directory) Subdir

func (d Directory) Subdir(name string) Directory

returns absolute path of subdirectory in this directory. The directory may not exist, it's just join of names.

type Dispatcher

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

Dispatcher is responsible for delivery events to registered listeners. The code is sending events via Notify and reacting on events by implementing EventListener.

func (*Dispatcher) Notify

func (d *Dispatcher) Notify(ev api.Event)

Send event

type Inventory

type Inventory struct {
	// don't use this attribute directly. It's public only because HCL parsing
	XRepositories []*Repository `yaml:"repositories"`
}

func OpenInventory

func OpenInventory(file string) (*Inventory, error)

OpenInventory load the inventory YAML file. If file is empty string, the default value will be used which is '{currentdir}/inventory.yaml'.

Example of the file is in testdata/inventory.yaml

func (*Inventory) Get

func (inv *Inventory) Get(repoName string) *Repository

GetByPath returns repo or null

func (*Inventory) GetAll

func (inv *Inventory) GetAll() []*Repository

func (*Inventory) GetByTags

func (inv *Inventory) GetByTags(tags ...string) []*Repository

GetByTags returns you list of filtered repositories they're matching given tag or all given tags. If tags is empty, the function returns all tags

type NewBulkOpts

type NewBulkOpts struct {
	Repos        []*Repository
	Branch       string
	Description  string
	GlobalParams Params
}

type Params

type Params map[string]string

parameters they're passed into every task. They're used for parametrized tasks like 'append-template' etc. The parameters can be defined as arguments during apply (see excav apply --h)

func MergeParams

func MergeParams(params ...Params) Params

merges multiple parameter collections into one. If the parameter is obtained in multiple collections, the value of last collection in function is used. Collections have priorrity from lowest to high.

func NewParams

func NewParams() Params

create new empty collection of parameters

func StringSliceToParams

func StringSliceToParams(params []string) Params

ParamsAsStringSlice consume parameters as array of 'KEY=VALUE' strings and parse it to Params structure - which is map btw. The 'KEY=VALUE' is used mainly for parameters given as cli argument.

func (Params) ToMap

func (p Params) ToMap() map[string]interface{}

ToMap convert parameters into map of interfaces. This is needed mainly for patch, because patch is expecting parameters as map of interfaces.

type Patch

type Patch struct {
	Params   Params
	Tasks    map[string]api.Task
	Metadata map[string]*api.TaskMetadata
	// contains filtered or unexported fields
}

Patch contains one or more tasks they're applied to some directory.

func OpenPatch

func OpenPatch(dir string) (*Patch, error)

Open and returns patch. It's read and parse 'patch.yaml' for given directory.

func (*Patch) Apply

func (p *Patch) Apply(repoDir string, params map[string]interface{}) error

Apply patch to directory(absolute path), where is repository cloned. If some task failed, the apply terminate process with error of task.

This function also emmit events like api.TaskStarted and api.TaskEnd into global dispatcher.

type PatchContext

type PatchContext struct {
	RepoName string `yaml:"repo_name"`

	// from which branch is new branch for patch created, by default it's 'main'
	DefaultBranch string `yaml:"default_branch"`

	// this is a created branch (from default) where is patch applied
	Branch string `yaml:"branch"`

	Phase PhaseType `yaml:"phase"`

	// Description is provided by user fist time, when bulk is created
	// (see CreateNew)
	Description string `yaml:"descr"`

	// This field is populated after changes are pushed (see bulk Push())
	MergeRequestURL string `yaml:"merge_request"`

	// This field indicates error state. You can check the state
	// via IsError func.
	ErrorMsg string `yaml:"error_msg"`

	// This field holds all parameters and values for patch
	AllParams Params `yaml:"params"`
	// contains filtered or unexported fields
}

PatchContext hold the repository and metadata related to current patching. When Bulk represent the group of repositories you apply patch, the PatchContext represent one repository you're currently patching

func (*PatchContext) Apply

func (ctx *PatchContext) Apply(p *Patch, message string) error

apply the given p to repository and commit the changes.

func (*PatchContext) Diff

func (ctx *PatchContext) Diff() string

func (*PatchContext) IsError

func (ctx *PatchContext) IsError() bool

func (*PatchContext) Push

func (ctx *PatchContext) Push() error

type PhaseType

type PhaseType string
const (
	PhaseNew     PhaseType = ""
	PhaseApplied PhaseType = "applied"
	PhasePushed  PhaseType = "pushed"
)

type Repository

type Repository struct {
	// Path of repository is in GitLab `/fodler/folder/repo` or in GitLab `/org/repo`
	Name string `yaml:"repository"`

	// not every repository have 'main' as default branch. Some legacy repos
	// might have 'master' as default branch
	DefaultBranch string `yaml:"default_branch"`

	// tags help you identify and select list of
	// repositories
	Tags []string `yaml:"tags,flow"`

	// repository might have some parameters they are
	// passed into templates
	RepoParams Params `yaml:"params,omitempty"`
}

func (*Repository) GetName

func (r *Repository) GetName() string

get the trimmed name ready to use. We're not using direct access, because Name might have weird characters

func (*Repository) HasTag

func (repo *Repository) HasTag(tag string) bool

func (*Repository) HasTags

func (repo *Repository) HasTags(tags ...string) bool

Directories

Path Synopsis
put

Jump to

Keyboard shortcuts

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