domain

package
v0.2.0-rc2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidArgument = errors.New("invalid argument")

ErrInvalidArgument is an error that indicates that a particular field is invalid.

View Source
var ErrKeyNotFound = errors.New("key not found")

ErrKeyNotFound is an error that indicates that a particular key was not found.

Functions

This section is empty.

Types

type CleanupContext

type CleanupContext struct {
	Repository *GitRepository
	ValueStore ValueStore
	// contains filtered or unexported fields
}

type CleanupService

type CleanupService struct{}

func NewCleanupService

func NewCleanupService() *CleanupService

func (*CleanupService) CleanupUnwantedFiles

func (s *CleanupService) CleanupUnwantedFiles(ctx CleanupContext) error

type Color

type Color string

Color is a 6-digit uppercase hexadecimal string value with '#' prefix

func (Color) CheckValue

func (c Color) CheckValue() error

func (Color) String

func (c Color) String() string

type CommitOptions

type CommitOptions struct {
	Message string
	Amend   bool
}

type GitRepository

type GitRepository struct {
	RootDir     Path
	URL         *GitURL
	PullRequest *PullRequest
	Labels      LabelSet

	CommitBranch  string
	DefaultBranch string
}

func NewGitRepository

func NewGitRepository(u *GitURL, root Path) *GitRepository

func (*GitRepository) SetLabels

func (r *GitRepository) SetLabels(labels LabelSet) error

type GitRepositoryStore

type GitRepositoryStore interface {
	FetchGitRepositories() ([]*GitRepository, error)

	Clone(repository *GitRepository) error
	Checkout(repository *GitRepository) error
	Fetch(repository *GitRepository) error
	Reset(repository *GitRepository) error
	Pull(repository *GitRepository) error

	Add(repository *GitRepository) error
	Commit(repository *GitRepository, options CommitOptions) error
	Diff(repository *GitRepository) (string, error)

	Push(repository *GitRepository, options PushOptions) error
}

type GitURL

type GitURL url.URL

GitURL is the same as url.URL but with additional helper methods.

func FromURL

func FromURL(url *url.URL) *GitURL

FromURL converts the given url.URL into a GitURL.

func (*GitURL) AsURL

func (u *GitURL) AsURL() *url.URL

func (*GitURL) GetFullName

func (u *GitURL) GetFullName() string

GetFullName returns the hostname (or host:port) joined by GetNamespace and GetRepositoryName delimited by slashes.

func (*GitURL) GetNamespace

func (u *GitURL) GetNamespace() string

GetNamespace returns the middle element(s) of the Git URL. Depending on the Git hosting service, this name may contain multiple slashes. Any leading "/" is removed.

func (*GitURL) GetRepositoryName

func (u *GitURL) GetRepositoryName() string

GetRepositoryName returns the last element of the Git URL. Strips the name from any .git extensions in the URL.

func (*GitURL) Redacted

func (u *GitURL) Redacted() string

Redacted returns the same as url.URL:Redacted().

func (*GitURL) String

func (u *GitURL) String() string

String returns the same as url.URL:String().

type Label

type Label struct {
	Name        string
	Description string
	// contains filtered or unexported fields
}

func (Label) GetColor

func (l Label) GetColor() Color

func (Label) IsEqualTo

func (l Label) IsEqualTo(label Label) bool

IsEqualTo returns true if all properties of Label are equal.

func (Label) IsSameAs

func (l Label) IsSameAs(label Label) bool

IsSameAs returns true if each Label.Name is equal.

func (*Label) SetColor

func (l *Label) SetColor(color Color) error

type LabelSet

type LabelSet []Label

func (LabelSet) CheckForDuplicates

func (s LabelSet) CheckForDuplicates() error

func (LabelSet) CheckForEmptyLabelNames

func (s LabelSet) CheckForEmptyLabelNames() error

func (LabelSet) FindLabelByName

func (s LabelSet) FindLabelByName(label string) (Label, bool)

func (LabelSet) Merge

func (s LabelSet) Merge(other LabelSet) LabelSet

Merge returns a new copy of LabelSet that contains the Label from other if they are missing in the original slice, and replaces existing ones. A label to replace is determined by equality of LabelSet.FindLabelByName.

No validation checks are performed. The original order is not preserved. Duplicates are removed from the result.

func (LabelSet) Without

func (s LabelSet) Without(other LabelSet) LabelSet

Without returns a new LabelSet that contain only the labels that do not exist in other set. A label is not included in the result if the name matches.

No validation checks are performed. The original order is preserved.

type LabelStore

type LabelStore interface {
	FetchLabelsForRepository(url *GitURL) (LabelSet, error)
	EnsureLabelsForRepository(url *GitURL, labels LabelSet) error
	RemoveLabelsFromRepository(url *GitURL, labels LabelSet) error
}

type Path

type Path string

func NewFilePath

func NewFilePath(elems ...string) Path

func NewPath

func NewPath(elems ...string) Path

func (Path) Delete

func (p Path) Delete()

