Files
mesh-delivery/modules/mesh-delivery-forge-bridge/internal/bridge/forgemade.go
T
jschoubben 3a4768ab43 FB6a: the forge bridge reads trees, files, pulls and tags through the seat git and hears its pull and delete events
Taken over from the join's 473f9323, 5f40d230, 159a679b; the events are the seat's pull-updated, pull-merged, pull-closed and forge-delete.

Builds: design 47 G §252, §310, §312, §317

Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ
2026-11-11 11:48:36 +01:00

46 lines
2.1 KiB
Go

package bridge
import (
"context"
"fmt"
git "git.novox.be/novox/mesh-delivery/contracts/go/seats/git"
)
// ForgePull is a pull request as the forge itself says it: what the bridge needs of a merge made on the forge, not
// through the gate (a recovery merge or the operator's own, which the gate holds no merge of; issue 1966).
type ForgePull struct {
Number int
Branch string // the pull request's head branch
Head string // the head commit
Merge string // the merge commit into the trunk
}
// ForgeMade reads, through the seat `git`'s verb pull, the merged pull request whose merge commit is merge: by number
// when number is given (its merge commit must then equal merge), else by the merge commit. A pull request not merged,
// merged into another branch than the trunk, or merged at another commit is refused.
func ForgeMade(ctx context.Context, call Caller, owner, repo string, number int, merge string) (ForgePull, error) {
in := git.PullInput{Repository: repository(owner, repo), MergeCommit: merge}
if number > 0 {
in = git.PullInput{Repository: repository(owner, repo), Number: int64(number)}
}
a, err := askGit[git.PullAnswer](ctx, call, git.VerbPull, in)
if err != nil {
return ForgePull{}, err
}
p := a.Pull
switch {
case p == nil || p.Number == 0:
return ForgePull{}, fmt.Errorf("the pull request of %s at %s: %w", in.Repository, merge, errNoAnswer)
case p.State != git.PullStateMerged:
return ForgePull{}, fmt.Errorf("the forge says the pull request %s#%d is %s, not merged", in.Repository, p.Number, p.State)
case p.MergeCommit != merge:
return ForgePull{}, fmt.Errorf("the forge says %s#%d was merged at %s, not at %s", in.Repository, p.Number, p.MergeCommit, merge)
case p.Base != Trunk:
return ForgePull{}, fmt.Errorf("the forge says %s#%d was merged into %s, not the trunk %s", in.Repository, p.Number, p.Base, Trunk)
case p.Branch == "":
return ForgePull{}, fmt.Errorf("the forge gives no head branch for %s#%d", in.Repository, p.Number)
}
return ForgePull{Number: int(p.Number), Branch: p.Branch, Head: p.Head, Merge: p.MergeCommit}, nil
}