package check import ( "encoding/json" "fmt" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" ) // TrunkVerb is the key of the seat verb the trunk heads are asked by (design 47 G ยง197). const TrunkVerb = "seat:" + meshcatalog.Seat + "." + meshcatalog.VerbRevision // TrunkHeads reads the trunk head of every repository out of the seat mesh-catalog's answer of `revision`. A candidate's // revision is no trunk's and is refused. func TrunkHeads(raw json.RawMessage) (map[string]string, error) { var a meshcatalog.RevisionAnswer if err := json.Unmarshal(raw, &a); err != nil { return nil, fmt.Errorf("the catalog half's revision does not read: %w", err) } if a.Revision == nil { return nil, fmt.Errorf("the catalog half's revision answers no revision (none-yet: %v)", a.NoneYet) } if a.Revision.Kind != "trunk" { return nil, fmt.Errorf("the catalog half's revision %d is a %q revision, not a trunk's", a.Revision.Revision, a.Revision.Kind) } heads := map[string]string{} for _, h := range a.Revision.Trunk { heads[h.Repository] = h.Commit } return heads, nil }