api

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 2 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package api holds the wire types and error codes of the /v1 routes.

Index

Constants

View Source
const (
	HeaderSignature = "X-Motte-Signature"
	HeaderPartition = "X-Motte-Partition"
	HeaderSequence  = "X-Motte-Sequence"
)

Headers of an event delivery. Signature is "sha256=" and the lowercase hex HMAC-SHA256 of the request body under the secret of the subscription.

Variables

This section is empty.

Functions

This section is empty.

Types

type Blobs

type Blobs struct {
	Blobs []string `json:"blobs"`
}

type BlobsRequest

type BlobsRequest struct {
	SHAs []string `json:"shas"`
}

type ClaimRequest

type ClaimRequest struct {
	Epoch uint64 `json:"epoch"`
	Owner string `json:"owner"`
	Repo  string `json:"repo"`
}

ClaimRequest is the body of PUT /v1/workspaces/{id}/claim.

type ClaimResponse

type ClaimResponse struct {
	Epoch    uint64 `json:"epoch"`
	Op       string `json:"op"`
	Snapshot string `json:"snapshot"`
}

ClaimResponse returns the stored epoch, op and snapshot of the workspace.

type Code

type Code string

Code is a wire error code.

const (
	CodeNotFound           Code = "vcs_not_found"
	CodePathNotFound       Code = "vcs_path_not_found"
	CodeGenerationConflict Code = "vcs_generation_conflict"
	CodeClaimLost          Code = "vcs_claim_lost"
	CodeObjectInvalid      Code = "vcs_object_invalid"
	CodeObjectTooLarge     Code = "vcs_object_too_large"
	CodeRepoForbidden      Code = "vcs_repo_forbidden"
	CodeWorkspaceConflict  Code = "vcs_workspace_conflict"
	CodeWorkspaceDeleted   Code = "vcs_workspace_deleted"
	CodeRefProtected       Code = "vcs_ref_protected"
	CodeEventsPruned       Code = "vcs_events_pruned"
	CodeLandConflict       Code = "vcs_land_conflict"
	CodeLandStale          Code = "vcs_land_stale"
	CodeLandInvalid        Code = "vcs_land_invalid"
	CodeLandTimeout        Code = "vcs_land_timeout"
	CodeLandPending        Code = "vcs_land_pending"
	CodeLandAcknowledged   Code = "vcs_land_acknowledged"
	CodeUnauthorized       Code = "unauthorized"
	CodeInvalidBody        Code = "invalid_body"
	CodeInternal           Code = "internal_error"
	CodeMethodNotAllowed   Code = "method_not_allowed"
)

func (Code) Status

func (c Code) Status() int

Status is the HTTP status of c. An unknown code is 500.

type Commit

type Commit struct {
	Tree    string   `json:"tree"`
	Time    string   `json:"time"`
	Parents []string `json:"parents"`
}

Commit is the root tree of a commit, its committer time (RFC 3339) and its parents in order.

type CreateRepoRequest

type CreateRepoRequest struct {
	// ID is an optional idempotency key of 8 to 64 characters of letters, digits, "_" and "-". A repeat of an ID
	// with the same name and owner answers the first path, and a repeat with another name or owner is refused.
	ID    string `json:"id,omitempty"`
	Name  string `json:"name"`
	Owner string `json:"owner"`
}

CreateRepoRequest is the body of POST /v1/repos.

type CreateRepoResponse

type CreateRepoResponse struct {
	Path string `json:"path"`
}

type CreateSubscriptionRequest added in v0.6.0

type CreateSubscriptionRequest struct {
	URL    string `json:"url"`
	Secret string `json:"secret"`
	Repo   string `json:"repo,omitempty"`
}

CreateSubscriptionRequest is the body of POST /v1/subscriptions. Repo is empty for the events of every repo.

type CreateUserTokenRequest added in v0.9.0

type CreateUserTokenRequest struct {
	Principal  string   `json:"principal"`
	Scope      string   `json:"scope"`
	Repos      []string `json:"repos"`
	TTLSeconds int64    `json:"ttl_seconds"`
}

CreateUserTokenRequest is the body of POST /v1/tokens. Scope is read or write with at least one repository text in Repos, or admin with none. TTLSeconds is 0 for a token with no expiry.

type CreateUserTokenResponse added in v0.9.0

type CreateUserTokenResponse struct {
	Token     string    `json:"token"`
	UserToken UserToken `json:"user_token"`
}

CreateUserTokenResponse holds the token text. The service keeps only its hash and never shows the text again.

type Error

type Error struct {
	Code    Code           `json:"code"`
	Message string         `json:"message"`
	Details map[string]any `json:"details"`
}

func (*Error) Error

func (e *Error) Error() string

type ErrorBody

type ErrorBody struct {
	Error Error `json:"error"`
}

