[F3] fix off by one error when importing repositories
This commit is contained in:
parent
82e2e17b45
commit
31689b1397
2 changed files with 17 additions and 23 deletions
|
@ -49,10 +49,10 @@ func (o *RepositoryProvider) FromFormat(ctx context.Context, p *format.Repositor
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *RepositoryProvider) GetObjects(ctx context.Context, user *User, project *Project, page int) []*Repository {
|
func (o *RepositoryProvider) GetObjects(ctx context.Context, user *User, project *Project, page int) []*Repository {
|
||||||
if page > 0 {
|
if page > 1 {
|
||||||
return make([]*Repository, 0)
|
return make([]*Repository, 0)
|
||||||
}
|
}
|
||||||
repositories := make([]*Repository, len(format.RepositoryNames))
|
repositories := make([]*Repository, 0, len(format.RepositoryNames))
|
||||||
for _, name := range format.RepositoryNames {
|
for _, name := range format.RepositoryNames {
|
||||||
repositories = append(repositories, o.Get(ctx, user, project, &Repository{
|
repositories = append(repositories, o.Get(ctx, user, project, &Repository{
|
||||||
Repository: format.Repository{
|
Repository: format.Repository{
|
||||||
|
@ -68,10 +68,12 @@ func (o *RepositoryProvider) ProcessObject(ctx context.Context, user *User, proj
|
||||||
|
|
||||||
func (o *RepositoryProvider) Get(ctx context.Context, user *User, project *Project, exemplar *Repository) *Repository {
|
func (o *RepositoryProvider) Get(ctx context.Context, user *User, project *Project, exemplar *Repository) *Repository {
|
||||||
repoPath := repo_model.RepoPath(user.Name, project.Name) + exemplar.Name
|
repoPath := repo_model.RepoPath(user.Name, project.Name) + exemplar.Name
|
||||||
|
o.g.GetLogger().Debug(repoPath)
|
||||||
return &Repository{
|
return &Repository{
|
||||||
Repository: format.Repository{
|
Repository: format.Repository{
|
||||||
Name: exemplar.Name,
|
Name: exemplar.Name,
|
||||||
FetchFunc: func(destination string) {
|
FetchFunc: func(destination string) {
|
||||||
|
o.g.GetLogger().Debug("RepositoryProvider:Get: git clone %s %s", repoPath, destination)
|
||||||
util.Command(ctx, "git", "clone", "--bare", repoPath, destination)
|
util.Command(ctx, "git", "clone", "--bare", repoPath, destination)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -16,6 +16,7 @@ import (
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
"code.gitea.io/gitea/modules/test"
|
"code.gitea.io/gitea/modules/test"
|
||||||
"code.gitea.io/gitea/services/f3/util"
|
"code.gitea.io/gitea/services/f3/util"
|
||||||
|
"code.gitea.io/gitea/services/migrations"
|
||||||
"code.gitea.io/gitea/tests"
|
"code.gitea.io/gitea/tests"
|
||||||
|
|
||||||
"github.com/markbates/goth"
|
"github.com/markbates/goth"
|
||||||
|
@ -30,7 +31,7 @@ import (
|
||||||
f3_util "lab.forgefriends.org/friendlyforgeformat/gof3/util"
|
f3_util "lab.forgefriends.org/friendlyforgeformat/gof3/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestF3_Mirror(t *testing.T) {
|
func TestF3_MirrorAPITOLocal(t *testing.T) {
|
||||||
onGiteaRun(t, func(t *testing.T, u *url.URL) {
|
onGiteaRun(t, func(t *testing.T, u *url.URL) {
|
||||||
AllowLocalNetworks := setting.Migrations.AllowLocalNetworks
|
AllowLocalNetworks := setting.Migrations.AllowLocalNetworks
|
||||||
setting.F3.Enabled = true
|
setting.F3.Enabled = true
|
||||||
|
@ -41,7 +42,9 @@ func TestF3_Mirror(t *testing.T) {
|
||||||
defer func() {
|
defer func() {
|
||||||
setting.Migrations.AllowLocalNetworks = AllowLocalNetworks
|
setting.Migrations.AllowLocalNetworks = AllowLocalNetworks
|
||||||
setting.AppVer = AppVer
|
setting.AppVer = AppVer
|
||||||
|
migrations.Init()
|
||||||
}()
|
}()
|
||||||
|
assert.NoError(t, migrations.Init())
|
||||||
|
|
||||||
//
|
//
|
||||||
// Step 1: create a fixture
|
// Step 1: create a fixture
|
||||||
|
@ -80,33 +83,22 @@ func TestF3_Mirror(t *testing.T) {
|
||||||
//
|
//
|
||||||
doer, err := user_model.GetAdminUser(context.Background())
|
doer, err := user_model.GetAdminUser(context.Background())
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
forgejoLocal := util.ForgejoForgeRoot(f3_types.AllFeatures, doer, 0)
|
forgejoLocalUpload := util.ForgejoForgeRoot(f3_types.AllFeatures, doer, 0)
|
||||||
|
upload := forgejoLocalUpload.Forge
|
||||||
options := f3_common.NewMirrorOptionsRecurse()
|
options := f3_common.NewMirrorOptionsRecurse()
|
||||||
forgejoLocal.Forge.Mirror(context.Background(), fixture.Forge, options)
|
upload.Mirror(context.Background(), fixture.Forge, options)
|
||||||
|
|
||||||
//
|
//
|
||||||
// Step 3: mirror Forgejo into F3
|
// Step 3: mirror Forgejo into F3
|
||||||
//
|
//
|
||||||
adminUsername := "user1"
|
|
||||||
logger := util.ToF3Logger(nil)
|
logger := util.ToF3Logger(nil)
|
||||||
forgejoAPI := f3_forges.NewForgeRoot(&f3_forgejo.Forgejo{}, &f3_forgejo.Options{
|
|
||||||
Options: f3_types.Options{
|
|
||||||
Configuration: f3_types.Configuration{
|
|
||||||
URL: setting.AppURL,
|
|
||||||
Directory: t.TempDir(),
|
|
||||||
},
|
|
||||||
Features: f3_types.AllFeatures,
|
|
||||||
Logger: logger,
|
|
||||||
},
|
|
||||||
AuthToken: getUserToken(t, adminUsername, auth_model.AccessTokenScopeWriteAdmin, auth_model.AccessTokenScopeAll),
|
|
||||||
})
|
|
||||||
|
|
||||||
f3 := f3_forges.FixtureNewF3Forge(t, logger, nil, t.TempDir())
|
f3 := f3_forges.FixtureNewF3Forge(t, logger, nil, t.TempDir())
|
||||||
apiForge := forgejoAPI.Forge
|
forgejoLocalDownload := util.ForgejoForgeRoot(f3_types.AllFeatures, doer, 0)
|
||||||
apiUser := apiForge.Users.GetFromFormat(context.Background(), &format.User{UserName: fixture.UserFormat.UserName})
|
download := forgejoLocalDownload.Forge
|
||||||
apiProject := apiUser.Projects.GetFromFormat(context.Background(), &format.Project{Name: fixture.ProjectFormat.Name})
|
downloadUser := download.Users.GetFromFormat(context.Background(), &format.User{UserName: fixture.UserFormat.UserName})
|
||||||
options = f3_common.NewMirrorOptionsRecurse(apiUser, apiProject)
|
downloadProject := downloadUser.Projects.GetFromFormat(context.Background(), &format.Project{Name: fixture.ProjectFormat.Name})
|
||||||
f3.Forge.Mirror(context.Background(), apiForge, options)
|
options = f3_common.NewMirrorOptionsRecurse(downloadUser, downloadProject)
|
||||||
|
f3.Forge.Mirror(context.Background(), download, options)
|
||||||
|
|
||||||
//
|
//
|
||||||
// Step 4: verify the fixture and F3 are equivalent
|
// Step 4: verify the fixture and F3 are equivalent
|
||||||
|
|
Loading…
Reference in a new issue