Files
mesh-delivery/modules/mesh-delivery-forge-bridge/internal/bridge/named.go
T
jschoubben 8ab8c5d04a Carry each named path's git object in the merged and pull messages of a module whose every artifact names its paths, read at its manifest's commit (issue 1758, I6, ADR 0499 §3)
Asks gitea_commit_trees with paths (the interface agreed with the lead); a forge that cannot say is a retry. Pins
mesh-sdk feat/r4e-sdk 9cb4d59.
2026-10-22 18:13:25 +02:00

64 lines
2.2 KiB
Go

package bridge
import (
"encoding/json"
"fmt"
"slices"
"git.novox.be/novox/mesh-sdk/go/catalogue"
)
// Named asks the forge for the git object of each named path of the module directories given, at a commit: by directory
// (the root spelled ""), the paths relative to it; answered by directory, then path (gitea_commit_trees with `paths`,
// mesh-sdk delivery.Forge.Paths; novox/hq ADR 0499 clause 3). A path the forge does not hold fails the call.
type Named func(owner, repo, sha string, paths map[string][]string) (map[string]map[string]string, error)
// namedPathsOf are, of each manifest that names the paths of every artifact, those paths by directory (catalogue
// Manifest.NamedPaths, ADR 0499 clause 2). Only the build section is read: what the paths are is the catalogue's rule,
// and a manifest the catalogue would refuse for another reason is judged by the indexer, which gives it none.
func namedPathsOf(manifests map[string]string) map[string][]string {
out := map[string][]string{}
for dir, raw := range manifests {
var m struct {
Build *catalogue.Build `json:"build"`
}
if json.Unmarshal([]byte(raw), &m) != nil || m.Build == nil {
continue
}
if paths, every := (catalogue.Manifest{Build: m.Build}).NamedPaths(); every {
out[dir] = paths
}
}
return out
}
// objectsOf asks named for the objects of the named paths the manifests give at sha, and answers none when no manifest
// names paths. A forge that cannot say is an error.
func objectsOf(owner, repo, sha string, manifests map[string]string, named Named) (map[string]map[string]string, error) {
paths := namedPathsOf(manifests)
if len(paths) == 0 || named == nil {
return nil, nil
}
objects, err := named(owner, repo, sha, paths)
if err != nil {
return nil, fmt.Errorf("the objects of the named paths of %s: %w", dirsOf(paths), err)
}
for dir, want := range paths {
for _, p := range want {
if objects[dir][p] == "" {
return nil, fmt.Errorf("the forge named no object for the named path %q of %q", p, dir)
}
}
}
return objects, nil
}
func dirsOf(paths map[string][]string) []string {
var dirs []string
for d := range paths {
dirs = append(dirs, d)
}
slices.Sort(dirs)
return dirs
}