64 lines
2.4 KiB
Go
64 lines
2.4 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/novox/mesh-controller/internal/builder"
|
|
"github.com/novox/mesh-controller/internal/inventory"
|
|
)
|
|
|
|
// A pull request's check builds go when it closes (novox/hq ADR 0350 §5): the build seat keeps them in the artifact
|
|
// store's scratch namespace for the walk of its merge to take. **Let go of where the moment is heard**: the
|
|
// controller ends the walk answering a merge — after that walk took what it reuses — and the delivery's owner, which
|
|
// hears the forge say a pull request closed unmerged, asks the `forget-checks` verb; both let go through the store,
|
|
// as the controller's own collection does. The build seat's holders let go of anything a week old on their own,
|
|
// so a word lost here leaves a week's builds, never more.
|
|
|
|
// checkBuildsIn is the scratch namespace as the controller reaches the artifact store.
|
|
func checkBuildsIn(ctx context.Context, inv *inventory.Inventory) (builder.Scratch, error) {
|
|
shelf, err := inv.Catalogue(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
address, err := artifactStoreAddress(ctx, inv, shelf, "")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if address == "" {
|
|
return nil, errors.New("the artifact store is not on the mesh's network")
|
|
}
|
|
return builder.Registry{Address: address}, nil
|
|
}
|
|
|
|
// forgetChecks lets go of a pull request's check builds and answers what it did.
|
|
var forgetChecks = func(ctx context.Context, inv *inventory.Inventory, pull builder.PullRef) (string, error) {
|
|
scratch, err := checkBuildsIn(ctx, inv)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
n, err := scratch.Forget(ctx, pull)
|
|
if err != nil {
|
|
return "", fmt.Errorf("%s: %d check(s)' builds let go of, and not all: %w", pull, n, err)
|
|
}
|
|
return fmt.Sprintf("%s: %d check(s)' builds let go of", pull, n), nil
|
|
}
|
|
|
|
// forgetChecksOfWalk lets go, on the save that ends a walk, of the check builds of every pull request whose merge
|
|
// it answers: the walk took what it reuses. Said, never fatal.
|
|
func forgetChecksOfWalk(ctx context.Context, inv *inventory.Inventory, p inventory.Plan) {
|
|
if p.WalkSaid != inventory.WalkEnded || p.Delivery == nil {
|
|
return
|
|
}
|
|
for _, pull := range pullsOfWalk(&p) {
|
|
said, err := forgetChecks(ctx, inv, builder.PullRef{Owner: pull.Owner, Repo: pull.Repo, Number: pull.Number})
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "%s: its check builds stay until the week's sweep: %v\n", p.ID, err)
|
|
continue
|
|
}
|
|
fmt.Printf("%s: %s\n", p.ID, said)
|
|
}
|
|
}
|