The bridge watches the registrations' branches by origin (a first view of registrations, then registration-changed), before the first registration the gate's source's (source-moved); no branch is named in its code, Trunk goes. Every move is heard on the seat git's branch-moved through the bridge's durable on SEAT_git_branch-moved, its head read by the seat's verb branch, never the event's: merged with its pull request and `base` (the watched branch) when the seat's pull names the head a pull request's merge, else `pushed` with branch, head and `before`, both with the take-in inputs at the head. The last head written per watched branch is kept in the state heads under branch.<owner>.<name>.<escaped branch>, so a move heard twice writes once, and each watched branch's head is read at the start and when a branch is registered. A move of an unprotected branch writes nothing. pull.merged into a watched branch writes nothing (its message is the move's); the forge-made merge's trunk filter goes. Builds: design 47 G §4, §7, §11, §20, §41, §507, §509, §532, §714, A-227, A-236 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
47 lines
2.0 KiB
Go
47 lines
2.0 KiB
Go
package bridge
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
git "git.novox.be/novox/mesh-delivery/modules/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
|
|
Base string // the branch it was merged into
|
|
}
|
|
|
|
// 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, 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 == "":
|
|
return ForgePull{}, fmt.Errorf("the forge gives no base branch for %s#%d", in.Repository, p.Number)
|
|
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, Base: p.Base}, nil
|
|
}
|