Files
mesh-delivery/modules/mesh-delivery-checker/checkermsg/checkermsg.go
T

57 lines
2.0 KiB
Go

// Package checkermsg is the checker's own published layouts (as forgemsg is the forge bridge's): the bodies of its events on the
// stream checks and the answer of its tool checker_tries. It is what the checker says on its stream checks when a whole try (a try of a delivery group, not narrowed
// to a level or to some tests) starts and ends (issue 1921), and what the indexer, which hears it, reads: a try has no pull
// request, so the indexer writes the candidate of its group from the members at their commits, and deletes it at the end.
// The events carry the members, so no part reads the checker's state.
package checkermsg
import (
"encoding/json"
"fmt"
"git.novox.be/novox/mesh-delivery/contracts/go/clients/meshcatalogclient"
)
// The events of the checker's stream checks.
const (
Started = "try.started"
Ended = "try.ended"
)
// Member is one repository of the try: the exact commit and the trunk commit it is merged onto.
type Member struct {
Repository string `json:"repository"`
Head string `json:"head"`
Trunk string `json:"trunk"`
}
// Event is the body of both events: the try, and for Started its members; for Ended the state it ended in.
type Event struct {
ID string `json:"id"`
Members []Member `json:"members,omitempty"`
State string `json:"state,omitempty"`
}
// Decode reads an event body; a started event names its members.
func Decode(event string, body []byte) (Event, error) {
var e Event
if err := json.Unmarshal(body, &e); err != nil {
return e, err
}
if !meshcatalogclient.IsTryGroup(e.ID) {
return e, fmt.Errorf("%q is not a try's id, try-<digits>", e.ID)
}
if event == Started && len(e.Members) == 0 {
return e, fmt.Errorf("the try %s starts with no member", e.ID)
}
return e, nil
}
// Open is one try that waits or runs, as the checker's tool checker_tries answers it.
type Open struct {
ID string `json:"id"`
State string `json:"state"`
Whole bool `json:"whole"`
Members []Member `json:"members"`
}