Documentation
¶
Overview ¶
Package service is vx's application logic: creating repos and efforts, opening workspaces and landing changes. It is independent of the API transport; internal/api adapts it to connect-go.
Index ¶
- Variables
- func Classify(err error) error
- type Actor
- type Code
- type CreateEffortInput
- type CreateRepoInput
- type EffortView
- type Error
- type LandInput
- type LandResult
- type LogEntry
- type Service
- func (s *Service) Abandon(ctx context.Context, actor Actor, id uuid.UUID) (WorkspaceView, error)
- func (s *Service) Branch(ctx context.Context, actor Actor, repo store.Repo, name string) (store.Branch, error)
- func (s *Service) CreateAgent(ctx context.Context, actor Actor, name, displayName string) (store.Principal, string, error)
- func (s *Service) CreateEffort(ctx context.Context, actor Actor, in CreateEffortInput) (store.Effort, error)
- func (s *Service) CreateRepo(ctx context.Context, actor Actor, in CreateRepoInput) (store.Repo, error)
- func (s *Service) GetChangeset(ctx context.Context, repoName, ref string) (store.Repo, LogEntry, error)
- func (s *Service) GetEffort(ctx context.Context, repoName, slug string) (EffortView, error)
- func (s *Service) GetWorkspace(ctx context.Context, id uuid.UUID) (WorkspaceView, error)
- func (s *Service) Land(ctx context.Context, actor Actor, in LandInput) (LandResult, error)
- func (s *Service) ListEfforts(ctx context.Context, repoName string, state store.EffortState) (store.Repo, []store.Effort, error)
- func (s *Service) ListShipments(ctx context.Context, repoName, slug string) ([]store.Shipment, error)
- func (s *Service) Log(ctx context.Context, repoName, slug string, limit int, withFiles bool) ([]LogEntry, error)
- func (s *Service) OpenShipment(ctx context.Context, actor Actor, in ShipInput) (ShipResult, error)
- func (s *Service) OpenWorkspace(ctx context.Context, actor Actor, repoName, slug, intent string) (WorkspaceView, error)
- func (s *Service) PlanShipment(ctx context.Context, actor Actor, repoName, slug, target string) (ShipPlan, error)
- func (s *Service) ResolveActor(ctx context.Context, p store.Principal) (Actor, error)
- func (s *Service) SetBase(ctx context.Context, actor Actor, id uuid.UUID, base hash.Hash) (WorkspaceView, error)
- func (s *Service) SyncBranch(ctx context.Context, actor Actor, repoName, branch string) (store.Branch, int, error)
- type ShipInput
- type ShipPlan
- type ShipResult
- type ShipStep
- type Shipper
- type UpstreamSyncer
- type WorkspaceView
Constants ¶
This section is empty.
Variables ¶
var ErrNothingToLand = errors.New("nothing to land")
ErrNothingToLand is returned when a snapshot has no changes.
Functions ¶
Types ¶
type Actor ¶
Actor is the authenticated caller, with the human it acts for.
func (Actor) OnBehalfOf ¶
OnBehalfOf is the parent's ref for agents, empty otherwise.
type CreateEffortInput ¶
type CreateEffortInput struct {
Repo string
Name string
Goal string
BaseBranch string // empty: the repo's default branch
}
CreateEffortInput describes a new effort.
type CreateRepoInput ¶
type CreateRepoInput struct {
Name string
Provider store.Provider
Remote string
DefaultBranch string
}
CreateRepoInput describes a new repo.
type EffortView ¶
EffortView is an effort with its repo and open workspaces.
type LandInput ¶
type LandInput struct {
WorkspaceID uuid.UUID
Base hash.Hash // changeset the snapshot was made on
Tree hash.Hash // snapshot root tree; objects must be uploaded
Intent string // empty: the workspace intent
Evidence *object.Evidence
DependsOn []string
Model string
Session string
// RequireUpToDate refuses to merge onto newer work.
RequireUpToDate bool
}
LandInput is a snapshot to land into a workspace's effort.
type LandResult ¶
type LandResult struct {
Landed bool
Changeset store.ChangesetRow
Files []store.FileChange
Rebased bool // the effort moved, the snapshot was merged onto it
AutoMerged []string // paths changed on both sides that merged cleanly
Conflicts []engine.Conflict // set when Landed is false
EffortHead hash.Hash
// EffortMoved is set when RequireUpToDate refused the land.
EffortMoved bool
}
LandResult is the outcome of Land.
type LogEntry ¶
type LogEntry struct {
store.ChangesetRow
Files []store.FileChange
}
LogEntry is a landed changeset with its file list.
type Service ¶
type Service struct {
Store *store.Store
Blobs blob.Store
Upstream UpstreamSyncer // nil: repos without an upstream only
Shipper Shipper // nil: shipping disabled
Now func() time.Time
// MaxLandAttempts bounds compare-and-swap retries when several agents
// land into the same effort at once.
MaxLandAttempts int
}
Service holds the dependencies of the application logic.
func New ¶
New returns a Service with defaults filled in. When upstream can also ship (the git bridge can), it is used for that too.
func (*Service) Branch ¶
func (s *Service) Branch(ctx context.Context, actor Actor, repo store.Repo, name string) (store.Branch, error)
Branch returns a tracked branch, importing it first if vx does not follow it yet. This is how efforts can start from any branch on the fly.
func (*Service) CreateAgent ¶
func (s *Service) CreateAgent(ctx context.Context, actor Actor, name, displayName string) (store.Principal, string, error)
CreateAgent creates an agent that acts for the calling human and returns it with a fresh token. Agents cannot create agents.
func (*Service) CreateEffort ¶
func (s *Service) CreateEffort(ctx context.Context, actor Actor, in CreateEffortInput) (store.Effort, error)
CreateEffort starts an effort on the current head of its base branch.
func (*Service) CreateRepo ¶
func (s *Service) CreateRepo(ctx context.Context, actor Actor, in CreateRepoInput) (store.Repo, error)
CreateRepo registers a repo. A repo with an upstream imports its default branch right away; a repo without one starts from an empty snapshot.
func (*Service) GetChangeset ¶
func (s *Service) GetChangeset(ctx context.Context, repoName, ref string) (store.Repo, LogEntry, error)
GetChangeset resolves a changeset by hash, prefix or change ID.
func (*Service) GetWorkspace ¶
GetWorkspace loads a workspace with its effort and repo.
func (*Service) Land ¶
Land merges a workspace snapshot into its effort.
When the effort has not moved since the snapshot's base, the snapshot becomes the new head. When it has, the snapshot is merged onto the current head with a three-way merge, and only real conflicts are sent back. The head moves with a compare-and-swap, so concurrent lands never lose work: the loser merges again on the new head and retries.
func (*Service) ListEfforts ¶
func (s *Service) ListEfforts(ctx context.Context, repoName string, state store.EffortState) (store.Repo, []store.Effort, error)
ListEfforts lists a repo's efforts.
func (*Service) ListShipments ¶
func (s *Service) ListShipments(ctx context.Context, repoName, slug string) ([]store.Shipment, error)
ListShipments returns an effort's shipments.
func (*Service) Log ¶
func (s *Service) Log(ctx context.Context, repoName, slug string, limit int, withFiles bool) ([]LogEntry, error)
Log lists changes landed in an effort since its base, newest first.
func (*Service) OpenShipment ¶
OpenShipment pushes the planned commits to vx/<effort> and opens or updates the pull request. Shipping again replaces the branch and updates the same PR. vx never merges: that stays a decision on the git host.
func (*Service) OpenWorkspace ¶
func (s *Service) OpenWorkspace(ctx context.Context, actor Actor, repoName, slug, intent string) (WorkspaceView, error)
OpenWorkspace starts a task in an effort, based on the effort's head.
func (*Service) PlanShipment ¶
func (s *Service) PlanShipment(ctx context.Context, actor Actor, repoName, slug, target string) (ShipPlan, error)
PlanShipment replays the effort's changes, oldest first, onto the latest head of the target branch. Each change becomes one commit. A change whose parent is not the current tree is merged onto it, so an effort started on an older commit, or on another branch, still ships cleanly.
func (*Service) ResolveActor ¶
ResolveActor loads the parent of an agent principal.
type ShipInput ¶
type ShipInput struct {
Repo, Effort, Target string
Title, Body string // empty: generated
Draft bool
}
ShipInput controls OpenShipment.
type ShipPlan ¶
type ShipPlan struct {
Repo store.Repo
Effort store.Effort
Target string
TargetHead store.ChangesetRow
Branch string
Title string
Body string
Steps []ShipStep
Conflicts []engine.Conflict
ConflictedAt *store.ChangesetRow
}
ShipPlan is what shipping an effort would produce.
type ShipResult ¶
ShipResult is a pushed branch and, where the provider has them, its PR.
type ShipStep ¶
type ShipStep struct {
Changeset store.ChangesetRow
Tree hash.Hash // tree after this step, on top of the target
Files int // files this step changes on the target
Skipped bool // the target already has this change
}
ShipStep is one landed change replayed onto the target.
type Shipper ¶
type Shipper interface {
ExportBranch(ctx context.Context, repo store.Repo, baseSHA, branch string, commits []provider.Commit) ([]string, error)
OpenPullRequest(ctx context.Context, repo store.Repo, pr provider.PullRequest) (provider.OpenedPR, error)
}
Shipper pushes branches and opens pull requests on the git host.
type UpstreamSyncer ¶
type UpstreamSyncer interface {
// DefaultBranch asks the provider for the repo's default branch.
DefaultBranch(ctx context.Context, repo store.Repo) (string, error)
// SyncBranch imports new commits on branch and records its head.
SyncBranch(ctx context.Context, repo store.Repo, branch string) (store.Branch, int, error)
}
UpstreamSyncer imports branches from a repo's git provider.