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 }