ErrorBody is the body of every error response. A conflict on a ref sets Details["ref"] to the stored Ref.

type Event added in v0.6.0

type Event struct {
	Partition  int    `json:"partition"`
	Seq        int64  `json:"seq"`
	Repo       string `json:"repo"`
	Ref        string `json:"ref"`
	Old        string `json:"old"`
	New        string `json:"new"`
	Generation int64  `json:"generation"`
	Kind       string `json:"kind"`
	Time       string `json:"time"`
}

Event is one change of a ref. Its identity is Partition and Seq. Events of one ref share a partition, and Seq has no gap and follows commit order in a partition. No order holds across partitions. Old is empty for a create and New is empty for a delete. Generation is that of the ref after the change, or of the deleted ref. Kind is the scope of the grant that wrote the ref: node, write, merge or operator. Time is RFC 3339.

type Events added in v0.6.0

type Events struct {
	Events []Event `json:"events"`
	Cursor string  `json:"cursor"`
}

Events is the answer of GET /v1/events. Cursor is opaque. A consumer passes it as the cursor of the next call, and gets the events after the last one here.

type File added in v0.19.0

type File struct {
	SHA  string `json:"sha"`
	Size int64  `json:"size"`
	Data string `json:"data"`
}

File is one file of a commit. Data is the base64 of the content.

type FlushRequest

type FlushRequest struct {
	Epoch      uint64 `json:"epoch"`
	Generation int64  `json:"generation"`
	Prev       string `json:"prev"`
	Op         string `json:"op"`
	Snapshot   string `json:"snapshot"`
}

FlushRequest is the body of POST /v1/workspaces/{id}/flush.

type Has

type Has struct {
	Present []bool `json:"present"`
}

type HasRequest

type HasRequest struct {
	SHAs []string `json:"shas"`
}

type ImportPackRequest

type ImportPackRequest struct {
	Index string `json:"index"`
	Pack  string `json:"pack"`
}

ImportPackRequest is the body of PUT /v1/vcs/packs/{pack_id}. The pack ID is the lowercase hex SHA-256 of the pack bytes. Both fields are base64.

type LandRequest added in v0.6.0

type LandRequest struct {
	ID         string `json:"id,omitempty"`
	Ref        string `json:"ref"`
	Base       string `json:"base"`
	Head       string `json:"head"`
	ExpectTree string `json:"expect_tree,omitempty"`
}

LandRequest is the body of POST /v1/repos/{repo}/lands. Base..Head is a linear range of commits that the repository already stores. ID is optional: a repeat of an accepted ID returns the first result and never lands twice. ExpectTree is optional: when set, the land moves the ref only if the tree of the commit that Head becomes equals it.

type LandResponse added in v0.6.0

type LandResponse struct {
	ID          string         `json:"id"`
	Ref         string         `json:"ref"`
	Generation  int64          `json:"generation"`
	Tip         string         `json:"tip"`
	FastForward bool           `json:"fast_forward"`
	Commits     []LandedCommit `json:"commits"`
}

LandResponse is the answer of a land that moved the ref, or found the head already at its tip. Tip is the commit of the head after the land, and Generation is the generation of the ref move that holds it. The ref can move on before the answer arrives. FastForward is set when the head already descended from the tip and the ref moved to it as it is, and Commits is then empty. Else Commits maps each commit of the range to its new commit, oldest first.

type LandedCommit added in v0.6.0

type LandedCommit struct {
	Old string `json:"old"`
	New string `json:"new"`
}

LandedCommit is a commit of the range and the commit that replaced it on the ref.

type Object

type Object struct {
	Type string `json:"type"`
	Data string `json:"data"`
}

Object is one git object. Type is commit, tree, blob or tag. Data is base64.

type OpHeads

type OpHeads struct {
	Epoch      uint64   `json:"epoch"`
	Generation int64    `json:"generation"`
	Heads      []string `json:"heads"`
}

OpHeads is the head set of the op log of a workspace. Generation starts at 1.

type OpObject

type OpObject struct {
	Data string `json:"data"`
}

type ProtectedRefs added in v0.6.0

type ProtectedRefs struct {
	Patterns []string `json:"patterns"`
}

ProtectedRefs is the body of PUT and GET /v1/repos/{repo}/protected-refs. A pattern is a ref name, or a prefix that ends in "*".

type PutObjectsRequest

type PutObjectsRequest struct {
	Objects []Object `json:"objects"`
}

type PutObjectsResponse

type PutObjectsResponse struct {
	SHAs []string `json:"shas"`
}

type PutSubscriptionRequest added in v0.19.0

type PutSubscriptionRequest = CreateSubscriptionRequest

PutSubscriptionRequest is the body of PUT /v1/subscriptions/{name}. A replace keeps the cursors.

type Ref

type Ref struct {
	Name       string `json:"name"`
	Commit     string `json:"commit"`
	Generation int64  `json:"generation"`
}

