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

29 lines
974 B
Go

package check
import (
"encoding/json"
"fmt"
"git.novox.be/novox/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.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
}