68 lines
2.3 KiB
Go
68 lines
2.3 KiB
Go
//go:build integration
|
|
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
sdk "git.novox.be/novox/mesh-sdk/go/delivery"
|
|
)
|
|
|
|
// A pull request and the head the checker judged, for checkPasses.
|
|
type judgedPull struct {
|
|
repository string
|
|
number int
|
|
head string
|
|
}
|
|
|
|
// checkPasses says on the bus what the mesh says of heads the checker passed (issue 1302, ADR 0447): its verdict at these
|
|
// heads in its verdicts bucket, each pull request's base requiring mesh/check and the forge's word that its bridge set it, the
|
|
// line naming the head and the trunk commit it judged. The gate follows no verdict of the controller (issue 1318).
|
|
func (b *testBus) checkPasses(t *testing.T, rt *runtime, group, trunk string, pulls ...judgedPull) {
|
|
t.Helper()
|
|
var heads []sdk.Head
|
|
trunks := map[string]string{}
|
|
for _, p := range pulls {
|
|
heads = append(heads, sdk.Head{Repository: p.repository, Number: p.number, Head: p.head})
|
|
trunks[p.repository] = trunk
|
|
}
|
|
hash, err := sdk.HeadsHash(heads)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
verdict, _ := json.Marshal(map[string]any{"v": 1, "group": group, "heads": hash, "trunk": trunks, "state": "pass"})
|
|
if _, err := b.kvs[checkerVerdicts].Put(context.Background(), group+"."+hash, verdict); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, p := range pulls {
|
|
owner, repo := splitRepository(p.repository)
|
|
line := "pass " + p.head[:12] + " on " + trunk[:12] + " | unit 3 run, 0 kept"
|
|
rt.mu.Lock()
|
|
found := false
|
|
for i := range rt.openPulls {
|
|
o := &rt.openPulls[i]
|
|
if o.Owner == owner && o.Repo == repo && o.Number == p.number {
|
|
o.Required, o.Statuses, o.Checks, found = []string{ctxCheck}, []string{ctxCheck}, map[string]HeadCheck{ctxCheck: {State: "success", Description: line}}, true
|
|
}
|
|
}
|
|
if !found {
|
|
rt.openPulls = append(rt.openPulls, OpenPull{Owner: owner, Repo: repo, Number: p.number, Base: "main", HeadSHA: p.head,
|
|
Required: []string{ctxCheck}, Statuses: []string{ctxCheck}, Checks: map[string]HeadCheck{ctxCheck: {State: "success", Description: line}}})
|
|
}
|
|
rt.mu.Unlock()
|
|
b.publish(t, "mesh.mod.gitea.event.forge.status", map[string]any{"owner": owner, "repo": repo, "sha": p.head,
|
|
"context": ctxCheck, "state": "success", "description": line})
|
|
}
|
|
}
|
|
|
|
func splitRepository(r string) (owner, repo string) {
|
|
for i := range r {
|
|
if r[i] == '/' {
|
|
return r[:i], r[i+1:]
|
|
}
|
|
}
|
|
return "", r
|
|
}
|