mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-22 12:54:53 -05:00
[F3] add GetLocalMatchingRemote with a default implementation
This commit is contained in:
parent
39ac5233ff
commit
0a22015039
15 changed files with 80 additions and 30 deletions
|
@ -82,7 +82,7 @@ func (o *Asset) FromFormat(asset *format.ReleaseAsset) {
|
|||
}
|
||||
|
||||
type AssetProvider struct {
|
||||
g *Forgejo
|
||||
BaseProvider
|
||||
}
|
||||
|
||||
func (o *AssetProvider) ToFormat(ctx context.Context, asset *Asset) *format.ReleaseAsset {
|
||||
|
|
54
services/f3/driver/base.go
Normal file
54
services/f3/driver/base.go
Normal file
|
@ -0,0 +1,54 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package driver
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"lab.forgefriends.org/friendlyforgeformat/gof3/forges/common"
|
||||
"lab.forgefriends.org/friendlyforgeformat/gof3/format"
|
||||
)
|
||||
|
||||
type BaseProvider struct {
|
||||
g *Forgejo
|
||||
}
|
||||
|
||||
func (o *BaseProvider) SetForgejo(g *Forgejo) {
|
||||
o.g = g
|
||||
}
|
||||
|
||||
type BaseProviderConstraint[Provider any] interface {
|
||||
*Provider
|
||||
SetForgejo(*Forgejo)
|
||||
}
|
||||
|
||||
func NewProvider[T any, TPtr BaseProviderConstraint[T]](g *Forgejo) TPtr {
|
||||
var p TPtr
|
||||
p = new(T)
|
||||
p.SetForgejo(g)
|
||||
return p
|
||||
}
|
||||
|
||||
func (o *BaseProvider) GetLocalMatchingRemote(ctx context.Context, format format.Interface, parents ...common.ContainerObjectInterface) (string, bool) {
|
||||
return "", false
|
||||
}
|
||||
|
||||
type BaseProviderWithProjectProvider struct {
|
||||
BaseProvider
|
||||
project *ProjectProvider
|
||||
}
|
||||
|
||||
func (o *BaseProviderWithProjectProvider) SetProjectProvider(project *ProjectProvider) {
|
||||
o.project = project
|
||||
}
|
||||
|
||||
type BaseProviderWithProjectProviderConstraint[Provider any] interface {
|
||||
BaseProviderConstraint[Provider]
|
||||
SetProjectProvider(project *ProjectProvider)
|
||||
}
|
||||
|
||||
func NewProviderWithProjectProvider[T any, TPtr BaseProviderWithProjectProviderConstraint[T]](g *Forgejo, project *ProjectProvider) TPtr {
|
||||
p := NewProvider[T, TPtr](g)
|
||||
p.SetProjectProvider(project)
|
||||
return p
|
||||
}
|
|
@ -82,7 +82,7 @@ func (o *Comment) FromFormat(comment *format.Comment) {
|
|||
}
|
||||
|
||||
type CommentProvider struct {
|
||||
g *Forgejo
|
||||
BaseProvider
|
||||
}
|
||||
|
||||
func (o *CommentProvider) ToFormat(ctx context.Context, comment *Comment) *format.Comment {
|
||||
|
|
|
@ -74,31 +74,31 @@ func (o *Forgejo) GetProvider(name string, parent common.ProviderInterface) comm
|
|||
}
|
||||
switch name {
|
||||
case driver.ProviderUser:
|
||||
return driver.NewProvider[UserProvider, *UserProvider, User, *User, format.User, *format.User](driver.ProviderUser, &UserProvider{g: o})
|
||||
return driver.NewProvider[UserProvider, *UserProvider, User, *User, format.User, *format.User](driver.ProviderUser, NewProvider[UserProvider](o))
|
||||
case driver.ProviderProject:
|
||||
return driver.NewProviderWithParentOne[ProjectProvider, *ProjectProvider, Project, *Project, format.Project, *format.Project, User, *User](driver.ProviderProject, &ProjectProvider{g: o})
|
||||
return driver.NewProviderWithParentOne[ProjectProvider, *ProjectProvider, Project, *Project, format.Project, *format.Project, User, *User](driver.ProviderProject, NewProvider[ProjectProvider, *ProjectProvider](o))
|
||||
case driver.ProviderMilestone:
|
||||
return driver.NewProviderWithParentOneTwo[MilestoneProvider, *MilestoneProvider, Milestone, *Milestone, format.Milestone, *format.Milestone, User, *User, Project, *Project](driver.ProviderMilestone, &MilestoneProvider{g: o, project: parentImpl.(*ProjectProvider)})
|
||||
return driver.NewProviderWithParentOneTwo[MilestoneProvider, *MilestoneProvider, Milestone, *Milestone, format.Milestone, *format.Milestone, User, *User, Project, *Project](driver.ProviderMilestone, NewProviderWithProjectProvider[MilestoneProvider](o, parentImpl.(*ProjectProvider)))
|
||||
case driver.ProviderIssue:
|
||||
return driver.NewProviderWithParentOneTwo[IssueProvider, *IssueProvider, Issue, *Issue, format.Issue, *format.Issue, User, *User, Project, *Project](driver.ProviderIssue, &IssueProvider{g: o, project: parentImpl.(*ProjectProvider)})
|
||||
return driver.NewProviderWithParentOneTwo[IssueProvider, *IssueProvider, Issue, *Issue, format.Issue, *format.Issue, User, *User, Project, *Project](driver.ProviderIssue, NewProviderWithProjectProvider[IssueProvider](o, parentImpl.(*ProjectProvider)))
|
||||
case driver.ProviderPullRequest:
|
||||
return driver.NewProviderWithParentOneTwo[PullRequestProvider, *PullRequestProvider, PullRequest, *PullRequest, format.PullRequest, *format.PullRequest, User, *User, Project, *Project](driver.ProviderPullRequest, &PullRequestProvider{g: o, project: parentImpl.(*ProjectProvider)})
|
||||
return driver.NewProviderWithParentOneTwo[PullRequestProvider, *PullRequestProvider, PullRequest, *PullRequest, format.PullRequest, *format.PullRequest, User, *User, Project, *Project](driver.ProviderPullRequest, NewProviderWithProjectProvider[PullRequestProvider](o, parentImpl.(*ProjectProvider)))
|
||||
case driver.ProviderReview:
|
||||
return driver.NewProviderWithParentOneTwoThree[ReviewProvider, *ReviewProvider, Review, *Review, format.Review, *format.Review, User, *User, Project, *Project, PullRequest, *PullRequest](driver.ProviderReview, &ReviewProvider{g: o})
|
||||
return driver.NewProviderWithParentOneTwoThree[ReviewProvider, *ReviewProvider, Review, *Review, format.Review, *format.Review, User, *User, Project, *Project, PullRequest, *PullRequest](driver.ProviderReview, NewProvider[ReviewProvider](o))
|
||||
case driver.ProviderRepository:
|
||||
return driver.NewProviderWithParentOneTwo[RepositoryProvider, *RepositoryProvider, Repository, *Repository, format.Repository, *format.Repository, User, *User, Project, *Project](driver.ProviderRepository, &RepositoryProvider{g: o})
|
||||
return driver.NewProviderWithParentOneTwo[RepositoryProvider, *RepositoryProvider, Repository, *Repository, format.Repository, *format.Repository, User, *User, Project, *Project](driver.ProviderRepository, NewProvider[RepositoryProvider](o))
|
||||
case driver.ProviderTopic:
|
||||
return driver.NewProviderWithParentOneTwo[TopicProvider, *TopicProvider, Topic, *Topic, format.Topic, *format.Topic, User, *User, Project, *Project](driver.ProviderTopic, &TopicProvider{g: o})
|
||||
return driver.NewProviderWithParentOneTwo[TopicProvider, *TopicProvider, Topic, *Topic, format.Topic, *format.Topic, User, *User, Project, *Project](driver.ProviderTopic, NewProvider[TopicProvider](o))
|
||||
case driver.ProviderLabel:
|
||||
return driver.NewProviderWithParentOneTwo[LabelProvider, *LabelProvider, Label, *Label, format.Label, *format.Label, User, *User, Project, *Project](driver.ProviderLabel, &LabelProvider{g: o, project: parentImpl.(*ProjectProvider)})
|
||||
return driver.NewProviderWithParentOneTwo[LabelProvider, *LabelProvider, Label, *Label, format.Label, *format.Label, User, *User, Project, *Project](driver.ProviderLabel, NewProviderWithProjectProvider[LabelProvider](o, parentImpl.(*ProjectProvider)))
|
||||
case driver.ProviderRelease:
|
||||
return driver.NewProviderWithParentOneTwo[ReleaseProvider, *ReleaseProvider, Release, *Release, format.Release, *format.Release, User, *User, Project, *Project](driver.ProviderRelease, &ReleaseProvider{g: o})
|
||||
return driver.NewProviderWithParentOneTwo[ReleaseProvider, *ReleaseProvider, Release, *Release, format.Release, *format.Release, User, *User, Project, *Project](driver.ProviderRelease, NewProvider[ReleaseProvider](o))
|
||||
case driver.ProviderAsset:
|
||||
return driver.NewProviderWithParentOneTwoThree[AssetProvider, *AssetProvider, Asset, *Asset, format.ReleaseAsset, *format.ReleaseAsset, User, *User, Project, *Project, Release, *Release](driver.ProviderAsset, &AssetProvider{g: o})
|
||||
return driver.NewProviderWithParentOneTwoThree[AssetProvider, *AssetProvider, Asset, *Asset, format.ReleaseAsset, *format.ReleaseAsset, User, *User, Project, *Project, Release, *Release](driver.ProviderAsset, NewProvider[AssetProvider](o))
|
||||
case driver.ProviderComment:
|
||||
return driver.NewProviderWithParentOneTwoThreeInterface[CommentProvider, *CommentProvider, Comment, *Comment, format.Comment, *format.Comment, User, *User, Project, *Project](driver.ProviderComment, &CommentProvider{g: o})
|
||||
return driver.NewProviderWithParentOneTwoThreeInterface[CommentProvider, *CommentProvider, Comment, *Comment, format.Comment, *format.Comment, User, *User, Project, *Project](driver.ProviderComment, NewProvider[CommentProvider](o))
|
||||
case driver.ProviderReaction:
|
||||
return driver.NewProviderWithParentOneTwoRest[ReactionProvider, *ReactionProvider, Reaction, *Reaction, format.Reaction, *format.Reaction, User, *User, Project, *Project](driver.ProviderReaction, &ReactionProvider{g: o})
|
||||
return driver.NewProviderWithParentOneTwoRest[ReactionProvider, *ReactionProvider, Reaction, *Reaction, format.Reaction, *format.Reaction, User, *User, Project, *Project](driver.ProviderReaction, NewProvider[ReactionProvider](o))
|
||||
default:
|
||||
panic(fmt.Sprintf("unknown provider name %s", name))
|
||||
}
|
||||
|
|
|
@ -125,8 +125,7 @@ func (o *Issue) FromFormat(issue *format.Issue) {
|
|||
}
|
||||
|
||||
type IssueProvider struct {
|
||||
g *Forgejo
|
||||
project *ProjectProvider
|
||||
BaseProviderWithProjectProvider
|
||||
}
|
||||
|
||||
func (o *IssueProvider) ToFormat(ctx context.Context, issue *Issue) *format.Issue {
|
||||
|
|
|
@ -76,8 +76,7 @@ func (o *Label) FromFormat(label *format.Label) {
|
|||
}
|
||||
|
||||
type LabelProvider struct {
|
||||
g *Forgejo
|
||||
project *ProjectProvider
|
||||
BaseProviderWithProjectProvider
|
||||
}
|
||||
|
||||
func (o *LabelProvider) ToFormat(ctx context.Context, label *Label) *format.Label {
|
||||
|
|
|
@ -119,8 +119,7 @@ func (o *Milestone) FromFormat(milestone *format.Milestone) {
|
|||
}
|
||||
|
||||
type MilestoneProvider struct {
|
||||
g *Forgejo
|
||||
project *ProjectProvider
|
||||
BaseProviderWithProjectProvider
|
||||
}
|
||||
|
||||
func (o *MilestoneProvider) ToFormat(ctx context.Context, milestone *Milestone) *format.Milestone {
|
||||
|
|
|
@ -84,7 +84,7 @@ func (o *Project) FromFormat(project *format.Project) {
|
|||
}
|
||||
|
||||
type ProjectProvider struct {
|
||||
g *Forgejo
|
||||
BaseProvider
|
||||
milestones f3_util.NameIDMap
|
||||
labels f3_util.NameIDMap
|
||||
}
|
||||
|
|
|
@ -210,8 +210,7 @@ func (o *PullRequest) FromFormat(pullRequest *format.PullRequest) {
|
|||
}
|
||||
|
||||
type PullRequestProvider struct {
|
||||
g *Forgejo
|
||||
project *ProjectProvider
|
||||
BaseProviderWithProjectProvider
|
||||
prHeadCache f3_forgejo.PrHeadCache
|
||||
}
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ func (o *Reaction) FromFormat(reaction *format.Reaction) {
|
|||
}
|
||||
|
||||
type ReactionProvider struct {
|
||||
g *Forgejo
|
||||
BaseProvider
|
||||
}
|
||||
|
||||
func (o *ReactionProvider) ToFormat(ctx context.Context, reaction *Reaction) *format.Reaction {
|
||||
|
|
|
@ -100,7 +100,7 @@ func (o *Release) FromFormat(release *format.Release) {
|
|||
}
|
||||
|
||||
type ReleaseProvider struct {
|
||||
g *Forgejo
|
||||
BaseProvider
|
||||
}
|
||||
|
||||
func (o *ReleaseProvider) ToFormat(ctx context.Context, release *Release) *format.Release {
|
||||
|
|
|
@ -35,7 +35,7 @@ func (o *Repository) FromFormat(repository *format.Repository) {
|
|||
}
|
||||
|
||||
type RepositoryProvider struct {
|
||||
g *Forgejo
|
||||
BaseProvider
|
||||
}
|
||||
|
||||
func (o *RepositoryProvider) ToFormat(ctx context.Context, repository *Repository) *format.Repository {
|
||||
|
|
|
@ -151,7 +151,7 @@ func (o *Review) FromFormat(review *format.Review) {
|
|||
}
|
||||
|
||||
type ReviewProvider struct {
|
||||
g *Forgejo
|
||||
BaseProvider
|
||||
}
|
||||
|
||||
func (o *ReviewProvider) ToFormat(ctx context.Context, review *Review) *format.Review {
|
||||
|
|
|
@ -68,7 +68,7 @@ func (o *Topic) FromFormat(topic *format.Topic) {
|
|||
}
|
||||
|
||||
type TopicProvider struct {
|
||||
g *Forgejo
|
||||
BaseProvider
|
||||
}
|
||||
|
||||
func (o *TopicProvider) ToFormat(ctx context.Context, topic *Topic) *format.Topic {
|
||||
|
|
|
@ -76,7 +76,7 @@ func (o *User) FromFormat(user *format.User) {
|
|||
}
|
||||
|
||||
type UserProvider struct {
|
||||
g *Forgejo
|
||||
BaseProvider
|
||||
}
|
||||
|
||||
func (o *UserProvider) ToFormat(ctx context.Context, user *User) *format.User {
|
||||
|
|
Loading…
Reference in a new issue