Design 32 (A config value renamed): the checker invokes seat:mesh-config.renames, never the module. A change bringing renamed-from to a holder that serves no renames (nothing answers the optional verb) is refused naming it; dropping a renamed-from while its window is open is refused naming the nodes holding it open; a check that cannot ask fails, saying so. The pull request's trunk and head manifests are read once for this and for the series changes (manifestPair). Rows in TestTheIndexersJudgeJudgesTheChangesManifests with the verb faked from the seat's definition (its fixture's answer): not served, served, open on g14, closed, an ask that fails, no seat to ask; the four refusals failed first. Manifest row for the invokes. Claude-Session: https://claude.ai/code/session_01JG73KJNrH5EgFXMKKYSrig
111 lines
3.6 KiB
Go
111 lines
3.6 KiB
Go
package check
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"slices"
|
|
"strings"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
|
)
|
|
|
|
// A change of a package series is named in the verdict, so the review of the change sees it (design 32 *A package, its
|
|
// series*; DLV-C4): for each module a pull request touches, every artifact both its trunk manifest and its head's
|
|
// manifest declare whose series differs, as `<module>/<artifact> series <trunk> → <head>`. An artifact that names none
|
|
// is in catalogue.DefaultSeries. A manifest that cannot be read is said in the same words, never left out.
|
|
|
|
// seriesChanges names, on the case per pull request, each change of an artifact's series the pull request makes.
|
|
func (st *state) seriesChanges(ctx context.Context) {
|
|
for _, p := range st.c.Pulls {
|
|
var words []string
|
|
for _, module := range p.Modules {
|
|
was, now, ok, err := st.manifestPair(ctx, p, module)
|
|
if err != nil {
|
|
words = append(words, fmt.Sprintf("%s: its series not compared (%v)", module, err))
|
|
continue
|
|
}
|
|
if ok {
|
|
words = append(words, seriesMoved(module, was, now)...)
|
|
}
|
|
}
|
|
if len(words) > 0 {
|
|
st.c.series(pullKey(p), words)
|
|
}
|
|
}
|
|
}
|
|
|
|
// manifestPair is a touched module's trunk manifest and its manifest at the pull request's head: the head's by the digest
|
|
// its candidate names, else read from the forge at the head. ok is false when the module is new on the pull request,
|
|
// unchanged, or not read here.
|
|
func (st *state) manifestPair(ctx context.Context, p Pull, module string) (was, now catalogue.Manifest, ok bool, err error) {
|
|
if st.j.Read == nil || st.j.Manifests == nil {
|
|
return was, now, false, nil
|
|
}
|
|
trunk := st.j.Manifests.ManifestDigests()[module]
|
|
digest := p.Fps[module].Manifest
|
|
if trunk == "" || digest == trunk {
|
|
return was, now, false, nil
|
|
}
|
|
if was, err = st.j.Read.Manifest(ctx, trunk); err != nil {
|
|
return was, now, false, fmt.Errorf("the trunk's manifest not read: %w", err)
|
|
}
|
|
switch {
|
|
case digest != "":
|
|
if now, err = st.j.Read.Manifest(ctx, digest); err != nil {
|
|
return was, now, false, fmt.Errorf("the head's manifest not read: %w", err)
|
|
}
|
|
case st.j.Forge != nil:
|
|
var found bool
|
|
if now, _, found, err = st.manifestAtHead(ctx, p, module); err != nil || !found {
|
|
return was, now, false, err
|
|
}
|
|
default:
|
|
return was, now, false, nil
|
|
}
|
|
return was, now, true, nil
|
|
}
|
|
|
|
// seriesMoved are the artifacts of module whose series the head's manifest changes from the trunk's.
|
|
func seriesMoved(module string, was, now catalogue.Manifest) []string {
|
|
if was.Build == nil || now.Build == nil {
|
|
return nil
|
|
}
|
|
before := map[string]string{}
|
|
for _, a := range was.Build.Artifacts {
|
|
before[a.Name] = a.SeriesOf()
|
|
}
|
|
var out []string
|
|
for _, a := range now.Build.Artifacts {
|
|
if old, ok := before[a.Name]; ok && old != a.SeriesOf() {
|
|
out = append(out, fmt.Sprintf("%s/%s series %s → %s", module, a.Name, old, a.SeriesOf()))
|
|
}
|
|
}
|
|
slices.Sort(out)
|
|
return out
|
|
}
|
|
|
|
// series keeps, of a pull request (pullKey), the words of the series changes it makes.
|
|
func (c *Case) series(key string, words []string) {
|
|
c.notesMu.Lock()
|
|
defer c.notesMu.Unlock()
|
|
if c.seriesOf == nil {
|
|
c.seriesOf = map[string][]string{}
|
|
}
|
|
c.seriesOf[key] = words
|
|
}
|
|
|
|
// Series are the series changes a pull request (pullKey) makes, as the check named them; none when it makes none.
|
|
func (c *Case) Series(key string) []string {
|
|
c.notesMu.Lock()
|
|
defer c.notesMu.Unlock()
|
|
return slices.Clone(c.seriesOf[key])
|
|
}
|
|
|
|
// seriesWords is a pull request's series changes for its status line.
|
|
func seriesWords(c *Case, p Pull) string {
|
|
if c == nil {
|
|
return ""
|
|
}
|
|
return strings.Join(c.Series(pullKey(p)), ", ")
|
|
}
|