The indexer hears the runner's run-started and pipeline-ended on their own streams and writes candidates.run-<id>: one pull per member, its repository and directory from its registration, its manifest and fingerprint from a take-in of its commit read through the seat git, over its branch's revision view when its registration watches the branch, else the trunk's. The state runs keeps each run's members and ended modules, so a restart between two ends still drops the candidate. The try candidates, the checker's checks consumer, checker_tries and the three try tools go; IsTryGroup takes run-<id> beside try-<digits>. Builds: design 47 G §64, §190, §321, §66, A-160, A-174 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
76 lines
2.9 KiB
Go
76 lines
2.9 KiB
Go
package meshcatalogclient
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"fmt"
|
|
"regexp"
|
|
"sort"
|
|
"strings"
|
|
|
|
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
|
"git.novox.be/novox/mesh-sdk/go/keys"
|
|
)
|
|
|
|
// FingerprintSet is the `fpset` of a candidate's pull requests: the first 12 hex digits of the sha256 over the lines
|
|
// `<module>=<fp2>` or `<module>=none:<reason>` of every module with an entry in a pull's fps, sorted and joined by a newline,
|
|
// so it is the same for every order and changes with any fingerprint or reason. A manifest digest does not enter: the
|
|
// fingerprint already covers the manifest. It is the empty string when no pull request carries a fingerprint. The checker
|
|
// keys its verdict by it.
|
|
func FingerprintSet(pulls []seat.CandidatesByGroupValuePullsItem) string {
|
|
lines := map[string]bool{}
|
|
for _, p := range pulls {
|
|
for module, m := range p.Fps {
|
|
if m.Fp2 != "" {
|
|
lines[module+"="+m.Fp2] = true
|
|
} else {
|
|
lines[module+"=none:"+m.None2] = true
|
|
}
|
|
}
|
|
}
|
|
if len(lines) == 0 {
|
|
return ""
|
|
}
|
|
all := make([]string, 0, len(lines))
|
|
for l := range lines {
|
|
all = append(all, l)
|
|
}
|
|
sort.Strings(all)
|
|
sum := sha256.Sum256([]byte(strings.Join(all, "\n")))
|
|
return hex.EncodeToString(sum[:])[:12]
|
|
}
|
|
|
|
// CandidatesKey is the key, in the state candidates, of a group: `<group>` escaped (keys.EscapeName), the branch name the
|
|
// group's pull requests share (a slash is allowed); a lone pull request is a group of one under its branch name.
|
|
func CandidatesKey(group string) (string, error) {
|
|
if group == "" {
|
|
return "", fmt.Errorf("meshcatalogclient: the group name is empty")
|
|
}
|
|
return seat.CandidatesByGroupKey(keys.EscapeName(group)), nil
|
|
}
|
|
|
|
// ParseCandidatesKey is the inverse of CandidatesKey.
|
|
func ParseCandidatesKey(key string) (string, error) {
|
|
part, ok := seat.ParseCandidatesByGroupKey(key)
|
|
if !ok {
|
|
return "", fmt.Errorf("meshcatalogclient: %q is not a candidates key", key)
|
|
}
|
|
group, err := keys.UnescapeName(part)
|
|
if err != nil {
|
|
return "", fmt.Errorf("meshcatalogclient: %q is not a candidates key: %w", key, err)
|
|
}
|
|
return group, nil
|
|
}
|
|
|
|
var tryGroupOK = regexp.MustCompile(`^(try-[0-9]{1,20}|run-[A-Za-z0-9_-]{1,64})$`)
|
|
|
|
// IsTryGroup says a candidates key is the group of a whole try, try-<digits>, which is also the try's id, or of a run on
|
|
// request, run-<id> (design 47 G A-160): the indexer makes the candidate of a run from the runner's run-started, and the
|
|
// checker judges neither as a pull request's check.
|
|
func IsTryGroup(key string) bool { return tryGroupOK.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; a reader that waits for a try's candidate takes one that still says it as not yet the
|
|
// candidate of the heads previewed.
|
|
const NoneNoPreview = "no merge preview is computed"
|