Delete removes the path (and possibly all children if it's a directory), ignoring any errors. If you need error handling, use os.RemoveAll directly.

func (Path) DirExists

func (p Path) DirExists() bool

DirExists returns true if the path exists in the local file system and is a directory.

func (Path) Exists

func (p Path) Exists() bool

Exists returns true if the path exists in the local file system.

func (Path) FileExists

func (p Path) FileExists() bool

FileExists returns true if the path exists in the local file system and is a file.

func (Path) Join

func (p Path) Join(elems ...Path) Path

Join takes this Path as root and makes a new Path with given elements.

func (Path) String

func (p Path) String() string

String returns a string representation of itself.

type Permissions

type Permissions fs.FileMode

func (Permissions) FileMode

func (p Permissions) FileMode() fs.FileMode

type PullRequest

type PullRequest struct {
	CommitBranch string
	BaseBranch   string
	// contains filtered or unexported fields
}

func NewPullRequest

func NewPullRequest(
	number *PullRequestNumber, title, body, commitBranch, baseBranch string,
	labels LabelSet,
) (*PullRequest, error)

func (*PullRequest) AttachLabels

func (pr *PullRequest) AttachLabels(labels LabelSet) error

func (*PullRequest) ChangeDescription

func (pr *PullRequest) ChangeDescription(title, body string) error

func (*PullRequest) GetBody

func (pr *PullRequest) GetBody() string

func (*PullRequest) GetLabels

func (pr *PullRequest) GetLabels() LabelSet

func (*PullRequest) GetNumber

func (pr *PullRequest) GetNumber() *PullRequestNumber

func (*PullRequest) GetTitle

func (pr *PullRequest) GetTitle() string

func (*PullRequest) SetNumber

func (pr *PullRequest) SetNumber(nr *PullRequestNumber) error

type PullRequestNumber

type PullRequestNumber int

func NewPullRequestNumber

func NewPullRequestNumber(nr *int) *PullRequestNumber

func (*PullRequestNumber) Int

func (nr *PullRequestNumber) Int() *int

func (PullRequestNumber) String

func (nr PullRequestNumber) String() string

type PullRequestStore

type PullRequestStore interface {
	// FindMatchingPullRequest returns the PullRequest that has the same branch as GitRepository.CommitBranch.
	// If not found, it returns nil without error.
	FindMatchingPullRequest(repository *GitRepository) (*PullRequest, error)

	// EnsurePullRequest creates or updates the GitRepository.PullRequest in the repository.
	//  * This operation does not alter any properties of existing labels.
	//  * Existing labels are left untouched, but any extraneous labels are removed.
	//  * Title and Body are updated.
	//  * Existing Commit and Base branches are left untouched.
	//
	// The first error encountered aborts the operation.
	EnsurePullRequest(repository *GitRepository) error
}

type PushOptions

type PushOptions struct {
	Force bool
}

type RenderContext

type RenderContext struct {
	Repository    *GitRepository
	ValueStore    ValueStore
	TemplateStore TemplateStore
	Engine        TemplateEngine
	// contains filtered or unexported fields
}

type RenderResult

type RenderResult string

func (RenderResult) WriteToFile

func (r RenderResult) WriteToFile(path Path, permissions Permissions) error

type RenderService

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

func NewRenderService

func NewRenderService(analyticsFactory RenderServiceInstrumentationFactory) *RenderService

func (*RenderService) RenderTemplates

func (s *RenderService) RenderTemplates(ctx RenderContext) error

type RenderServiceInstrumentation

type RenderServiceInstrumentation interface {
	// FetchedTemplatesFromStore logs a message indicating that fetching templates from TemplateStore was successful, but only if fetchErr is nil.
	// Returns fetchErr unmodified for method chaining.
	FetchedTemplatesFromStore(fetchErr error) error
	// FetchedValuesForTemplate logs a message indicating that fetching Values from ValueStore was successful but only if fetchErr is nil.
	// Returns fetchErr unmodified for method chaining.
	FetchedValuesForTemplate(fetchErr error, template *Template) error
	// AttemptingToRenderTemplate logs a message indicating that the actual rendering is about to begin.
	AttemptingToRenderTemplate(template *Template)
	WrittenRenderResultToFile(template *Template, targetPath Path, writeErr error) error
}

type RenderServiceInstrumentationFactory

type RenderServiceInstrumentationFactory interface {
	// NewRenderServiceInstrumentation creates a new RenderServiceInstrumentation instance using the given GitRepository as context.
	NewRenderServiceInstrumentation(repository *GitRepository) RenderServiceInstrumentation
}

type Template

type Template struct {
	RelativePath    Path
	FilePermissions Permissions
}

func NewTemplate

func NewTemplate(relPath Path, perms Permissions) *Template

func (*Template) Render

func (t *Template) Render(values Values, engine TemplateEngine) (RenderResult, error)

type TemplateEngine

type TemplateEngine interface {
	Execute(template *Template, values Values) (RenderResult, error)
}

type TemplateStore

type TemplateStore interface {
	FetchTemplates() ([]*Template, error)
}

type ValueStore

type ValueStore interface {
	// FetchValuesForTemplate retrieves the Values for the given template.
	FetchValuesForTemplate(template *Template, repository *GitRepository) (Values, error)
	// FetchUnmanagedFlag returns true if the given template should not be rendered.
	// The implementation may return ErrKeyNotFound if the flag is undefined, as the boolean 'false' is ambiguous.
	FetchUnmanagedFlag(template *Template, repository *GitRepository) (bool, error)
	// FetchTargetPath returns an alternative output path for the given template relative to the Git repository.
	// An empty string indicates that there is no alternative path configured.
	FetchTargetPath(template *Template, repository *GitRepository) (Path, error)
	// FetchFilesToDelete returns a slice of Path that should be deleted in the Git repository.
	// The paths are relative to the Git root directory.
	FetchFilesToDelete(repository *GitRepository) ([]Path, error)
}

type Values

type Values map[string]interface{}

Jump to

Keyboard shortcuts

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