plan

package
v0.0.0-...-940c0a0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package plan handles the synchronization plan.

Each synchronization plan is a set of checks and actions to perform on specified paths that will result in the "plugin" repository being updated.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyDirectory

func CopyDirectory(src, dst string) error

CopyDirectory copies the directory src to dst so that after a successful operation the contents of src and dst are equal.

func IsCheckFail

func IsCheckFail(err error) bool

IsCheckFail determines if an error is a check fail error.

Types

type Action

type Action interface {
	// Run performs the action on the specified path.
	Run(string, Setup) error
	// Check runs checks associated with the action
	// before running it.
	Check(string, Setup) error
}

Action runs the defined action.

type ActionConditions

type ActionConditions struct {
	// Conditions are checkers run before executing the
	// action. If any one fails (returns an error), the action
	// itself is not executed.
	Conditions []Check
}

ActionConditions adds condition support to actions.

func (ActionConditions) Check

func (c ActionConditions) Check(path string, setup Setup) error

Check runs the conditions associated with the action and returns the first error (if any).

type ActionSet

type ActionSet struct {
	Paths   []string
	Actions []Action
}

ActionSet is a set of actions along with a set of paths to perform those actions on.

type Check

type Check interface {
	Check(string, Setup) error
}

Check returns an error if the condition fails.

type CheckFail

type CheckFail string

CheckFail is a custom error type used to indicate a check that did not pass (but did not fail due to external causes. Use `IsCheckFail` to check if an error is a check failure.

func CheckFailf

func CheckFailf(msg string, args ...interface{}) CheckFail

CheckFailf creates an error with the specified message string. The error will pass the IsCheckFail filter.

func (CheckFail) Error

func (e CheckFail) Error() string

type FileUnalteredChecker

type FileUnalteredChecker struct {
	Params struct {
		SourceRepo RepoID `json:"compared-to"`
		TargetRepo RepoID `json:"in"`
	}
}

FileUnalteredChecker checks whether the file in Repo is an unaltered version of that same file in ReferenceRepo.

Its purpose is to check that a file has not been changed after forking a repository. It could be an old unaltered version, so the git history of the file is traversed until a matching version is found.

If the repositories in the parameters are not specified, reference will default to the source repository and repo - to the target.

func (FileUnalteredChecker) Check

func (f FileUnalteredChecker) Check(path string, setup Setup) error

Check implements the Checker interface.

type OverwriteDirectoryAction

type OverwriteDirectoryAction struct {
	ActionConditions
	Params struct {
		// Create determines whether the target directory
		// will be created if it does not exist.
		Create bool `json:"create"`
	}
}

OverwriteDirectoryAction is used to completely overwrite directories. If the target directory exists, it will be removed first.

func (OverwriteDirectoryAction) Run

func (a OverwriteDirectoryAction) Run(path string, setup Setup) error

Run implements plan.Action.Run.

type OverwriteFileAction

type OverwriteFileAction struct {
	ActionConditions
	Params struct {
		// Create determines whether the target directory
		// will be created if it does not exist.
		Create bool `json:"create"`
	}
}

OverwriteFileAction is used to overwrite a file.

func (OverwriteFileAction) Run

func (a OverwriteFileAction) Run(path string, setup Setup) error

Run implements plan.Action.Run.

type PathExistsChecker

type PathExistsChecker struct {
	Params struct {
		Repo RepoID
	}
}

PathExistsChecker checks whether the fle or directory with the path exists. If it does not, an error is returned.

func (PathExistsChecker) Check

func (r PathExistsChecker) Check(path string, ctx Setup) error

Check implements the Checker interface.

type Plan

type Plan struct {
	Checks []Check `json:"checks"`
	// Each set of paths has multiple actions associated, each a fallback for the one
	// previous to it.
	Actions []ActionSet
}

Plan defines the plan for synchronizing a target and a source directory.

func (*Plan) Execute

func (p *Plan) Execute(c Setup) error

Execute executes the synchronization plan.

func (*Plan) UnmarshalJSON

func (p *Plan) UnmarshalJSON(raw []byte) error

UnmarshalJSON implements the `json.Unmarshaler` interface.

type RepoID

type RepoID string

RepoID identifies a repository - either plugin or template.

const (
	// SourceRepo is the id of the template repository (source).
	SourceRepo RepoID = "source"
	// TargetRepo is the id of the plugin repository (target).
	TargetRepo RepoID = "target"
)

type RepoIsCleanChecker

type RepoIsCleanChecker struct {
	Params struct {
		Repo RepoID
	}
}

RepoIsCleanChecker checks whether the git repository is clean.

func (RepoIsCleanChecker) Check

func (r RepoIsCleanChecker) Check(_ string, ctx Setup) error

Check implements the Checker interface. The path parameter is ignored because this checker checks the state of a repository.

type RepoSetup

type RepoSetup struct {
	Git  *git.Repository
	Path string
}

RepoSetup contains relevant information about a single repository (either source or target).

func GetRepoSetup

func GetRepoSetup(path string) (RepoSetup, error)

GetRepoSetup returns the repository setup for the specified path.

type Setup

type Setup struct {
	Source         RepoSetup
	Target         RepoSetup
	VerboseLogging bool
}

Setup contains information about both parties in the sync: the plugin repository being updated and the source of the update - the template repo.

func (Setup) GetRepo

func (c Setup) GetRepo(r RepoID) RepoSetup

GetRepo is a helper to get the required repo setup. If the target parameter is not one of "plugin" or "template", the function panics.

func (Setup) LogErrorf

func (c Setup) LogErrorf(tpl string, args ...interface{})

LogErrorf logs the provided error message.

func (Setup) Logf

func (c Setup) Logf(tpl string, args ...interface{})

Logf logs the provided message. If verbose output is not enabled, the message will not be printed.

func (Setup) PathInRepo

func (c Setup) PathInRepo(repo RepoID, path string) string

PathInRepo returns the full path of a file in the specified repository.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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