Ref is one ref of a repository. Commit is 40 lowercase hex digits. Generation is never reused, even when the ref is deleted and created again.

type Refs

type Refs struct {
	Refs []Ref `json:"refs"`
}

type Repo

type Repo struct {
	Path      string `json:"path"`
	Name      string `json:"name"`
	Owner     string `json:"owner"`
	CreatedAt string `json:"created_at"`
}

Repo is one repository of the store.

type Repos

type Repos struct {
	Repos []Repo `json:"repos"`
}

type SetWorkspaceRequest

type SetWorkspaceRequest struct {
	Op         string `json:"op"`
	Commit     string `json:"commit"`
	Generation int64  `json:"generation"`
}

SetWorkspaceRequest is the body of PUT /v1/vcs/workspace. Generation is that of the op-heads swap of Op.

type Subscription added in v0.6.0

type Subscription struct {
	ID        string `json:"id"`
	URL       string `json:"url"`
	Repo      string `json:"repo,omitempty"`
	Cursor    string `json:"cursor"`
	CreatedAt string `json:"created_at"`
}

Subscription is a registered receiver. Cursor is an event cursor that holds the last event that it acknowledged in each partition. The secret is never returned.

type Subscriptions added in v0.6.0

type Subscriptions struct {
	Subscriptions []Subscription `json:"subscriptions"`
}

type SwapOpHeadsRequest

type SwapOpHeadsRequest struct {
	ExpectGeneration int64    `json:"expect_generation"`
	Heads            []string `json:"heads"`
}

SwapOpHeadsRequest is the body of PUT /v1/vcs/op-heads. ExpectGeneration is 0 for the first write.

type SwapRefRequest

type SwapRefRequest struct {
	Expect int64  `json:"expect"`
	Commit string `json:"commit"`
}

SwapRefRequest is the body of PUT /v1/vcs/refs/{name}. Expect is the stored generation, or 0 to create the ref.

type Tree

type Tree struct {
	SHA     string      `json:"sha"`
	Entries []TreeEntry `json:"entries"`
}

type TreeEntry

type TreeEntry struct {
	Name string `json:"name"`
	Mode string `json:"mode"`
	SHA  string `json:"sha"`
	Size int64  `json:"size,omitempty"`
}

TreeEntry is one entry of a tree. Name is the base64 of the name bytes, which need not be UTF-8. Mode is the octal git mode.

type Trees

type Trees struct {
	Trees []Tree `json:"trees"`
}

type TrialChange added in v0.19.0

type TrialChange struct {
	Head string `json:"head"`
	Base string `json:"base"`
}

TrialChange is one change of a trial land. Base is required.

type TrialConflict added in v0.19.0

type TrialConflict struct {
	Paths []string `json:"paths"`
}

TrialConflict names the paths that a change shares with what changed since its base.

type TrialItem added in v0.19.0

type TrialItem struct {
	Base     string         `json:"base,omitempty"`
	Tree     string         `json:"tree,omitempty"`
	Tip      string         `json:"tip,omitempty"`
	Commits  []LandedCommit `json:"commits,omitempty"`
	Conflict *TrialConflict `json:"conflict,omitempty"`
	Error    *Error         `json:"error,omitempty"`
}

TrialItem is the result of one change of a trial land: Base, Tree, Tip and Commits when it landed, Conflict when it clashed, else Error. Tree is the root tree of Tip, and Commits maps the commits of the range to the new commits. A landed item always holds Commits, which is [] for a head that already descends from the running tip.

func (TrialItem) MarshalJSON added in v0.19.0

func (i TrialItem) MarshalJSON() ([]byte, error)

MarshalJSON writes Commits as [] and never drops it for an item that landed.

type TrialRequest added in v0.19.0

type TrialRequest struct {
	Tip     string        `json:"tip"`
	Changes []TrialChange `json:"changes"`
}

TrialRequest is the body of POST /v1/repos/{repo}/lands:trial. Each change lands on the result of the one before, the first on Tip.

type TrialResponse added in v0.19.0

type TrialResponse struct {
	Items []TrialItem `json:"items"`
}

TrialResponse has one item for each change, in order.

type UserToken added in v0.9.0

type UserToken struct {
	ID        string   `json:"id"`
	Principal string   `json:"principal"`
	Scope     string   `json:"scope"`
	Repos     []string `json:"repos"`
	CreatedAt string   `json:"created_at"`
	ExpiresAt string   `json:"expires_at,omitempty"`
	RevokedAt string   `json:"revoked_at,omitempty"`
}

UserToken is the record of a per-user token. The times are RFC 3339, empty when unset.

type UserTokens added in v0.9.0

type UserTokens struct {
	Tokens []UserToken `json:"tokens"`
}

Jump to

Keyboard shortcuts

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