B2: on every branch-moved of a watched branch, and at its start for every watched branch's head, the bridge reads the head through the seat git's verb branch, as a kept call that waits on the holder's return while the branch is watched, and writes one head-moved (repository, branch, head, before the head held in its state heads, start) on its stream forge; a head equal to the one held writes nothing. It reads no pull request, no tree, no file and no protection: the merged and pushed messages, their inputs and the state inputs, the call of git.pull, the finding branch-unprotected with its held finding writer, and the ten-second redelivery go. A move whose head cannot be read is left unacknowledged for the bus to deliver again. B3: the pull-message path (Convert, the open pull requests at start and reconnect, the forge-delete message), the groups (internal/groups' group part, forge.group.merged, end-asks, bridge_groups, bridge_group_end_again), bridge_merged_message with the forge-made reader, the checker's owed and the merge act of a switched key (with the switch's bookkeeping read) go, with their consumes, invokes, states and requires. The gate's owed path stays (H-A-71), its catch-up from the gate's verb groups gone with that verb. The two meet in main.go and the package compiles only with both, as it did not since B1. The unit suites pass; the whole test (integration) is rewritten in B4. Builds: design 47 H §739, §764 (the forge bridge; the branch protection); lead answers H-A-23, H-A-27, H-A-48, H-A-71 Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
119 lines
4.6 KiB
Go
119 lines
4.6 KiB
Go
package bridge
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
|
|
git "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/git"
|
|
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-forge-bridge/forgemsg"
|
|
)
|
|
|
|
// OwedCall is one act owed to the forge as the seat git's verb that performs it: the seat that said it (Of), the act's
|
|
// id, and the verb with its input (novox/hq design 47 *What the gate owes the forge*). Every verb is safe to repeat at
|
|
// the forge: a status and the view replace what stands, and a comment and a note line carry the id, which the seat's holder skips when it already holds it.
|
|
type OwedCall struct {
|
|
Of string
|
|
ID string
|
|
Act string
|
|
Repository string
|
|
Number int
|
|
Verb string
|
|
Input any
|
|
}
|
|
|
|
// ErrUndecodable is an owed event the bridge cannot read: it is said as owed.ended `undecodable`, never only logged.
|
|
var ErrUndecodable = errors.New("an owed act the bridge cannot read")
|
|
|
|
func undecodable(why string, args ...any) error {
|
|
return fmt.Errorf("%w: %s", ErrUndecodable, fmt.Sprintf(why, args...))
|
|
}
|
|
|
|
// GateOwed reads the seat mesh-delivery's event owed into the seat git's verb that performs it.
|
|
func GateOwed(data []byte) (OwedCall, error) {
|
|
var o seat.OwedEvent
|
|
if err := json.Unmarshal(data, &o); err != nil {
|
|
return OwedCall{}, undecodable("the gate's owed is not json: %v", err)
|
|
}
|
|
c := OwedCall{Of: seat.Seat, ID: o.ID, Act: o.Act, Repository: o.Repository, Number: int(o.Number)}
|
|
if err := c.common(o.Head); err != nil {
|
|
return c, err
|
|
}
|
|
commit := o.Commit
|
|
if commit == "" {
|
|
commit = o.Head
|
|
}
|
|
needsPull := func() error {
|
|
if o.Number <= 0 {
|
|
return undecodable("the owed %s %s names no pull request", o.Act, o.ID)
|
|
}
|
|
return nil
|
|
}
|
|
switch o.Act {
|
|
case seat.OwedActStatus:
|
|
if o.Context == "" || o.State == "" {
|
|
return c, undecodable("the owed status %s names no context or state", o.ID)
|
|
}
|
|
c.Verb, c.Input = git.VerbStatus, git.StatusInput{ID: o.ID, Repository: o.Repository, Commit: commit, Context: o.Context,
|
|
State: o.State, Description: o.Description, Target: o.Target}
|
|
case seat.OwedActView:
|
|
if err := needsPull(); err != nil {
|
|
return c, err
|
|
}
|
|
c.Verb, c.Input = git.VerbView, git.ViewInput{ID: o.ID, Repository: o.Repository, Number: o.Number, Text: o.Text}
|
|
case seat.OwedActComment:
|
|
if err := needsPull(); err != nil {
|
|
return c, err
|
|
}
|
|
c.Verb, c.Input = git.VerbComment, git.CommentInput{ID: o.ID, Repository: o.Repository, Number: o.Number, Text: o.Text}
|
|
case seat.OwedActNote:
|
|
if o.Line == "" {
|
|
return c, undecodable("the owed note line %s says no line", o.ID)
|
|
}
|
|
c.Verb, c.Input = git.VerbNote, git.NoteInput{ID: o.ID, Repository: o.Repository, Commit: commit, Line: o.Line}
|
|
default:
|
|
return c, undecodable("the owed %s is the act %q, none the seat git performs", o.ID, o.Act)
|
|
}
|
|
return c, nil
|
|
}
|
|
|
|
func (c OwedCall) common(head string) error {
|
|
switch {
|
|
case c.ID == "":
|
|
return undecodable("an owed %s of %s names no id", c.Act, c.Repository)
|
|
case c.Repository == "":
|
|
return undecodable("the owed %s names no repository", c.ID)
|
|
case !sha40.MatchString(head):
|
|
return undecodable("the owed %s names the head %q, not 40 hex digits", c.ID, head)
|
|
}
|
|
if _, _, err := splitRepository(c.Repository); err != nil {
|
|
return undecodable("the owed %s: %v", c.ID, err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Outcome is what an act's call of the seat git came to, as owed.ended says it: performed when the forge holds the act
|
|
// (done now, or its id already held); refused with the forge's own words when the seat answers an error of the kind
|
|
// refused; could not be performed with the error when the seat did not answer, answered an error of the
|
|
// kind failed, or answered what the contract cannot read.
|
|
func Outcome(raw json.RawMessage, callErr error) (outcome, words string) {
|
|
if callErr != nil {
|
|
return forgemsg.OwedCouldNotBePerformed, callErr.Error()
|
|
}
|
|
var a git.StatusAnswer // every act verb's answer (status, comment, view, note) has these fields
|
|
if err := json.Unmarshal(raw, &a); err != nil {
|
|
return forgemsg.OwedCouldNotBePerformed, "the seat git's answer is not its contract's: " + err.Error()
|
|
}
|
|
switch {
|
|
case a.Error != "" && a.ErrorKind == git.ErrorKindRefused:
|
|
return forgemsg.OwedRefused, a.Error
|
|
case a.Error != "":
|
|
// failed, or a kind the contract does not name: the forge did not do it, and did not say no
|
|
return forgemsg.OwedCouldNotBePerformed, a.Error
|
|
case a.Performed || a.Held:
|
|
return forgemsg.OwedPerformed, ""
|
|
}
|
|
return forgemsg.OwedCouldNotBePerformed, "the seat git's answer says neither performed, held nor an error: " + string(raw)
|
|
}
|