Files
mesh-delivery/sdk/tryevent/tryevent.go
T
jschoubben 03809d8d83 Merge origin/main into b7/registry: the group try and the successor validation take the group's contracts, clients and seat list (issue 1966, issue 1921)
The seat verb try gains members (ADR 0637 section 6); the try's group name and the missing-preview reason are one definition of mesh-delivery-sdk (ADR 0637 section 8).

Claude-Session: https://claude.ai/code/session_01NcbgfFSnn24M3GcqttoU7i
2026-11-05 20:41:41 +01:00

66 lines
2.4 KiB
Go

// Package tryevent 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 tryevent
import (
"encoding/json"
"fmt"
"regexp"
)
// The events of the checker's stream checks.
const (
Started = "try.started"
Ended = "try.ended"
)
// IDOK is the shape of a try's id, which is also the name of its group (the key of its candidate).
var IDOK = regexp.MustCompile(`^try-[0-9]{1,20}$`)
// IsGroup says a candidates key is the group of a try: the one definition the checker and the indexer share.
func IsGroup(key string) bool { return IDOK.MatchString(key) }
// NoneNoPreview is why a candidate's touched module has no fingerprint of the new form yet: its merge preview is not
// computed. The indexer writes it; the checker, which waits for a try's candidate, takes a candidate that still says it as
// not yet the candidate of the heads previewed. One definition for both.
const NoneNoPreview = "no merge preview is computed"
// 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 !IDOK.MatchString(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"`
}