The delivery repository's contracts and SDK live under modules/ as mesh-delivery-contracts and mesh-delivery-sdk, their Go module paths renamed to match the folders (the TypeScript names already did), and every importer in mesh-delivery, mesh-catalog, mesh-host, mesh-tools and mesh-sdk follows in the same group: a design as it should be, one path per module, checked by the group's check building every importer. Builds: design 47 G §427, §88 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
79 lines
3.2 KiB
Go
79 lines
3.2 KiB
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"hash/fnv"
|
|
"strconv"
|
|
"time"
|
|
|
|
mdc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient"
|
|
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery"
|
|
"git.novox.be/novox/mesh-sdk/go/keys"
|
|
)
|
|
|
|
// The gate writes nothing to the forge: each act it owes it — the delivery's view on the pull request, a comment, a line of
|
|
// the commit's note — is said as the event owed of the seat mesh-delivery, on
|
|
// `mesh.seat.mesh-delivery.event.owed.<repository>.<number>`, under one id, which the forge bridge performs through the
|
|
// seat git and answers as owed.ended (design 47 *What the gate owes the forge*, §167). The act is kept in its delivery record's
|
|
// acts, with when it was said, before it is said, and stays there until its owed.ended is heard (A-35). A comment's act carries a
|
|
// sequence number, so two comments on one head are two acts.
|
|
|
|
// notesRef is the notes ref the commit's note is kept under.
|
|
const notesRef = "mesh-plan"
|
|
|
|
// OwedSayer says one act owed to the forge as the seat mesh-delivery's event owed.
|
|
type OwedSayer interface {
|
|
Say(o seat.Owed) error
|
|
}
|
|
|
|
// seatOwed says owed on the seat's subject, under the act's id, which the bus keeps once.
|
|
type seatOwed struct{ say SeatSay }
|
|
|
|
func (s seatOwed) Say(o seat.Owed) error {
|
|
return s.say(seat.SubjectOwed(keys.EscapeName(o.Repository), strconv.FormatInt(o.Number, 10)), o, "owed."+o.ID)
|
|
}
|
|
|
|
// actID is the id of an act owed: its key, when it was first owed and a digest of what it says, so it is the same each time
|
|
// it is said again and two acts of one key are two ids. It holds an @, which a switched act's id never holds.
|
|
func actID(key string, since time.Time, says string) string {
|
|
d := fnv.New32a()
|
|
_, _ = d.Write([]byte(says))
|
|
return key + "@" + strconv.FormatInt(since.UnixNano(), 10) + "." + strconv.FormatUint(uint64(d.Sum32()), 16)
|
|
}
|
|
|
|
// owe keeps an act in the record, with when it was said, and then says it. An act the record holds already is said again under
|
|
// its id and its first said time, never kept twice.
|
|
func (h *Holder) owe(r *Record, o seat.Owed) error {
|
|
if h.Owed == nil || h.Records == nil {
|
|
return errors.New("no seat to say owed on")
|
|
}
|
|
now := h.Now().UTC()
|
|
if had, ok := r.Acts[o.ID]; ok && had.Owed.Said != nil {
|
|
o.Said = had.Owed.Said
|
|
} else {
|
|
o.Said = &now
|
|
}
|
|
if err := h.Records.Act(r, RecordAct{ID: o.ID, Act: o.Act, Repository: o.Repository, Number: int(o.Number), Head: o.Head,
|
|
At: *o.Said, Owed: o}); err != nil {
|
|
return err
|
|
}
|
|
return h.Owed.Say(o)
|
|
}
|
|
|
|
// seatOwedOf is an act in the old form (the state owed's value) as the seat's event owed says it.
|
|
func seatOwedOf(o Owed, id, repository string, number int, head string, said *time.Time) seat.Owed {
|
|
out := seat.Owed{ID: id, Repository: repository, Number: int64(number), Head: head, Said: said, Text: o.Text}
|
|
switch o.Act {
|
|
case mdc.OwedStatus:
|
|
out.Act, out.Context, out.State, out.Description, out.Target, out.Commit = seat.OwedActStatus, o.Context, o.State, o.Text, o.Target, head
|
|
out.Text = ""
|
|
case mdc.OwedNote:
|
|
out.Act, out.Line, out.Commit, out.Text = seat.OwedActNote, o.Text, head, ""
|
|
case mdc.OwedView:
|
|
out.Act = seat.OwedActView
|
|
case mdc.OwedComment:
|
|
out.Act = seat.OwedActComment
|
|
}
|
|
return out
|
|
}
|