transaction

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAbortTransaction      = errors.New("transaction aborted")
	ErrTransactionActive     = errors.New("transaction is active")
	ErrNoPullRequestProvider = errors.New("no pull request provider given")
)

Functions

This section is empty.

Types

type CommitResult

type CommitResult interface {
	// GetAuthorName describes the author's name (as per git config)
	// +required
	GetAuthorName() string
	// GetAuthorEmail describes the author's email (as per git config)
	// +required
	GetAuthorEmail() string
	// GetTitle describes the change concisely, so it can be used as a commit message or PR title.
	// +required
	GetTitle() string
	// GetDescription contains optional extra information about the change.
	// +optional
	GetDescription() string

	// GetMessage returns GetTitle() followed by a newline and GetDescription(), if set.
	GetMessage() string
	// Validate validates that all required fields are set, and given data is valid.
	Validate() error
}

CommitResult describes a result of a transaction.

type GenericCommitResult

type GenericCommitResult struct {
	// AuthorName describes the author's name (as per git config)
	// +required
	AuthorName string
	// AuthorEmail describes the author's email (as per git config)
	// +required
	AuthorEmail string
	// Title describes the change concisely, so it can be used as a commit message or PR title.
	// +required
	Title string
	// Description contains optional extra information about the change.
	// +optional
	Description string
}

GenericCommitResult implements CommitResult.

func (*GenericCommitResult) GetAuthorEmail

func (r *GenericCommitResult) GetAuthorEmail() string

func (*GenericCommitResult) GetAuthorName

func (r *GenericCommitResult) GetAuthorName() string

func (*GenericCommitResult) GetDescription

func (r *GenericCommitResult) GetDescription() string

func (*GenericCommitResult) GetMessage

func (r *GenericCommitResult) GetMessage() string

func (*GenericCommitResult) GetTitle

func (r *GenericCommitResult) GetTitle() string

func (*GenericCommitResult) Validate

func (r *GenericCommitResult) Validate() error

type GenericPullRequestResult

type GenericPullRequestResult struct {
	// GenericPullRequestResult is a superset of a CommitResult.
	CommitResult

	// Labels specifies what labels should be applied on the PR.
	// +optional
	Labels []string
	// Assignees specifies what user login names should be assigned to this PR.
	// Note: Only users with "pull" access or more can be assigned.
	// +optional
	Assignees []string
	// Milestone specifies what milestone this should be attached to.
	// +optional
	Milestone string
}

GenericPullRequestResult implements PullRequestResult.

func (*GenericPullRequestResult) GetAssignees

func (r *GenericPullRequestResult) GetAssignees() []string

func (*GenericPullRequestResult) GetLabels

func (r *GenericPullRequestResult) GetLabels() []string

func (*GenericPullRequestResult) GetMilestone

func (r *GenericPullRequestResult) GetMilestone() string

func (*GenericPullRequestResult) Validate

func (r *GenericPullRequestResult) Validate() error

type GenericPullRequestSpec

type GenericPullRequestSpec struct {
	// GenericPullRequestSpec is a superset of PullRequestResult.
	PullRequestResult

	// MainBranch returns the main branch of the repository.
	// +required
	MainBranch string
	// MergeBranch returns the branch that is pending to be merged into main with this PR.
	// +required
	MergeBranch string
	// RepositoryRef returns the branch that is pending to be merged into main with this PR.
	// +required
	RepositoryRef gitprovider.RepositoryRef
}

GenericPullRequestSpec implements PullRequestSpec.

func (*GenericPullRequestSpec) GetMainBranch

func (r *GenericPullRequestSpec) GetMainBranch() string

func (*GenericPullRequestSpec) GetMergeBranch

func (r *GenericPullRequestSpec) GetMergeBranch() string

func (*GenericPullRequestSpec) GetRepositoryRef

func (r *GenericPullRequestSpec) GetRepositoryRef() gitprovider.RepositoryRef

func (*GenericPullRequestSpec) Validate

func (r *GenericPullRequestSpec) Validate() error

type GitStorage

type GitStorage struct {
	storage.ReadStorage
	// contains filtered or unexported fields
}

func (*GitStorage) Transaction

func (s *GitStorage) Transaction(ctx context.Context, streamName string, fn TransactionFunc) error

type PullRequestProvider

type PullRequestProvider interface {
	// CreatePullRequest creates a Pull Request using the given specification.
	CreatePullRequest(ctx context.Context, spec PullRequestSpec) error
}

PullRequestProvider is an interface for providers that can create so-called "Pull Requests", as popularized by Git. A Pull Request is a formal ask for a branch to be merged into the main one. It can be UI-based, as in GitHub and GitLab, or it can be using some other method.

type PullRequestResult

type PullRequestResult interface {
	// PullRequestResult is a superset of CommitResult
	CommitResult

	// GetLabels specifies what labels should be applied on the PR.
	// +optional
	GetLabels() []string
	// GetAssignees specifies what user login names should be assigned to this PR.
	// Note: Only users with "pull" access or more can be assigned.
	// +optional
	GetAssignees() []string
	// GetMilestone specifies what milestone this should be attached to.
	// +optional
	GetMilestone() string
}

PullRequestResult can be returned from a TransactionFunc instead of a CommitResult, if a PullRequest is desired to be created by the PullRequestProvider.

type PullRequestSpec

type PullRequestSpec interface {
	// PullRequestSpec is a superset of PullRequestResult.
	PullRequestResult

	// GetMainBranch returns the main branch of the repository.
	// +required
	GetMainBranch() string
	// GetMergeBranch returns the branch that is pending to be merged into main with this PR.
	// +required
	GetMergeBranch() string
	// GetMergeBranch returns the branch that is pending to be merged into main with this PR.
	// +required
	GetRepositoryRef() gitprovider.RepositoryRef
}

PullRequestSpec is the messaging interface between the TransactionStorage, and the PullRequestProvider. The PullRequestSpec contains all the needed information for creating a Pull Request successfully.

type TransactionFunc

type TransactionFunc func(ctx context.Context, s storage.Storage) (CommitResult, error)

type TransactionStorage

type TransactionStorage interface {
	storage.ReadStorage

	// Transaction creates a new "stream" (for Git: branch) with the given name, or
	// prefix if streamName ends with a dash (in that case, a 8-char hash will be appended).
	// The environment is made sure to be as up-to-date as possible before fn executes. When
	// fn executes, the given storage can be used to modify the desired state. If you want to
	// "commit" the changes made in fn, just return nil. If you want to abort, return ErrAbortTransaction.
	// If you want to
	Transaction(ctx context.Context, streamName string, fn TransactionFunc) error
}

Directories

Path Synopsis
pullrequest

Jump to

Keyboard shortcuts

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