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

41 lines
2.1 KiB
Go

package check
import (
"context"
"git.novox.be/novox/mesh-delivery/contracts/go/clients/meshdeliverycheckerclient"
"git.novox.be/novox/mesh-delivery/contracts/go/seats/meshdeliverychecker"
)
// EventVerdict is the checker's event that says a pull request's check ended, with the generated files its steps found out
// of step with their seat definitions (design 26 *Out of step*; ADR 0620): on the checker's own family asks (its stream
// asks), so the indexer learns them from the event and runs no generator, and a waiter on the stream checks does not wake.
const EventVerdict = meshdeliverychecker.HolderEventVerdict
// VerdictEvent is the body of verdict, as the seat definition of mesh-delivery-checker says it.
type VerdictEvent = meshdeliverychecker.VerdictHolderEvent
// VerdictSayer publishes a verdict event.
type VerdictSayer interface {
Say(ctx context.Context, v VerdictEvent) error
}
// sayVerdict says, for each pull request of a check that ended in pass or fail, one verdict event naming its head and its
// out-of-step files. A try owes no pull request anything and says none (ADR 0501 §5). A publish that fails is said in the
// log: the verdict and the status are written already, and the next check of the heads says it again.
func (ch *Checker) sayVerdict(ctx context.Context, cs *Case, v meshdeliverychecker.VerdictsByGroupHeadsValue, out Outcome) {
if ch.Says == nil || cs.Try != nil || (v.State != meshdeliverycheckerclient.VerdictPass && v.State != meshdeliverycheckerclient.VerdictFail) {
return
}
for _, p := range cs.Pulls {
key := pullKey(Pull{Repository: p.Repository, Number: p.Number})
e := VerdictEvent{Repository: p.Repository, Pull: int64(p.Number), Head: p.Head, Verdict: v.State, OutOfStep: out.OutOfStep[key]}
for _, s := range cs.SeriesChanges(key) {
e.Series = append(e.Series, meshdeliverychecker.VerdictHolderEventSeriesItem{Module: s.Module, Artifact: s.Artifact, From: s.From, To: s.To})
}
if err := ch.Says.Say(ctx, e); err != nil {
ch.logf("%s: the verdict of %s#%d was written, and its event could not be said: %v", cs.Key, p.Repository, p.Number, err)
}
}
}