Files
mesh-delivery/modules/mesh-delivery-checker/internal/check/seatdefs.go
T

57 lines
2.3 KiB
Go

package check
import (
"context"
"fmt"
"git.novox.be/novox/mesh-delivery/contracts/go/clients/meshdeliverycheckerclient"
"git.novox.be/novox/mesh-delivery/contracts/go/seats/meshdeliverychecker"
)
// A pull request whose head's seat definition does not parse fails its check, naming the seat and where it lives (design
// 26; the lead's ruling on A2i's finding 1): the indexer keeps such a definition as the pull request's entry of its state
// seat-definitions with `unparsed` set, and cannot refuse the manifest itself, whose digest the trunk may share.
// UnparsedSeat is one seat definition of a pull request's head that does not parse: the seat (the contracts module's name
// when its index did not parse), its module's directory and the indexer's words of why.
type UnparsedSeat struct {
Seat, Module, Directory, Why string
}
// SeatDefinitions reads the indexer's seat definitions of one pull request (its state seat-definitions, through its
// first view, DLV-M2).
type SeatDefinitions interface {
Unparsed(ctx context.Context, repository string, pull int) ([]UnparsedSeat, error)
}
// refuseUnparsed fails the check of each pull request with a seat definition that does not parse; a state that cannot be
// read fails it too, saying so.
func (st *state) refuseUnparsed(ctx context.Context) *meshdeliverychecker.VerdictsByGroupHeadsValue {
if st.j.SeatDefinitions == nil || st.c.Try != nil {
return nil
}
var out *meshdeliverychecker.VerdictsByGroupHeadsValue
failed := func(words string) {
f := FailedFirst{Machine: SeatDefinitionsMachine, Words: words}
if out == nil {
out = &meshdeliverychecker.VerdictsByGroupHeadsValue{State: meshdeliverycheckerclient.VerdictFail, Failed: &f}
return
}
addFailure(out, f)
}
for _, p := range st.c.Pulls {
bad, err := st.j.SeatDefinitions.Unparsed(ctx, p.Repository, p.Number)
if err != nil {
failed(fmt.Sprintf("%s: the indexer's seat definitions of it cannot be read, so none is known to parse: %v", pullKey(p), err))
continue
}
for _, u := range bad {
failed(fmt.Sprintf("%s: the seat definition of %s (module %s, %s) does not parse: %s", pullKey(p), u.Seat, u.Module, u.Directory, u.Why))
}
}
return out
}
// SeatDefinitionsMachine names what refused a seat definition in a verdict's failure.
const SeatDefinitionsMachine = "seat-definitions"