forgejo/services/f3/driver/driver.go
Earl Warren 6aa76e9bcf
[F3] Forgejo driver and CLI
user, topic, project, label, milestone, repository, pull_request,
release, asset, comment, reaction, review providers

Signed-off-by: Earl Warren <contact@earl-warren.org>

Preserve file size when creating attachments

Introduced in c6f5029708

repoList.LoadAttributes has a ctx argument now

Rename `repo.GetOwner` to `repo.LoadOwner`

bd66fa586a

upgrade to the latest gof3

(cherry picked from commit c770713656)

[F3] ID remapping logic is in place, remove workaround

(cherry picked from commit d0fee30167)

[F3] it is experimental, do not enable by default

(cherry picked from commit de325b21d0)
(cherry picked from commit 547e7b3c40)
(cherry picked from commit 820df3a56b)
(cherry picked from commit eaba87689b)
(cherry picked from commit 1b86896b3b)
(cherry picked from commit 0046aac1c6)
(cherry picked from commit f14220df8f)
(cherry picked from commit 559b731001)
(cherry picked from commit 801f7d600d)
2023-07-03 09:22:02 +02:00

109 lines
4.9 KiB
Go

// SPDX-License-Identifier: MIT
package driver
import (
"fmt"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/services/migrations"
"lab.forgefriends.org/friendlyforgeformat/gof3"
"lab.forgefriends.org/friendlyforgeformat/gof3/forges/common"
"lab.forgefriends.org/friendlyforgeformat/gof3/forges/driver"
"lab.forgefriends.org/friendlyforgeformat/gof3/format"
)
type Options struct {
gof3.Options
Doer *user_model.User
}
type Forgejo struct {
perPage int
options *Options
}
func (o *Forgejo) GetPerPage() int {
return o.perPage
}
func (o *Forgejo) GetOptions() gof3.OptionsInterface {
return o.options
}
func (o *Forgejo) SetOptions(options gof3.OptionsInterface) {
var ok bool
o.options, ok = options.(*Options)
if !ok {
panic(fmt.Errorf("unexpected type %T", options))
}
}
func (o *Forgejo) GetLogger() *gof3.Logger {
return o.GetOptions().GetLogger()
}
func (o *Forgejo) Init(options gof3.OptionsInterface) {
o.SetOptions(options)
o.perPage = setting.ItemsPerPage
}
func (o *Forgejo) GetDirectory() string {
return o.options.GetDirectory()
}
func (o *Forgejo) GetDoer() *user_model.User {
return o.options.Doer
}
func (o *Forgejo) GetNewMigrationHTTPClient() gof3.NewMigrationHTTPClientFun {
return migrations.NewMigrationHTTPClient
}
func (o *Forgejo) SupportGetRepoComments() bool {
return false
}
func (o *Forgejo) GetProvider(name string, parent common.ProviderInterface) common.ProviderInterface {
var parentImpl any
if parent != nil {
parentImpl = parent.GetImplementation()
}
switch name {
case driver.ProviderUser:
return driver.NewProvider[UserProvider, *UserProvider, User, *User, format.User, *format.User](driver.ProviderUser, &UserProvider{g: o})
case driver.ProviderProject:
return driver.NewProviderWithParentOne[ProjectProvider, *ProjectProvider, Project, *Project, format.Project, *format.Project, User, *User](driver.ProviderProject, &ProjectProvider{g: 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)})
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)})
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)})
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})
case driver.ProviderRepository:
return driver.NewProviderWithParentOneTwo[RepositoryProvider, *RepositoryProvider, Repository, *Repository, format.Repository, *format.Repository, User, *User, Project, *Project](driver.ProviderRepository, &RepositoryProvider{g: o})
case driver.ProviderTopic:
return driver.NewProviderWithParentOneTwo[TopicProvider, *TopicProvider, Topic, *Topic, format.Topic, *format.Topic, User, *User, Project, *Project](driver.ProviderTopic, &TopicProvider{g: 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)})
case driver.ProviderRelease:
return driver.NewProviderWithParentOneTwo[ReleaseProvider, *ReleaseProvider, Release, *Release, format.Release, *format.Release, User, *User, Project, *Project](driver.ProviderRelease, &ReleaseProvider{g: 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})
case driver.ProviderComment:
return driver.NewProviderWithParentOneTwoThreeInterface[CommentProvider, *CommentProvider, Comment, *Comment, format.Comment, *format.Comment, User, *User, Project, *Project](driver.ProviderComment, &CommentProvider{g: o})
case driver.ProviderReaction:
return driver.NewProviderWithParentOneTwoRest[ReactionProvider, *ReactionProvider, Reaction, *Reaction, format.Reaction, *format.Reaction, User, *User, Project, *Project](driver.ProviderReaction, &ReactionProvider{g: o})
default:
panic(fmt.Sprintf("unknown provider name %s", name))
}
}
func (o Forgejo) Finish() {
}