Documentation
¶
Overview ¶
Package check holds the required checks of a ref, the results that a runner posts, and the delivery of check requests.
Index ¶
- Constants
- Variables
- type Check
- type Clock
- type Manager
- func (m *Manager) Changed() <-chan struct{}
- func (m *Manager) Ensure(ctx context.Context, repo, tree, commit string, c Check) error
- func (m *Manager) Mark(ctx context.Context) (int64, error)
- func (m *Manager) Post(ctx context.Context, repo string, p Posted) error
- func (m *Manager) Runner(repo string) (Runner, bool)
- func (m *Manager) Start(ctx context.Context) error
- func (m *Manager) Verdict(ctx context.Context, repo, tree string, c Check, mark int64) (Verdict, error)
- func (m *Manager) Wait()
- type Posted
- type Request
- type Result
- type Runner
- type State
- type Status
- type Store
- type Verdict
Constants ¶
const (
// FilePath is the check file at the tip of a target ref.
FilePath = ".ward/checks.json"
)
Variables ¶
var ( // ErrInvalid means that a posted result breaks a rule of the body. ErrInvalid = errors.New("check: invalid result") // ErrUnknownRequest means that no request has the posted request_id. ErrUnknownRequest = errors.New("check: unknown request") // ErrOtherRepo means that the request belongs to another repository. ErrOtherRepo = errors.New("check: request of another repository") )
var ErrNoRunner = errors.New("check: no runner for the repository")
ErrNoRunner means that no runner is configured for the repository.
Functions ¶
This section is empty.
Types ¶
type Check ¶
type Check struct {
Name string `json:"name"`
Run []string `json:"run"`
TimeoutSeconds int `json:"timeout_seconds"`
}
Check is one required check. The runner runs Run at the root of the tree.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager keeps the results and sends the check requests. It has no poll: a result wakes the waiters.
func (*Manager) Changed ¶
func (m *Manager) Changed() <-chan struct{}
Changed returns a channel that closes at the next result. Take it before reading the state that the result changes.
func (*Manager) Ensure ¶
Ensure makes sure that a request for check c of tree is open, and starts its delivery when it opens one.
func (*Manager) Mark ¶
Mark returns the position after the newest result. A fail counts for a land only when it is after its mark.
func (*Manager) Post ¶
Post records a result that a runner posted for a repository. A second result for a request changes nothing.
type Posted ¶
type Posted struct {
RequestID string `json:"request_id"`
Status Status `json:"status"`
Summary string `json:"summary"`
LogURL string `json:"log_url"`
}
Posted is the body that a runner posts.
type Request ¶
type Request struct {
ID string
Repo string
Tree string
Commit string
Check Check
Hash string
Env string
AcceptedAt time.Time
Open bool
}
Request is one check request to a runner. It is open until a result or a newer request for its key ends it.
type Result ¶
type Result struct {
ID int64
RequestID string
Repo string
Tree string
Hash string
Env string
Status Status
Summary string
LogURL string
}
Result is a fact about the content of a tree. Its ID orders results across the store.
type Runner ¶
type Runner struct {
Repo string `json:"repo"`
URL string `json:"url"`
SecretFile string `json:"secret_file"`
Env string `json:"env"`
}
Runner says where ward sends the check requests of one repository.
func ParseRunners ¶
ParseRunners decodes and checks the WARD_RUNNERS list. It rejects an unknown field.
type Store ¶
type Store interface {
// OpenRequest returns the open request for the key of r. With no open request and no pass for the key, it stores r and returns it with true.
OpenRequest(ctx context.Context, r Request) (Request, bool, error)
Request(ctx context.Context, id string) (Request, bool, error)
OpenRequests(ctx context.Context) ([]Request, error)
SetAccepted(ctx context.Context, id string, at time.Time) error
// Supersede closes the request old and stores next, an open request for the same key. It does nothing and returns false
// when old is no longer open or the key has a pass.
Supersede(ctx context.Context, old string, next Request) (bool, error)
// AddResult stores a result and closes its request. A pass also closes every other open request for the key.
// It returns false and changes nothing when the request already has a result.
AddResult(ctx context.Context, r Result) (bool, error)
// Results returns the results of one key, oldest first.
Results(ctx context.Context, repo, tree, hash, env string) ([]Result, error)
MaxResultID(ctx context.Context) (int64, error)
}
Store is the transactional state of requests and results. Each method that writes is one transaction.