Verified Commit 11072926 authored by Loïc Dachary's avatar Loïc Dachary
Browse files

options do not need generics

parent 4fe69c75
......@@ -21,10 +21,15 @@ import (
type NewMigrationHTTPClientFun func() *http.Client
type Configuration struct {
Verbose bool
Directory string
NewMigrationHTTPClient NewMigrationHTTPClientFun
}
func (c Configuration) GetVerbose() bool {
return c.Verbose
}
func (c Configuration) GetDirectory() string {
return c.Directory
}
......
......@@ -83,15 +83,17 @@ func TestMigrateFile2Gitea(t *testing.T) {
projectname := "projectname"
cloneAddr := "http://" + ip + ":8781/" + username + "/" + projectname
uploaderOptions := gitea.Options{
Configuration: gofff.Configuration{
Directory: t.TempDir(),
Options: gofff.Options{
Configuration: gofff.Configuration{
Directory: t.TempDir(),
},
Features: features,
},
Features: features,
CloneAddr: cloneAddr,
AuthUsername: "root",
AuthPassword: "Wrobyak4",
}
uploader := forges.New(uploaderOptions)
uploader := forges.New(&uploaderOptions)
uploader.DeleteProject()
migrate(context.Background(), downloader, uploader, gofff.NewLogger(), features)
......@@ -101,7 +103,7 @@ func TestMigrateFile2Gitea(t *testing.T) {
issues := uploader.GetIssues()
assert.EqualValues(t, 1, len(issues))
uploader = forges.New(uploaderOptions)
uploader = forges.New(&uploaderOptions)
migrate(context.Background(), downloader, uploader, gofff.NewLogger(), features)
// FIXME
// assert.EqualValues(t, 1, len(uploader.GetIssues()))
......
......@@ -28,23 +28,13 @@ import (
)
type Options struct {
gofff.Logger
gofff.Features
gofff.Configuration
gofff.Options
Validation bool
}
func (o *Options) Verbose() bool {
return true
}
func (o *Options) GetProjectPath() string {
return o.Directory
}
func (o *Options) GetConfiguration() *gofff.Configuration {
return &o.Configuration
return o.GetDirectory()
}
type File struct {
......@@ -55,8 +45,8 @@ type File struct {
reviewsPath string
}
func (f *File) Init(options *Options) {
f.Options = options
func (f *File) Init(options gofff.OptionsInterface) {
f.Options = options.(*Options)
f.commentsPath = "comments"
f.commentsPath = "reviews"
}
......
......@@ -47,10 +47,12 @@ func NewFixture(t *testing.T, features gofff.Features) *Fixture {
directory := t.TempDir()
f := &File{}
f.Init(&Options{
Configuration: gofff.Configuration{
Directory: directory,
Options: gofff.Options{
Configuration: gofff.Configuration{
Directory: directory,
},
Features: features,
},
Features: features,
})
return &Fixture{
t: t,
......@@ -62,10 +64,12 @@ func NewFixture(t *testing.T, features gofff.Features) *Fixture {
func (f *Fixture) CreateSimilarFile() *File {
c := &File{}
c.Init(&Options{
Configuration: gofff.Configuration{
Directory: f.t.TempDir(),
Options: gofff.Options{
Configuration: gofff.Configuration{
Directory: f.t.TempDir(),
},
Features: f.f.Options.Features,
},
Features: f.f.Options.Features,
Validation: true,
})
......
......@@ -28,14 +28,11 @@ import (
"lab.forgefriends.org/friendlyforgeformat/gofff/list"
)
type OptionsConstraint[Options any] interface {
*Options
gofff.OptionsInterface
}
type IOConstraint[IO any, OptionsPtr any, ProjectPtr any, MilestonePtr any, LabelPtr any, IssuePtr any, CommentPtr any, ReviewPtr any, PullRequestPtr any, ReleasePtr any, TopicPtr any] interface {
type IOConstraint[IO any, ProjectPtr any, MilestonePtr any, LabelPtr any, IssuePtr any, CommentPtr any, ReviewPtr any, PullRequestPtr any, ReleasePtr any, TopicPtr any] interface {
*IO
Init(OptionsPtr)
Init(gofff.OptionsInterface)
GetProjectPath() string
GetDirectory() string
SetContext(context.Context)
Finish()
GetRepository(format.Repository)
......@@ -110,11 +107,9 @@ type TopicConstraint interface {
}
type Forge[
Options any,
IO any,
OptionsPtr OptionsConstraint[Options],
IOPtr IOConstraint[IO, OptionsPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr],
IOPtr IOConstraint[IO, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr],
ProjectPtr ProjectConstraint[ProjectPtr],
MilestonePtr MilestoneConstraint[MilestonePtr],
LabelPtr LabelConstraint[LabelPtr],
......@@ -126,7 +121,6 @@ type Forge[
TopicPtr TopicConstraint,
] struct {
null.Null
options OptionsPtr
io IOPtr
ctx context.Context
project ProjectPtr
......@@ -139,9 +133,8 @@ type Forge[
releases list.Cache[ReleasePtr, int64]
}
func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) Init(options OptionsPtr) {
f.options = options
gofff.OptionsSetDefaults(f.options)
func (f *Forge[IO, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) Init(options gofff.OptionsInterface) {
options.SetDefaults()
f.io = new(IO)
f.io.Init(options)
f.milestones.Init()
......@@ -152,24 +145,24 @@ func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPt
f.releases.Init()
}
func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) SetContext(ctx context.Context) {
func (f *Forge[IO, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) SetContext(ctx context.Context) {
f.ctx = ctx
f.io.SetContext(ctx)
}
func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) Finish() {
func (f *Forge[IO, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) Finish() {
f.io.Finish()
}
func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) GetProject() *format.Project {
func (f *Forge[IO, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) GetProject() *format.Project {
provider := f.io.GetProjectProvider()
if f.project == nil {
f.project = provider.GetProjectByPath(f.options.GetProjectPath())
f.project = provider.GetProjectByPath(f.io.GetProjectPath())
}
return provider.ToFormat(f.project)
}
func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) CreateProject(project *format.Project) {
func (f *Forge[IO, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) CreateProject(project *format.Project) {
if f.project == nil {
provider := f.io.GetProjectProvider()
p := provider.FromFormat(project)
......@@ -180,30 +173,30 @@ func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPt
}
}
func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) DeleteProject() *format.Project {
project := f.io.GetProjectProvider().DeleteProject(f.options.GetProjectPath())
func (f *Forge[IO, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) DeleteProject() *format.Project {
project := f.io.GetProjectProvider().DeleteProject(f.io.GetProjectPath())
if project != nil {
return project.ToFormat()
}
return nil
}
func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) GetRepositories() []*format.Repository {
func (f *Forge[IO, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) GetRepositories() []*format.Repository {
repository := &format.Repository{
Directory: filepath.Join(f.options.GetDirectory(), "repository"),
Directory: filepath.Join(f.io.GetDirectory(), "repository"),
Name: format.RepositoryNameDefault,
}
f.io.GetRepository(*repository)
return []*format.Repository{repository}
}
func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) CreateRepositories(directory string, repositories ...*format.Repository) {
func (f *Forge[IO, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) CreateRepositories(directory string, repositories ...*format.Repository) {
for _, repository := range repositories {
f.io.CreateRepository(directory, *repository)
}
}
func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) GetMilestones() []*format.Milestone {
func (f *Forge[IO, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) GetMilestones() []*format.Milestone {
provider := f.io.GetMilestoneProvider(f.project)
milestones := make([]*format.Milestone, 0, 100)
for _, m := range provider.GetObjects() {
......@@ -214,7 +207,7 @@ func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPt
return milestones
}
func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) CreateMilestones(milestones ...*format.Milestone) {
func (f *Forge[IO, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) CreateMilestones(milestones ...*format.Milestone) {
p := f.io.GetMilestoneProvider(f.project)
for _, milestone := range milestones {
m := p.FromFormat(milestone)
......@@ -222,7 +215,7 @@ func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPt
}
}
func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) GetLabels() []*format.Label {
func (f *Forge[IO, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) GetLabels() []*format.Label {
provider := f.io.GetLabelProvider(f.project)
labels := make([]*format.Label, 0, 100)
for _, l := range provider.GetLabels() {
......@@ -233,7 +226,7 @@ func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPt
return labels
}
func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) CreateLabels(labels ...*format.Label) {
func (f *Forge[IO, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) CreateLabels(labels ...*format.Label) {
p := f.io.GetLabelProvider(f.project)
for _, label := range labels {
l := p.FromFormat(label)
......@@ -241,7 +234,7 @@ func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPt
}
}
func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) GetIssues() []*format.Issue {
func (f *Forge[IO, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) GetIssues() []*format.Issue {
provider := f.io.GetIssueProvider(f.project)
issues := make([]*format.Issue, 0, 100)
for _, i := range provider.GetIssues() {
......@@ -252,7 +245,7 @@ func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPt
return issues
}
func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) CreateIssues(issues ...*format.Issue) {
func (f *Forge[IO, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) CreateIssues(issues ...*format.Issue) {
p := f.io.GetIssueProvider(f.project)
for _, issue := range issues {
i := p.FromFormat(issue)
......@@ -260,7 +253,7 @@ func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPt
}
}
func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) GetComments(commentable format.Commentable) []*format.Comment {
func (f *Forge[IO, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) GetComments(commentable format.Commentable) []*format.Comment {
p := f.io.GetCommentProvider(f.project, commentable)
comments := make([]*format.Comment, 0, 100)
for _, i := range p.GetComments() {
......@@ -270,7 +263,7 @@ func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPt
return comments
}
func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) CreateComments(commentable format.Commentable, comments ...*format.Comment) {
func (f *Forge[IO, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) CreateComments(commentable format.Commentable, comments ...*format.Comment) {
provider := f.io.GetCommentProvider(f.project, commentable)
for _, comment := range comments {
c := provider.FromFormat(comment)
......@@ -278,7 +271,7 @@ func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPt
}
}
func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) GetReviews(reviewable format.Reviewable) []*format.Review {
func (f *Forge[IO, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) GetReviews(reviewable format.Reviewable) []*format.Review {
p := f.io.GetReviewProvider(f.project)
reviews := make([]*format.Review, 0, 100)
for _, i := range p.GetReviews(reviewable) {
......@@ -288,7 +281,7 @@ func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPt
return reviews
}
func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) CreateReviews(reviews ...*format.Review) {
func (f *Forge[IO, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) CreateReviews(reviews ...*format.Review) {
provider := f.io.GetReviewProvider(f.project)
for _, review := range reviews {
c := provider.FromFormat(review)
......@@ -296,17 +289,17 @@ func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPt
}
}
func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) GetPullRequests() []*format.PullRequest {
func (f *Forge[IO, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) GetPullRequests() []*format.PullRequest {
provider := f.io.GetPullRequestProvider(f.project)
prs := make([]*format.PullRequest, 0, 100)
for _, i := range provider.GetPullRequests(filepath.Join(f.options.GetDirectory(), "repository")) {
for _, i := range provider.GetPullRequests(filepath.Join(f.io.GetDirectory(), "repository")) {
f.prs.Store(i)
prs = append(prs, provider.ToFormat(i))
}
return prs
}
func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) CreatePullRequests(prs ...*format.PullRequest) {
func (f *Forge[IO, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) CreatePullRequests(prs ...*format.PullRequest) {
provider := f.io.GetPullRequestProvider(f.project)
for _, pr := range prs {
p := provider.FromFormat(pr)
......@@ -314,7 +307,7 @@ func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPt
}
}
func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) GetReleases() []*format.Release {
func (f *Forge[IO, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) GetReleases() []*format.Release {
provider := f.io.GetReleaseProvider(f.project)
releases := make([]*format.Release, 0, 100)
for _, r := range provider.GetReleases() {
......@@ -324,7 +317,7 @@ func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPt
return releases
}
func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) CreateReleases(releases ...*format.Release) {
func (f *Forge[IO, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) CreateReleases(releases ...*format.Release) {
provider := f.io.GetReleaseProvider(f.project)
for _, release := range releases {
r := provider.FromFormat(release)
......@@ -332,7 +325,7 @@ func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPt
}
}
func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) GetTopics() []*format.Topic {
func (f *Forge[IO, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) GetTopics() []*format.Topic {
provider := f.io.GetTopicProvider(f.project)
topics := make([]*format.Topic, 0, 100)
for _, t := range provider.GetTopics() {
......@@ -341,7 +334,7 @@ func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPt
return topics
}
func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) CreateTopics(topics ...*format.Topic) {
func (f *Forge[IO, IOPtr, ProjectPtr, MilestonePtr, LabelPtr, IssuePtr, CommentPtr, ReviewPtr, PullRequestPtr, ReleasePtr, TopicPtr]) CreateTopics(topics ...*format.Topic) {
provider := f.io.GetTopicProvider(f.project)
ts := make([]TopicPtr, 0, 10)
for _, topic := range topics {
......@@ -351,23 +344,23 @@ func (f *Forge[Options, IO, OptionsPtr, IOPtr, ProjectPtr, MilestonePtr, LabelPt
provider.CreateTopics(ts...)
}
func New(options any) gofff.ForgeInterface {
func New(options gofff.OptionsInterface) gofff.ForgeInterface {
switch o := options.(type) {
case file.Options:
case *file.Options:
f := &file.File{}
f.Init(&o)
f.Init(o)
return f
case gitea.Options:
f := &Forge[gitea.Options, gitea.Gitea,
*gitea.Options, *gitea.Gitea, *gitea.Project, *gitea.Milestone, *gitea.Label, *gitea.Issue, *gitea.Comment, *gitea.Review, *gitea.PullRequest, *gitea.Release, *gitea.Topic]{}
f.Init(&o)
case *gitea.Options:
f := &Forge[gitea.Gitea,
*gitea.Gitea, *gitea.Project, *gitea.Milestone, *gitea.Label, *gitea.Issue, *gitea.Comment, *gitea.Review, *gitea.PullRequest, *gitea.Release, *gitea.Topic]{}
f.Init(o)
return f
default:
panic(fmt.Errorf("unsupported type %T", options))
}
}
func NewForge(options any) (forge gofff.ForgeInterface, err error) {
func NewForge(options gofff.OptionsInterface) (forge gofff.ForgeInterface, err error) {
err = nil
defer func() {
......
......@@ -26,7 +26,7 @@ import (
)
func TestNewFile(t *testing.T) {
downloader := New(file.Options{})
downloader := New(&file.Options{})
assert.NotNil(t, downloader)
}
......@@ -39,9 +39,11 @@ func TestNewGitea(t *testing.T) {
username := "root"
projectname := "projectname"
cloneAddr := "http://" + ip + ":8781/" + username + "/" + projectname
uploader := New(gitea.Options{
Configuration: gofff.Configuration{
Directory: tmpDir,
uploader := New(&gitea.Options{
Options: gofff.Options{
Configuration: gofff.Configuration{
Directory: tmpDir,
},
},
CloneAddr: cloneAddr,
AuthUsername: "root",
......
......@@ -30,9 +30,7 @@ import (
)
type Options struct {
gofff.Logger
gofff.Features
gofff.Configuration
gofff.Options
CloneAddr string
AuthUsername string
......@@ -40,14 +38,6 @@ type Options struct {
AuthToken string
}
func (o *Options) GetConfiguration() *gofff.Configuration {
return &o.Configuration
}
func (o *Options) GetNewMigrationHTTPClient() gofff.NewMigrationHTTPClientFun {
return o.Configuration.GetNewMigrationHTTPClient()
}
func (o *Options) GetPushURL() string {
u, err := url.Parse(o.CloneAddr)
if err != nil {
......@@ -85,15 +75,6 @@ func (o *Options) ParseCloneURL() (baseURL, repoPath string) {
return
}
func (o *Options) Verbose() bool {
return true
}
func (o *Options) GetProjectPath() string {
_, repoPath := o.ParseCloneURL()
return repoPath
}
type Gitea struct {
perPage int
ctx context.Context
......@@ -101,19 +82,32 @@ type Gitea struct {
options *Options
}
func (g *Gitea) Init(options *Options) {
baseURL, _ := options.ParseCloneURL()
func (g *Gitea) SetOptions(options gofff.OptionsInterface) {
var ok bool
g.options, ok = options.(*Options)
if !ok {
panic(fmt.Errorf("unexpected type %T", options))
}
}
func (g *Gitea) Init(options gofff.OptionsInterface) {
g.SetOptions(options)
baseURL, _ := g.options.ParseCloneURL()
c, err := gitea_sdk.NewClient(
baseURL,
gitea_sdk.SetToken(options.AuthToken),
gitea_sdk.SetBasicAuth(options.AuthUsername, options.AuthPassword),
gitea_sdk.SetToken(g.options.AuthToken),
gitea_sdk.SetBasicAuth(g.options.AuthUsername, g.options.AuthPassword),
)
if err != nil {
panic(fmt.Errorf("Failed to create Gitea client for: %s. Error: %v", baseURL, err))
}
g.perPage = 100
g.client = c
g.options = options
}
func (g *Gitea) GetProjectPath() string {
_, repoPath := g.options.ParseCloneURL()
return repoPath
}
func (g *Gitea) GetDirectory() string {
......
......@@ -66,14 +66,16 @@ func newTestGitea(t *testing.T, username, password, projectname string) giteaIns
cloneAddr := "http://" + ip + ":8781/" + username + "/" + projectname
g := Gitea{}
options := &Options{
Configuration: gofff.Configuration{
Directory: t.TempDir(),
Options: gofff.Options{
Configuration: gofff.Configuration{
Directory: t.TempDir(),
},
},
CloneAddr: cloneAddr,
AuthUsername: username,
AuthPassword: password,
}
gofff.OptionsSetDefaults(options)
options.SetDefaults()
options.Logger = gofff.NewLogger()
g.Init(options)
g.SetContext(context.Background())
......
......@@ -19,15 +19,21 @@ import (
)
type OptionsInterface interface {
Verbose() bool
GetConfiguration() *Configuration
GetDirectory() string
GetProjectPath() string
SetDefaults()
}
func OptionsSetDefaults(options OptionsInterface) {
configuration := options.GetConfiguration()
if configuration.GetNewMigrationHTTPClient() == nil {
configuration.SetNewMigrationHTTPClient(func() *http.Client { return &http.Client{} })
type Options struct {
Logger
Features
Configuration
}
func (o *Options) GetConfiguration() *Configuration {
return &o.Configuration
}
func (o *Options) SetDefaults() {
if o.GetNewMigrationHTTPClient() == nil {
o.SetNewMigrationHTTPClient(func() *http.Client { return &http.Client{} })
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment