[F3] fix off by one error when importing repositories

This commit is contained in:
Earl Warren 2023-09-08 17:34:42 +02:00
parent 82e2e17b45
commit 31689b1397
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
2 changed files with 17 additions and 23 deletions

View file

@ -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 {
if page > 0 {
if page > 1 {
return make([]*Repository, 0)
}
repositories := make([]*Repository, len(format.RepositoryNames))
repositories := make([]*Repository, 0, len(format.RepositoryNames))
for _, name := range format.RepositoryNames {
repositories = append(repositories, o.Get(ctx, user, project, &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 {
repoPath := repo_model.RepoPath(user.Name, project.Name) + exemplar.Name
o.g.GetLogger().Debug(repoPath)
return &Repository{
Repository: format.Repository{
Name: exemplar.Name,
FetchFunc: func(destination string) {
o.g.GetLogger().Debug("RepositoryProvider:Get: git clone %s %s", repoPath, destination)
util.Command(ctx, "git", "clone", "--bare", repoPath, destination)
},
},

View file

@ -16,6 +16,7 @@ import (
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/test"
"code.gitea.io/gitea/services/f3/util"
"code.gitea.io/gitea/services/migrations"
"code.gitea.io/gitea/tests"
"github.com/markbates/goth"
@ -30,7 +31,7 @@ import (
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) {
AllowLocalNetworks := setting.Migrations.AllowLocalNetworks
setting.F3.Enabled = true
@ -41,7 +42,9 @@ func TestF3_Mirror(t *testing.T) {
defer func() {
setting.Migrations.AllowLocalNetworks = AllowLocalNetworks
setting.AppVer = AppVer
migrations.Init()
}()
assert.NoError(t, migrations.Init())
//
// Step 1: create a fixture
@ -80,33 +83,22 @@ func TestF3_Mirror(t *testing.T) {
//
doer, err := user_model.GetAdminUser(context.Background())
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()
forgejoLocal.Forge.Mirror(context.Background(), fixture.Forge, options)
upload.Mirror(context.Background(), fixture.Forge, options)
//
// Step 3: mirror Forgejo into F3
//
adminUsername := "user1"
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())
apiForge := forgejoAPI.Forge
apiUser := apiForge.Users.GetFromFormat(context.Background(), &format.User{UserName: fixture.UserFormat.UserName})
apiProject := apiUser.Projects.GetFromFormat(context.Background(), &format.Project{Name: fixture.ProjectFormat.Name})
options = f3_common.NewMirrorOptionsRecurse(apiUser, apiProject)
f3.Forge.Mirror(context.Background(), apiForge, options)
forgejoLocalDownload := util.ForgejoForgeRoot(f3_types.AllFeatures, doer, 0)
download := forgejoLocalDownload.Forge
downloadUser := download.Users.GetFromFormat(context.Background(), &format.User{UserName: fixture.UserFormat.UserName})
downloadProject := downloadUser.Projects.GetFromFormat(context.Background(), &format.Project{Name: fixture.ProjectFormat.Name})
options = f3_common.NewMirrorOptionsRecurse(downloadUser, downloadProject)
f3.Forge.Mirror(context.Background(), download, options)
//
// Step 4: verify the fixture and F3 are equivalent