Adding upstream version 3.10.8.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
37e9b6d587
commit
03bfe4079e
356 changed files with 28857 additions and 0 deletions
73
forges/helpers/pullrequest/helper.go
Normal file
73
forges/helpers/pullrequest/helper.go
Normal file
|
@ -0,0 +1,73 @@
|
|||
// Copyright Earl Warren <contact@earl-warren.org>
|
||||
// Copyright Loïc Dachary <loic@dachary.org>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package pullrequest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"code.forgejo.org/f3/gof3/v3/f3"
|
||||
helpers_repository "code.forgejo.org/f3/gof3/v3/forges/helpers/repository"
|
||||
"code.forgejo.org/f3/gof3/v3/id"
|
||||
"code.forgejo.org/f3/gof3/v3/logger"
|
||||
f3_tree "code.forgejo.org/f3/gof3/v3/tree/f3"
|
||||
"code.forgejo.org/f3/gof3/v3/tree/generic"
|
||||
)
|
||||
|
||||
type Interface interface {
|
||||
Upsert(context.Context) id.NodeID
|
||||
Get(context.Context) bool
|
||||
}
|
||||
|
||||
type prInterface interface {
|
||||
logger.MessageInterface
|
||||
f3_tree.PullRequestDriverInterface
|
||||
GetNode() generic.NodeInterface
|
||||
SetFetchFunc(func(ctx context.Context, url, ref string))
|
||||
ToFormat() f3.Interface
|
||||
}
|
||||
|
||||
type helper struct {
|
||||
pr prInterface
|
||||
r helpers_repository.Interface
|
||||
}
|
||||
|
||||
func (o *helper) getRepository(ctx context.Context) helpers_repository.Interface {
|
||||
if o.r == nil {
|
||||
project := f3_tree.GetFirstNodeKind(o.pr.GetNode(), f3_tree.KindProject)
|
||||
r := project.Find(generic.NewPathFromString("repositories/vcs"))
|
||||
if r == generic.NilNode {
|
||||
panic(fmt.Errorf("no repository found for %s", project.GetCurrentPath()))
|
||||
}
|
||||
o.r = r.GetDriver().(f3_tree.ForgeDriverInterface).GetHelper().(helpers_repository.Interface)
|
||||
}
|
||||
return o.r
|
||||
}
|
||||
|
||||
func (o *helper) Get(ctx context.Context) bool {
|
||||
headURL := o.getRepository(ctx).GetRepositoryURL()
|
||||
headRef := o.pr.GetPullRequestHead()
|
||||
o.pr.SetFetchFunc(func(ctx context.Context, url, ref string) {
|
||||
helpers_repository.GitMirrorRef(ctx, o.pr, headURL, headRef, url, ref)
|
||||
})
|
||||
return true
|
||||
}
|
||||
|
||||
func (o *helper) Upsert(ctx context.Context) id.NodeID {
|
||||
f := o.pr.ToFormat().(*f3.PullRequest)
|
||||
if f.FetchFunc != nil {
|
||||
pushURL := o.getRepository(ctx).GetRepositoryPushURL()
|
||||
for _, pushRef := range o.pr.GetPullRequestPushRefs() {
|
||||
f.FetchFunc(ctx, pushURL, pushRef)
|
||||
}
|
||||
}
|
||||
return o.pr.GetNode().GetID()
|
||||
}
|
||||
|
||||
func NewHelper(ctx context.Context, pr prInterface) Interface {
|
||||
return &helper{
|
||||
pr: pr,
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue