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

implement pull requests

parent 399b2070
Pipeline #999 passed with stage
in 1 minute and 34 seconds
......@@ -53,6 +53,20 @@ func migrate(ctx context.Context, downloader, uploader abstract.ForgeInterface,
}
}
}
if options.PullRequests {
util.MaybeTerminate(ctx)
prs := downloader.GetPullRequests()
uploader.CreatePullRequests(prs...)
if options.Comments && !supportAllComments {
util.MaybeTerminate(ctx)
for _, pr := range prs {
uploader.CreateComments(downloader.GetComments(pr)...)
}
}
// reviews go here
}
if options.Releases {
util.MaybeTerminate(ctx)
uploader.CreateReleases(downloader.GetReleases()...)
......
......@@ -25,24 +25,23 @@ import (
"lab.forgefriends.org/friendlyforgeformat/gofff/forges/gitea"
"github.com/stretchr/testify/assert"
"github.com/unknwon/com"
)
func TestMigrateFile2File(t *testing.T) {
a := "../forges/file/testdata/repo1"
downloader := forges.New(file.Options{Directory: a})
fixture := file.NewFixture(t)
fixture.CreateProject()
b := t.TempDir()
uploader := forges.New(file.Options{Directory: b})
downloader := fixture.GetFile()
uploader := fixture.CopyFile()
Migrate(context.Background(), downloader, uploader, MigrateOptions{
Issues: true,
Comments: true,
Releases: true,
Issues: true,
Comments: true,
Releases: true,
PullRequests: true,
})
assert.FileExists(t, filepath.Join(b, "issue.json"))
file.AssertEquals(t, a, b)
fixture.AssertEquals(downloader, uploader)
}
func TestMigrateCancel(t *testing.T) {
......@@ -60,10 +59,10 @@ func TestMigrateCancel(t *testing.T) {
}
func TestMigrateFile2Gitea(t *testing.T) {
tmpDir := t.TempDir()
b := tmpDir + "/repo1"
assert.NoError(t, com.CopyDir("../forges/file/testdata/repo1", b))
downloader := forges.New(file.Options{Directory: b})
fixture := file.NewFixture(t)
fixture.CreateProject()
downloader := fixture.GetFile()
ip := os.Getenv("MY_IP")
if ip == "" {
......@@ -76,7 +75,7 @@ func TestMigrateFile2Gitea(t *testing.T) {
CloneAddr: cloneAddr,
AuthUsername: "root",
AuthPassword: "Wrobyak4",
Directory: tmpDir,
Directory: t.TempDir(),
}
uploader := forges.New(uploader_options)
......
......@@ -88,12 +88,16 @@ func (f *File) GetReleases() []*format.Release {
return GetBeans[format.Release](f, "release.json")
}
func (f *File) CreatePullRequests(prs ...*format.PullRequest) {
CreateBeans[format.PullRequest](f, "pull_request.json", prs...)
}
func (f *File) CreateReleases(releases ...*format.Release) {
CreateBeans[format.Release](f, "release.json", releases...)
}
func (f *File) GetComments(commentable format.Commentable) []*format.Comment {
return GetBeans[format.Comment](f, filepath.Join(f.commentsPath, fmt.Sprintf("%d.json", commentable.GetID())))
return MaybeGetBeans[format.Comment](f, filepath.Join(f.commentsPath, fmt.Sprintf("%d.json", commentable.GetID())))
}
func (f *File) CreateComments(comments ...*format.Comment) {
......@@ -115,9 +119,13 @@ func (f *File) SupportGetRepoComments() bool {
return false
}
func (f *File) GetPullRequests() []*format.PullRequest {
return GetBeans[format.PullRequest](f, "pull_request.json")
}
func (f *File) GetProject() *format.Project {
projectPath := filepath.Join(f.options.Directory, "project.json")
if _, err := os.Stat(projectPath); os.IsNotExist(err) {
if !util.FileExists(projectPath) {
return nil
}
......@@ -146,9 +154,20 @@ func (f *File) DeleteProject() *format.Project {
return project
}
func MaybeGetBeans[Format any](f *File, filename string) []*Format {
return getBeans[Format](f, filename, true)
}
func GetBeans[Format any](f *File, filename string) []*Format {
beans := make([]*Format, 0, 10)
return getBeans[Format](f, filename, false)
}
func getBeans[Format any](f *File, filename string, noFileIsOk bool) []*Format {
beansFile := filepath.Join(f.options.Directory, filename)
if noFileIsOk && !util.FileExists(beansFile) {
return []*Format{}
}
beans := make([]*Format, 0, 10)
if err := format.Load(beansFile, &beans, f.options.Validation); err != nil {
panic(fmt.Errorf("%v: %w", beansFile, err))
}
......
......@@ -38,6 +38,15 @@ func TestFile(t *testing.T) {
assert.NotEmpty(t, original.GetRepositories())
copy.CreateRepositories(original.GetRepositories()...)
assert.NotEmpty(t, original.GetPullRequests())
copy.CreatePullRequests(original.GetPullRequests()...)
assert.EqualValues(t, original.GetPullRequests(), copy.GetPullRequests())
issues := original.GetIssues()
assert.NotEmpty(t, original.GetComments(issues[0]))
copy.CreateComments(original.GetComments(issues[0])...)
assert.EqualValues(t, original.GetComments(issues[0]), copy.GetComments(issues[0]))
copy.CreateProject(original.GetProject())
assert.EqualValues(t, original.GetProject(), copy.GetProject())
......
......@@ -15,12 +15,14 @@
package file
import (
"bytes"
"os/exec"
"fmt"
"os"
"path/filepath"
"testing"
"time"
"lab.forgefriends.org/friendlyforgeformat/gofff/format"
"lab.forgefriends.org/friendlyforgeformat/gofff/util"
"github.com/stretchr/testify/assert"
)
......@@ -31,6 +33,12 @@ type Fixture struct {
f *File
}
type User struct {
ID int64
Name string
Email string
}
func NewFixture(t *testing.T) *Fixture {
directory := t.TempDir()
f := &File{}
......@@ -124,6 +132,61 @@ func (f *Fixture) BranchRepositoryFeature(directory string) (ref, sha string) {
return branch, sha
}
func (f *Fixture) CreatePullRequest(project *format.Project, user User) format.PullRequest {
f.CreateRepositories()
repository := f.GetDefaultRepositoryDirectory()
mainRef, mainSha := f.CreateRepositoryContent(repository)
featureRef, featureSha := f.BranchRepositoryFeature(repository)
now := time.Now()
tick := time.Duration(0)
tick++
prCreated := now.Add(tick)
tick++
prUpdated := now.Add(tick)
tick++
prClosed := now.Add(tick)
tick++
prMerged := now.Add(tick)
return format.PullRequest{
Number: 2,
PosterID: user.ID,
PosterName: user.Name,
PosterEmail: user.Email,
Title: "pr title",
Content: "pr content",
Milestone: "milestone",
State: "open",
IsLocked: false,
Created: prCreated,
Updated: prUpdated,
Closed: &prClosed,
// Labels
// Reactions
// Assignees
PatchURL: "https://example.com/pr",
Merged: false,
MergedTime: &prMerged,
MergeCommitSHA: "pr merge sha",
Head: format.PullRequestBranch{
CloneURL: "http://example.com/pr/head",
Ref: featureRef,
SHA: featureSha,
RepoName: project.Name,
OwnerName: project.Owner,
},
Base: format.PullRequestBranch{
CloneURL: "http://example.com/pr/base",
Ref: mainRef,
SHA: mainSha,
RepoName: project.Name,
OwnerName: project.Owner,
},
}
}
func (f *Fixture) CreateProject() {
project := &format.Project{
Index: 1,
......@@ -138,11 +201,6 @@ func (f *Fixture) CreateProject() {
}
f.f.CreateProject(project)
type User struct {
id int64
name string
email string
}
user1 := User{1, "user1", "user1@example.com"}
now := time.Now()
......@@ -154,12 +212,14 @@ func (f *Fixture) CreateProject() {
tick++
created := now.Add(tick)
issueNumber := int64(1)
issues := []*format.Issue{
{
Number: 1,
PosterID: user1.id,
PosterName: user1.name,
PosterEmail: user1.email,
Number: issueNumber,
PosterID: user1.ID,
PosterName: user1.Name,
PosterEmail: user1.Email,
Title: "title",
Content: "content",
Milestone: "milestone",
......@@ -195,9 +255,9 @@ func (f *Fixture) CreateProject() {
Body: "v12 body",
Draft: false,
Prerelease: false,
PublisherID: user1.id,
PublisherName: user1.name,
PublisherEmail: user1.email,
PublisherID: user1.ID,
PublisherName: user1.Name,
PublisherEmail: user1.Email,
Assets: []*format.ReleaseAsset{
{
ID: 5,
......@@ -215,4 +275,26 @@ func (f *Fixture) CreateProject() {
},
}
f.f.CreateReleases(releases...)
pr := f.CreatePullRequest(project, user1)
f.f.CreatePullRequests(&pr)
tick++
commentCreated := now.Add(tick)
tick++
commentUpdated := now.Add(tick)
comments := []*format.Comment{
{
IssueIndex: issueNumber,
Index: 123,
PosterID: user1.ID,
PosterName: user1.Name,
PosterEmail: user1.Email,
Created: commentCreated,
Updated: commentUpdated,
Content: "comment content",
Reactions: []*format.Reaction{},
},
}
f.f.CreateComments(comments...)
}
......@@ -34,7 +34,7 @@ type OptionsConstraint interface {
GetDirectory() string
}
type IOConstraint[IO any, Options OptionsConstraint, ProjectProviderPtr any, ProjectPtr any, IssueProviderPtr any, CommentProviderPtr any] interface {
type IOConstraint[IO any, Options OptionsConstraint, ProjectProviderPtr any, ProjectPtr any, IssueProviderPtr any, CommentProviderPtr any, PullRequestProviderPtr any] interface {
*IO
Init(Options)
Context(context.Context)
......@@ -44,6 +44,7 @@ type IOConstraint[IO any, Options OptionsConstraint, ProjectProviderPtr any, Pro
GetProjectProvider() ProjectProviderPtr
GetIssueProvider(ProjectPtr) IssueProviderPtr
GetCommentProvider(ProjectPtr) CommentProviderPtr
GetPullRequestProvider(ProjectPtr) PullRequestProviderPtr
}
type ProjectProviderInterface[ProjectProvider any, Project any, ProjectPtr ProjectConstraint[Project]] interface {
......@@ -101,6 +102,24 @@ type CommentConstraint[Comment any] interface {
CommentConverterInterface[Comment]
}
type PullRequestProviderInterface[PullRequestProvider any, PullRequest any, PullRequestPtr PullRequestConstraint[PullRequest]] interface {
*PullRequestProvider
abstract.ForeignReferenceProvider
list.ProviderConstraint[PullRequest, PullRequestPtr, PullRequestProvider]
GetPullRequests() []PullRequest
}
type PullRequestConverterInterface[PullRequest any] interface {
*PullRequest
ToFormat() *format.PullRequest
FromFormat(format.PullRequest)
}
type PullRequestConstraint[PullRequest any] interface {
list.CacheableConstraint[PullRequest]
PullRequestConverterInterface[PullRequest]
}
type Forge[
Options OptionsConstraint,
IO any,
......@@ -110,14 +129,18 @@ type Forge[
IssueProvider any,
Comment any,
CommentProvider any,
PullRequest any,
PullRequestProvider any,
IOPtr IOConstraint[IO, Options, ProjectProviderPtr, ProjectPtr, IssueProviderPtr, CommentProviderPtr],
IOPtr IOConstraint[IO, Options, ProjectProviderPtr, ProjectPtr, IssueProviderPtr, CommentProviderPtr, PullRequestProviderPtr],
ProjectPtr ProjectConstraint[Project],
ProjectProviderPtr ProjectProviderInterface[ProjectProvider, Project, ProjectPtr],
IssuePtr IssueConstraint[Issue],
IssueProviderPtr IssueProviderInterface[IssueProvider, Issue, IssuePtr],
CommentPtr CommentConstraint[Comment],
CommentProviderPtr CommentProviderInterface[CommentProvider, Comment, CommentPtr],
PullRequestPtr PullRequestConstraint[PullRequest],
PullRequestProviderPtr PullRequestProviderInterface[PullRequestProvider, PullRequest, PullRequestPtr],
] struct {
null.Null
options Options
......@@ -127,9 +150,10 @@ type Forge[
project ProjectPtr
issues list.Cache[Issue, IssuePtr]
comments list.Cache[Comment, CommentPtr]
prs list.Cache[PullRequest, PullRequestPtr]
}
func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, _, _, _, _, _, _, _, _, _]) Init(options Options) {
func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, Comment, CommentProvider, PullRequest, PullRequestProvider, IOPtr, ProjectPtr, ProjectProviderPtr, IssuePtr, IssueProviderPtr, CommentPtr, CommentProviderPtr, PullRequestPtr, PullRequestProviderPtr]) Init(options Options) {
f.options = options
f.db = db.Db{}
f.db.Open(filepath.Join(f.options.GetDirectory(), "references.db"))
......@@ -137,26 +161,27 @@ func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, _, _
f.io.Init(options)
f.issues.Init()
f.comments.Init()
f.prs.Init()
}
func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, _, _, _, _, _, _, _, _, _]) Context(ctx context.Context) {
func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, Comment, CommentProvider, PullRequest, PullRequestProvider, IOPtr, ProjectPtr, ProjectProviderPtr, IssuePtr, IssueProviderPtr, CommentPtr, CommentProviderPtr, PullRequestPtr, PullRequestProviderPtr]) Context(ctx context.Context) {
f.ctx = ctx
f.io.Context(ctx)
}
func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, _, _, _, _, _, _, _, _, _]) Finish() {
func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, Comment, CommentProvider, PullRequest, PullRequestProvider, IOPtr, ProjectPtr, ProjectProviderPtr, IssuePtr, IssueProviderPtr, CommentPtr, CommentProviderPtr, PullRequestPtr, PullRequestProviderPtr]) Finish() {
f.io.Finish()
f.db.Close()
}
func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, _, _, _, ProjectPtr, _, ProjectProviderPtr, _, _, _]) GetProject() *format.Project {
func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, Comment, CommentProvider, PullRequest, PullRequestProvider, IOPtr, ProjectPtr, ProjectProviderPtr, IssuePtr, IssueProviderPtr, CommentPtr, CommentProviderPtr, PullRequestPtr, PullRequestProviderPtr]) GetProject() *format.Project {
if f.project == nil {
f.project = f.io.GetProjectProvider().GetProjectByPath(f.options.GetProjectPath())
}
return f.project.ToFormat()
}
func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, _, _, _, ProjectPtr, ProjectProviderPtr, _, _, _, _]) CreateProject(project *format.Project) {
func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, Comment, CommentProvider, PullRequest, PullRequestProvider, IOPtr, ProjectPtr, ProjectProviderPtr, IssuePtr, IssueProviderPtr, CommentPtr, CommentProviderPtr, PullRequestPtr, PullRequestProviderPtr]) CreateProject(project *format.Project) {
if f.project == nil {
p := new(Project)
ProjectPtr(p).FromFormat(*project)
......@@ -177,7 +202,7 @@ func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, _, _
}
}
func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, _, _, _, ProjectPtr, ProjectProviderPtr, _, _, _, _]) DeleteProject() *format.Project {
func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, Comment, CommentProvider, PullRequest, PullRequestProvider, IOPtr, ProjectPtr, ProjectProviderPtr, IssuePtr, IssueProviderPtr, CommentPtr, CommentProviderPtr, PullRequestPtr, PullRequestProviderPtr]) DeleteProject() *format.Project {
project := f.io.GetProjectProvider().DeleteProject(f.options.GetProjectPath())
if project != nil {
return project.ToFormat()
......@@ -205,7 +230,7 @@ type ForeignTranslatable interface {
SetID(int64)
}
func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, _, _, _, ProjectPtr, ProjectProviderPtr, _, _, _, _]) foreignToLocal(provider abstract.ForeignReferenceProvider, foreign, local ForeignTranslatable) {
func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, Comment, CommentProvider, PullRequest, PullRequestProvider, IOPtr, ProjectPtr, ProjectProviderPtr, IssuePtr, IssueProviderPtr, CommentPtr, CommentProviderPtr, PullRequestPtr, PullRequestProviderPtr]) foreignToLocal(provider abstract.ForeignReferenceProvider, foreign, local ForeignTranslatable) {
if !provider.ForeignReferenceRequired() {
return
}
......@@ -215,7 +240,7 @@ func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, _, _
}
}
func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, _, _, _, ProjectPtr, ProjectProviderPtr, _, _, _, _]) localToForeign(provider abstract.ForeignReferenceProvider, local, foreign ForeignTranslatable) {
func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, Comment, CommentProvider, PullRequest, PullRequestProvider, IOPtr, ProjectPtr, ProjectProviderPtr, IssuePtr, IssueProviderPtr, CommentPtr, CommentProviderPtr, PullRequestPtr, PullRequestProviderPtr]) localToForeign(provider abstract.ForeignReferenceProvider, local, foreign ForeignTranslatable) {
if !provider.ForeignReferenceRequired() {
return
}
......@@ -225,7 +250,7 @@ func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, _, _
}
}
func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, _, _, _, ProjectPtr, ProjectProviderPtr, _, _, _, _]) storeForeignReference(provider abstract.ForeignReferenceProvider, foreign, local ForeignTranslatable) {
func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, Comment, CommentProvider, PullRequest, PullRequestProvider, IOPtr, ProjectPtr, ProjectProviderPtr, IssuePtr, IssueProviderPtr, CommentPtr, CommentProviderPtr, PullRequestPtr, PullRequestProviderPtr]) storeForeignReference(provider abstract.ForeignReferenceProvider, foreign, local ForeignTranslatable) {
if !provider.ForeignReferenceRequired() {
return
}
......@@ -237,7 +262,7 @@ func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, _, _
})
}
func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, _, _, _, _, _, IssuePtr, IssueProviderPtr, _, _]) GetIssues() []*format.Issue {
func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, Comment, CommentProvider, PullRequest, PullRequestProvider, IOPtr, ProjectPtr, ProjectProviderPtr, IssuePtr, IssueProviderPtr, CommentPtr, CommentProviderPtr, PullRequestPtr, PullRequestProviderPtr]) GetIssues() []*format.Issue {
p := f.io.GetIssueProvider(f.project)
issues := make([]*format.Issue, 0, 100)
for _, i := range p.GetIssues() {
......@@ -249,7 +274,7 @@ func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, _, _
return issues
}
func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, _, _, _, _, _, IssuePtr, IssueProviderPtr, _, _]) CreateIssues(issues ...*format.Issue) {
func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, Comment, CommentProvider, PullRequest, PullRequestProvider, IOPtr, ProjectPtr, ProjectProviderPtr, IssuePtr, IssueProviderPtr, CommentPtr, CommentProviderPtr, PullRequestPtr, PullRequestProviderPtr]) CreateIssues(issues ...*format.Issue) {
p := f.io.GetIssueProvider(f.project)
for _, issue := range issues {
i := new(Issue)
......@@ -260,7 +285,7 @@ func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, _, _
}
}
func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, _, _, _, _, _, _, _, CommentPtr, CommentProviderPtr]) GetComments(commentable format.Commentable) []*format.Comment {
func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, Comment, CommentProvider, PullRequest, PullRequestProvider, IOPtr, ProjectPtr, ProjectProviderPtr, IssuePtr, IssueProviderPtr, CommentPtr, CommentProviderPtr, PullRequestPtr, PullRequestProviderPtr]) GetComments(commentable format.Commentable) []*format.Comment {
p := f.io.GetCommentProvider(f.project)
comments := make([]*format.Comment, 0, 100)
for _, i := range p.GetComments(commentable) {
......@@ -272,7 +297,7 @@ func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, _, _
return comments
}
func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, Comment, CommentProvider, _, _, _, _, _, CommentPtr, CommentProviderPtr]) CreateComments(comments ...*format.Comment) {
func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, Comment, CommentProvider, PullRequest, PullRequestProvider, IOPtr, ProjectPtr, ProjectProviderPtr, IssuePtr, IssueProviderPtr, CommentPtr, CommentProviderPtr, PullRequestPtr, PullRequestProviderPtr]) CreateComments(comments ...*format.Comment) {
p := f.io.GetCommentProvider(f.project)
for _, comment := range comments {
i := new(Comment)
......@@ -283,6 +308,29 @@ func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, Comm
}
}
func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, Comment, CommentProvider, PullRequest, PullRequestProvider, IOPtr, ProjectPtr, ProjectProviderPtr, IssuePtr, IssueProviderPtr, CommentPtr, CommentProviderPtr, PullRequestPtr, PullRequestProviderPtr]) GetPullRequests() []*format.PullRequest {
p := f.io.GetPullRequestProvider(f.project)
prs := make([]*format.PullRequest, 0, 100)
for _, i := range p.GetPullRequests() {
f.prs.Store(&i)
pr := PullRequestPtr(&i).ToFormat()
f.localToForeign(p, PullRequestPtr(&i), pr)
prs = append(prs, pr)
}
return prs
}
func (f *Forge[Options, IO, Project, ProjectProvider, Issue, IssueProvider, Comment, CommentProvider, PullRequest, PullRequestProvider, IOPtr, ProjectPtr, ProjectProviderPtr, IssuePtr, IssueProviderPtr, CommentPtr, CommentProviderPtr, PullRequestPtr, PullRequestProviderPtr]) CreatePullRequests(prs ...*format.PullRequest) {
p := f.io.GetPullRequestProvider(f.project)
for _, pr := range prs {
i := new(PullRequest)
PullRequestPtr(i).FromFormat(*pr)
f.foreignToLocal(p, pr, PullRequestPtr(i))
list.UpsertBean[PullRequest, PullRequestProvider, PullRequestPtr, PullRequestProviderPtr](&f.prs, p, i)
f.storeForeignReference(p, pr, PullRequestPtr(i))
}
}
func New(options OptionsConstraint) abstract.ForgeInterface {
switch o := options.(type) {
case file.Options:
......@@ -290,8 +338,8 @@ func New(options OptionsConstraint) abstract.ForgeInterface {
f.Init(o)
return f
case gitea.Options:
f := &Forge[gitea.Options, gitea.Gitea, gitea.Project, gitea.ProjectProvider, gitea.Issue, gitea.IssueProvider, gitea.Comment, gitea.CommentProvider,
*gitea.Gitea, *gitea.Project, *gitea.ProjectProvider, *gitea.Issue, *gitea.IssueProvider, *gitea.Comment, *gitea.CommentProvider]{}
f := &Forge[gitea.Options, gitea.Gitea, gitea.Project, gitea.ProjectProvider, gitea.Issue, gitea.IssueProvider, gitea.Comment, gitea.CommentProvider, gitea.PullRequest, gitea.PullRequestProvider,
*gitea.Gitea, *gitea.Project, *gitea.ProjectProvider, *gitea.Issue, *gitea.IssueProvider, *gitea.Comment, *gitea.CommentProvider, *gitea.PullRequest, *gitea.PullRequestProvider]{}
f.Init(o)
return f
default:
......
......@@ -21,6 +21,8 @@ import (
"strings"
"lab.forgefriends.org/friendlyforgeformat/gofff/forges/null"
"lab.forgefriends.org/friendlyforgeformat/gofff/format"
"lab.forgefriends.org/friendlyforgeformat/gofff/util"
gitea_sdk "code.gitea.io/sdk/gitea"
)
......@@ -37,6 +39,19 @@ func (o Options) GetDirectory() string {
return o.Directory
}
func (o Options) GetPushURL() string {
u, err := url.Parse(o.CloneAddr)
if err != nil {
panic(err)
}
if o.AuthToken != "" {
u.User = url.UserPassword("token", o.AuthToken)
} else {
u.User = url.UserPassword(o.AuthUsername, o.AuthPassword)
}
return u.String()
}
func (o Options) ParseCloneURL() (baseURL, repoPath string) {
u, err := url.Parse(o.CloneAddr)
if err != nil {
......@@ -72,13 +87,14 @@ func (o Options) GetProjectPath() string {
type Gitea struct {
null.Null
perPage int
ctx context.Context
client *gitea_sdk.Client
options Options
projectProvider *ProjectProvider
issueProvider *IssueProvider
commentProvider *CommentProvider
perPage int
ctx context.Context
client *gitea_sdk.Client
options Options
projectProvider *ProjectProvider
issueProvider *IssueProvider
commentProvider *CommentProvider
pullRequestProvider *PullRequestProvider
}
func (g *Gitea) Init(options Options) {
......@@ -97,6 +113,7 @@ func (g *Gitea) Init(options Options) {
g.projectProvider = (&ProjectProvider{}).Init(g)