6aa76e9bcf
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 inc6f5029708
repoList.LoadAttributes has a ctx argument now Rename `repo.GetOwner` to `repo.LoadOwner`bd66fa586a
upgrade to the latest gof3 (cherry picked from commitc770713656
) [F3] ID remapping logic is in place, remove workaround (cherry picked from commitd0fee30167
) [F3] it is experimental, do not enable by default (cherry picked from commitde325b21d0
) (cherry picked from commit547e7b3c40
) (cherry picked from commit820df3a56b
) (cherry picked from commiteaba87689b
) (cherry picked from commit1b86896b3b
) (cherry picked from commit0046aac1c6
) (cherry picked from commitf14220df8f
) (cherry picked from commit559b731001
) (cherry picked from commit801f7d600d
)
102 lines
2.9 KiB
Go
102 lines
2.9 KiB
Go
// SPDX-License-Identifier: MIT
|
|
|
|
package driver
|
|
|
|
import (
|
|
"context"
|
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
|
base "code.gitea.io/gitea/modules/migration"
|
|
repo_module "code.gitea.io/gitea/modules/repository"
|
|
"code.gitea.io/gitea/services/migrations"
|
|
|
|
"lab.forgefriends.org/friendlyforgeformat/gof3/format"
|
|
"lab.forgefriends.org/friendlyforgeformat/gof3/util"
|
|
)
|
|
|
|
type Repository struct {
|
|
format.Repository
|
|
}
|
|
|
|
func (o *Repository) Equals(other *Repository) bool {
|
|
return false // it is costly to figure that out, mirroring is as fast
|
|
}
|
|
|
|
func (o *Repository) ToFormat() *format.Repository {
|
|
return &o.Repository
|
|
}
|
|
|
|
func (o *Repository) FromFormat(repository *format.Repository) {
|
|
o.Repository = *repository
|
|
}
|
|
|
|
type RepositoryProvider struct {
|
|
g *Forgejo
|
|
}
|
|
|
|
func (o *RepositoryProvider) ToFormat(ctx context.Context, repository *Repository) *format.Repository {
|
|
return repository.ToFormat()
|
|
}
|
|
|
|
func (o *RepositoryProvider) FromFormat(ctx context.Context, p *format.Repository) *Repository {
|
|
var repository Repository
|
|
repository.FromFormat(p)
|
|
return &repository
|
|
}
|
|
|
|
func (o *RepositoryProvider) GetObjects(ctx context.Context, user *User, project *Project, page int) []*Repository {
|
|
if page > 0 {
|
|
return make([]*Repository, 0)
|
|
}
|
|
repositories := make([]*Repository, len(format.RepositoryNames))
|
|
for _, name := range format.RepositoryNames {
|
|
repositories = append(repositories, o.Get(ctx, user, project, &Repository{
|
|
Repository: format.Repository{
|
|
Name: name,
|
|
},
|
|
}))
|
|
}
|
|
return repositories
|
|
}
|
|
|
|
func (o *RepositoryProvider) ProcessObject(ctx context.Context, user *User, project *Project, 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
|
|
return &Repository{
|
|
Repository: format.Repository{
|
|
Name: exemplar.Name,
|
|
FetchFunc: func(destination string) {
|
|
util.Command(ctx, "git", "clone", "--bare", repoPath, destination)
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func (o *RepositoryProvider) Put(ctx context.Context, user *User, project *Project, repository *Repository) *Repository {
|
|
if repository.FetchFunc != nil {
|
|
directory, delete := format.RepositoryDefaultDirectory()
|
|
defer delete()
|
|
repository.FetchFunc(directory)
|
|
|
|
_, err := repo_module.MigrateRepositoryGitData(ctx, &user.User, &project.Repository, base.MigrateOptions{
|
|
RepoName: project.Name,
|
|
Mirror: false,
|
|
MirrorInterval: "",
|
|
LFS: false,
|
|
LFSEndpoint: "",
|
|
CloneAddr: directory,
|
|
Wiki: o.g.GetOptions().GetFeatures().Wiki,
|
|
Releases: o.g.GetOptions().GetFeatures().Releases,
|
|
}, migrations.NewMigrationHTTPTransport())
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
return o.Get(ctx, user, project, repository)
|
|
}
|
|
|
|
func (o *RepositoryProvider) Delete(ctx context.Context, user *User, project *Project, repository *Repository) *Repository {
|
|
panic("It is not possible to delete a repository")
|
|
}
|