|
|
|
@@ -23,7 +23,6 @@ import (
|
|
|
|
|
"errors"
|
|
|
|
|
"flag"
|
|
|
|
|
"fmt"
|
|
|
|
|
"io/fs"
|
|
|
|
|
"log"
|
|
|
|
|
"net/url"
|
|
|
|
|
"os"
|
|
|
|
@@ -147,7 +146,9 @@ func listMaintainers(obs *common.ObsClient, prj string, pkgs []string) {
|
|
|
|
|
log.Panicln(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
contact_email = append(contact_email, fmt.Sprintf("%s <%s>", user.Name, user.Email))
|
|
|
|
|
if user != nil {
|
|
|
|
|
contact_email = append(contact_email, fmt.Sprintf("%s <%s>", user.Name, user.Email))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
log.Println(strings.Join(contact_email, ", "))
|
|
|
|
|
}
|
|
|
|
@@ -158,6 +159,7 @@ func gitImporter(prj, pkg string) error {
|
|
|
|
|
params = append(params, "-l", "debug")
|
|
|
|
|
}
|
|
|
|
|
params = append(params, pkg)
|
|
|
|
|
common.LogDebug("git-importer", params)
|
|
|
|
|
cmd := exec.Command("./git-importer", params...)
|
|
|
|
|
if idx := slices.IndexFunc(cmd.Env, func(val string) bool { return val[0:12] == "GITEA_TOKEN=" }); idx != -1 {
|
|
|
|
|
cmd.Env = slices.Delete(cmd.Env, idx, idx+1)
|
|
|
|
@@ -170,361 +172,113 @@ func gitImporter(prj, pkg string) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func cloneDevel(git common.Git, gitDir, outName, urlString string) error {
|
|
|
|
|
url, err := url.Parse(urlString)
|
|
|
|
|
// branch := url.Fragment
|
|
|
|
|
url.Fragment = ""
|
|
|
|
|
|
|
|
|
|
params := []string{"clone"}
|
|
|
|
|
/* if len(branch) > 0 {
|
|
|
|
|
params = append(params, "-b", branch)
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
params = append(params, url.String(), outName)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("error parsing SSH URL. %w", err)
|
|
|
|
|
func cloneDevel(git common.Git, gitDir, outName, urlString, remote string, fatal bool) error {
|
|
|
|
|
if url, _ := url.Parse(urlString); url != nil {
|
|
|
|
|
url.Fragment = ""
|
|
|
|
|
urlString = url.String()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
params := []string{"clone", "-o", remote}
|
|
|
|
|
params = append(params, urlString, outName)
|
|
|
|
|
|
|
|
|
|
if fatal {
|
|
|
|
|
git.GitExecOrPanic(gitDir, params...)
|
|
|
|
|
} else {
|
|
|
|
|
git.GitExec(gitDir, params...)
|
|
|
|
|
}
|
|
|
|
|
git.GitExecOrPanic(gitDir, params...)
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func importRepos(packages []string) {
|
|
|
|
|
RepoToObsName := make(map[string]string)
|
|
|
|
|
|
|
|
|
|
factoryRepos := make([]*models.Repository, 0, len(packages)*2)
|
|
|
|
|
develProjectPackages := make([]string, 0, len(packages))
|
|
|
|
|
for _, pkg := range packages {
|
|
|
|
|
src_pkg_name := strings.Split(pkg, ":")
|
|
|
|
|
RepoToObsName[giteaPackage(src_pkg_name[0])] = src_pkg_name[0]
|
|
|
|
|
repo, err := client.Repository.RepoGet(
|
|
|
|
|
repository.NewRepoGetParams().
|
|
|
|
|
WithDefaults().WithOwner("pool").WithRepo(giteaPackage(src_pkg_name[0])),
|
|
|
|
|
r.DefaultAuthentication)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
if !errors.Is(err, &repository.RepoGetNotFound{}) {
|
|
|
|
|
log.Panicln(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.Println("Cannot find src package:", src_pkg_name)
|
|
|
|
|
develProjectPackages = append(develProjectPackages, src_pkg_name[0])
|
|
|
|
|
} else {
|
|
|
|
|
factoryRepos = append(factoryRepos, repo.Payload)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
log.Println("Num repos found:", len(factoryRepos))
|
|
|
|
|
if len(develProjectPackages) > 0 {
|
|
|
|
|
log.Println("Num of repos that need to create:", len(develProjectPackages))
|
|
|
|
|
log.Println("Create the following packages in pool to continue:", strings.Join(develProjectPackages, " "))
|
|
|
|
|
if forceNonPoolPackages {
|
|
|
|
|
log.Println(" IGNORING and will create these as non-pool packages!")
|
|
|
|
|
} else {
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
oldPackageNames := make([]string, 0, len(factoryRepos))
|
|
|
|
|
for _, repo := range factoryRepos {
|
|
|
|
|
oldPackageNames = append(oldPackageNames, RepoToObsName[repo.Name])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// fork packags from pool
|
|
|
|
|
for i := 0; i < len(oldPackageNames); {
|
|
|
|
|
pkg := oldPackageNames[i]
|
|
|
|
|
log.Println(" + package:", pkg)
|
|
|
|
|
if err := gitImporter("openSUSE:Factory", pkg); err != nil {
|
|
|
|
|
log.Println(" ** failed to import openSUSE:Factory", pkg)
|
|
|
|
|
log.Println(" ** falling back to devel project only")
|
|
|
|
|
|
|
|
|
|
develProjectPackages = append(develProjectPackages, pkg)
|
|
|
|
|
oldPackageNames = slices.Delete(oldPackageNames, i, i+1)
|
|
|
|
|
} else {
|
|
|
|
|
i++
|
|
|
|
|
func findMissingDevelBranch(git common.Git, pkg, project string) {
|
|
|
|
|
d, err := git.GitBranchHead(pkg, "devel")
|
|
|
|
|
if err != nil {
|
|
|
|
|
if _, err = git.GitBranchHead(pkg, "factory"); err != nil {
|
|
|
|
|
log.Println("factory is missing... so maybe repo is b0rked.")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hash := common.SplitLines(git.GitExecWithOutputOrPanic(pkg,
|
|
|
|
|
"log",
|
|
|
|
|
"factory",
|
|
|
|
|
"--all",
|
|
|
|
|
"--grep=build.opensuse.org/package/show/"+project+"/"+pkg,
|
|
|
|
|
"-1",
|
|
|
|
|
"--pretty=format:%H"))
|
|
|
|
|
if len(hash) > 0 {
|
|
|
|
|
log.Println(" devel @", hash[0])
|
|
|
|
|
git.GitExecOrPanic(pkg, "branch", "devel", hash[0])
|
|
|
|
|
} else {
|
|
|
|
|
git.GitExecOrPanic(pkg, "branch", "devel", "factory")
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
log.Println(" devel already exists?", d)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.Println("adding remotes...")
|
|
|
|
|
for i := 0; i < len(factoryRepos); i++ {
|
|
|
|
|
pkg := factoryRepos[i]
|
|
|
|
|
pkgName := RepoToObsName[pkg.Name]
|
|
|
|
|
gitName := pkg.Name
|
|
|
|
|
|
|
|
|
|
// verify that package was created by `git-importer`, or it's scmsync package and clone it
|
|
|
|
|
fi, err := os.Stat(filepath.Join(git.GetPath(), gitName))
|
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
|
if slices.Contains(develProjectPackages, pkgName) {
|
|
|
|
|
// failed import of former factory package
|
|
|
|
|
log.Println("Failed to import former factory pkg:", pkgName)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// scmsync?
|
|
|
|
|
devel_project, err := devel_projects.GetDevelProject(pkgName)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Panicln("devel project not found for", RepoToObsName[pkg.Name], "err:", err)
|
|
|
|
|
}
|
|
|
|
|
meta, _ := obs.GetPackageMeta(devel_project, pkgName)
|
|
|
|
|
if len(meta.ScmSync) > 0 {
|
|
|
|
|
if err2 := cloneDevel(git, "", gitName, meta.ScmSync); err != nil {
|
|
|
|
|
log.Panicln(err2)
|
|
|
|
|
}
|
|
|
|
|
if err2 := git.GitExec(gitName, "checkout", "-B", "main"); err2 != nil {
|
|
|
|
|
git.GitExecOrPanic(gitName, "checkout", "-B", "master")
|
|
|
|
|
}
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// try again, should now exist
|
|
|
|
|
if fi, err = os.Stat(filepath.Join(git.GetPath(), gitName)); err != nil {
|
|
|
|
|
log.Panicln(err)
|
|
|
|
|
}
|
|
|
|
|
} else if err != nil {
|
|
|
|
|
func importFactoryRepoAndCheckHistory(pkg string, meta *common.PackageMeta) (factoryRepo *models.Repository, retErr error) {
|
|
|
|
|
if repo, err := client.Repository.RepoGet(repository.NewRepoGetParams().WithDefaults().WithOwner("pool").WithRepo(giteaPackage(pkg)), r.DefaultAuthentication); err != nil {
|
|
|
|
|
if !errors.Is(err, &repository.RepoGetNotFound{}) {
|
|
|
|
|
log.Panicln(err)
|
|
|
|
|
} else {
|
|
|
|
|
// verify that we do not have scmsync for imported packages
|
|
|
|
|
meta, err := obs.GetPackageMeta(prj, pkgName)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Panicln(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(meta.ScmSync) > 0 {
|
|
|
|
|
u, err := url.Parse(meta.ScmSync)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Println("Invlid scmsync in", pkg, meta.ScmSync, err)
|
|
|
|
|
}
|
|
|
|
|
o, err := url.Parse(strings.TrimSpace(git.GitExecWithOutputOrPanic(gitName, "remote", "get-url", "origin")))
|
|
|
|
|
log.Println("Invlid scmsync in git repo", pkg, meta.ScmSync, err)
|
|
|
|
|
if u.Host != o.Host || u.Path != u.Path {
|
|
|
|
|
log.Panicln("importing an scmsync package??:", prj, gitName)
|
|
|
|
|
} else {
|
|
|
|
|
log.Println("previous SCMSYNC package. Pull.")
|
|
|
|
|
git.GitExecOrPanic(gitName, "pull", "origin", "HEAD:main")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !fi.IsDir() {
|
|
|
|
|
log.Panicln("Expected package file should be a directory. It's not.", fi)
|
|
|
|
|
}
|
|
|
|
|
log.Println("Cannot find src package:", pkg)
|
|
|
|
|
return nil, nil
|
|
|
|
|
} else {
|
|
|
|
|
factoryRepo = repo.Payload
|
|
|
|
|
CreatePoolFork(factoryRepo)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// add remote repos
|
|
|
|
|
out := git.GitExecWithOutputOrPanic(gitName, "remote", "show", "-n")
|
|
|
|
|
switch pkg.Owner.UserName {
|
|
|
|
|
case "pool":
|
|
|
|
|
if !slices.Contains(strings.Split(out, "\n"), "pool") {
|
|
|
|
|
out := git.GitExecWithOutputOrPanic(gitName, "remote", "add", "pool", pkg.CloneURL)
|
|
|
|
|
if len(strings.TrimSpace(out)) > 1 {
|
|
|
|
|
log.Println(out)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
log.Panicln(pkg.Owner.UserName)
|
|
|
|
|
if _, err := os.Stat(filepath.Join(git.GetPath(), pkg)); os.IsNotExist(err) {
|
|
|
|
|
common.LogDebug("Cloning factory...")
|
|
|
|
|
cloneDevel(git, "", pkg, factoryRepo.CloneURL, "pool", true) // in case we have imported
|
|
|
|
|
} else if err != nil {
|
|
|
|
|
common.PanicOnError(err)
|
|
|
|
|
} else {
|
|
|
|
|
// we have already cloned it... so, fetch pool remote
|
|
|
|
|
common.LogDebug("Fetching pool, as already should have the remote")
|
|
|
|
|
if err = git.GitExec(pkg, "fetch", "pool"); err != nil {
|
|
|
|
|
common.LogError(err)
|
|
|
|
|
return factoryRepo, err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for idx := 0; idx < len(oldPackageNames); idx++ {
|
|
|
|
|
pkgName := oldPackageNames[idx]
|
|
|
|
|
log.Println("fetching git:", pkgName)
|
|
|
|
|
remotes := common.SplitStringNoEmpty(git.GitExecWithOutputOrPanic(pkgName, "remote", "show", "-n"), "\n")
|
|
|
|
|
|
|
|
|
|
params := []string{"fetch", "--multiple"}
|
|
|
|
|
params = append(params, remotes...)
|
|
|
|
|
out, _ := git.GitExecWithOutput(pkgName, params...)
|
|
|
|
|
if len(strings.TrimSpace(out)) > 1 {
|
|
|
|
|
log.Println(out)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if slices.Contains(remotes, "origin") {
|
|
|
|
|
log.Println(" --- scmsync already, so we are done")
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// check if devel is ahead or behind factory and use that as reference
|
|
|
|
|
import_branch := "factory"
|
|
|
|
|
if len(common.SplitStringNoEmpty(git.GitExecWithOutputOrPanic(pkgName, "rev-list", "^factory", "devel"), "\n")) > 0 {
|
|
|
|
|
log.Println(" *** devel ahead. Swtiching branches.")
|
|
|
|
|
import_branch = "devel"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// check that nothing is broken with the update
|
|
|
|
|
if slices.Contains(remotes, "pool") {
|
|
|
|
|
// check which branch is ahead
|
|
|
|
|
branches, err := fs.ReadDir(os.DirFS(path.Join(git.GetPath(), pkgName, ".git/refs/remotes")), "pool")
|
|
|
|
|
if err != nil {
|
|
|
|
|
if forceBadPool {
|
|
|
|
|
log.Println(" *** factory has no branches!!! Treating as a devel package.")
|
|
|
|
|
develProjectPackages = append(develProjectPackages, pkgName)
|
|
|
|
|
continue
|
|
|
|
|
} else {
|
|
|
|
|
log.Panicln(" *** factory has no branches", branches)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pool_branch := "factory"
|
|
|
|
|
|
|
|
|
|
has_factory_devel := false
|
|
|
|
|
has_factory_factory := false
|
|
|
|
|
|
|
|
|
|
for _, branch := range branches {
|
|
|
|
|
if branch.Name() == "factory" {
|
|
|
|
|
has_factory_factory = true
|
|
|
|
|
} else if branch.Name() == "devel" {
|
|
|
|
|
has_factory_devel = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
log.Println(branches)
|
|
|
|
|
|
|
|
|
|
if has_factory_devel && has_factory_factory {
|
|
|
|
|
if len(common.SplitStringNoEmpty(git.GitExecWithOutputOrPanic(pkgName, "rev-list", "^pool/factory", "pool/devel"), "\n")) > 0 {
|
|
|
|
|
log.Println(" *** pool branch devel ahead. Switching branches.")
|
|
|
|
|
pool_branch = "devel"
|
|
|
|
|
}
|
|
|
|
|
} else if has_factory_devel && !has_factory_factory {
|
|
|
|
|
pool_branch = "devel"
|
|
|
|
|
} else if !has_factory_devel && has_factory_factory {
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
log.Panicln("branches screwed up for pkg", pkgName, branches)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// find tree object in factory branch
|
|
|
|
|
tree := strings.TrimSpace(git.GitExecWithOutputOrPanic(pkgName, "rev-list", "-1", "--format=%T", "--no-commit-header", "pool/"+pool_branch))
|
|
|
|
|
log.Println("tree", tree)
|
|
|
|
|
import_tree_commits := common.SplitStringNoEmpty(git.GitExecWithOutputOrPanic(pkgName, "rev-list", "--format=%H %T", "--no-commit-header", import_branch), "\n")
|
|
|
|
|
found := false
|
|
|
|
|
for i := range import_tree_commits {
|
|
|
|
|
commit_tree := strings.Split(import_tree_commits[i], " ")
|
|
|
|
|
if len(commit_tree) != 2 {
|
|
|
|
|
log.Panicln("wrong format?", commit_tree)
|
|
|
|
|
}
|
|
|
|
|
if commit_tree[1] == tree {
|
|
|
|
|
found = true
|
|
|
|
|
cherry_picks := common.SplitStringNoEmpty(git.GitExecWithOutputOrPanic(pkgName, "rev-list", "--no-merges", "--reverse", "--ancestry-path", commit_tree[0]+".."+import_branch), "\n")
|
|
|
|
|
|
|
|
|
|
log.Println("cherry picks", cherry_picks)
|
|
|
|
|
git.GitExecOrPanic(pkgName, "checkout", "-B", "main", "pool/"+pool_branch)
|
|
|
|
|
for _, pick := range cherry_picks {
|
|
|
|
|
git.GitExecOrPanic(pkgName, "cherry-pick", pick)
|
|
|
|
|
}
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !found {
|
|
|
|
|
log.Println("*** WARNING: Cannot find same tree for pkg", pkgName, "Will use current import instead")
|
|
|
|
|
git.GitExecOrPanic(pkgName, "checkout", "-B", "main", "heads/"+import_branch)
|
|
|
|
|
log.Println("setting main to", "heads/"+import_branch)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
log.Println("setting main to", "heads/"+import_branch)
|
|
|
|
|
git.GitExecOrPanic(pkgName, "checkout", "-B", "main", "heads/"+import_branch)
|
|
|
|
|
roots := 0
|
|
|
|
|
if _, err := git.GitRemoteHead(pkg, "pool", "devel"); err == nil {
|
|
|
|
|
factory_roots := strings.TrimSpace(git.GitExecWithOutputOrPanic(pkg, "rev-list", "pool/factory", "--max-parents=0"))
|
|
|
|
|
devel_roots := strings.TrimSpace(git.GitExecWithOutputOrPanic(pkg, "rev-list", "pool/devel", "--max-parents=0"))
|
|
|
|
|
roots = len(common.SplitLines(factory_roots))
|
|
|
|
|
if devel_roots != factory_roots || len(common.SplitLines(factory_roots)) != 1 {
|
|
|
|
|
roots = 10
|
|
|
|
|
}
|
|
|
|
|
} else if _, err := git.GitRemoteHead(pkg, "pool", "factory"); err == nil {
|
|
|
|
|
items := strings.TrimSpace(git.GitExecWithOutputOrPanic(pkg, "rev-list", "pool/factory", "--max-parents=0"))
|
|
|
|
|
roots = len(common.SplitLines(items))
|
|
|
|
|
} else {
|
|
|
|
|
common.LogInfo("No factory import ...")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for i := 0; i < len(develProjectPackages); i++ {
|
|
|
|
|
pkg := develProjectPackages[i]
|
|
|
|
|
log.Println("setting main branch for devel package:", pkg)
|
|
|
|
|
meta, err := obs.GetPackageMeta(prj, pkg)
|
|
|
|
|
if err != nil {
|
|
|
|
|
meta, err = obs.GetPackageMeta(prj, pkg)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Println("Error fetching pkg meta for:", prj, pkg, err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if meta == nil {
|
|
|
|
|
log.Println(" **** pkg meta is nil? ****")
|
|
|
|
|
} else if len(meta.ScmSync) > 0 {
|
|
|
|
|
if _, err := os.Stat(path.Join(git.GetPath(), pkg)); os.IsNotExist(err) {
|
|
|
|
|
if err2 := cloneDevel(git, "", pkg, meta.ScmSync); err2 != nil {
|
|
|
|
|
log.Panicln(err2)
|
|
|
|
|
}
|
|
|
|
|
git.GitExecOrPanic(pkg, "checkout", "-B", "main")
|
|
|
|
|
}
|
|
|
|
|
log.Println("skip for scmsync")
|
|
|
|
|
continue
|
|
|
|
|
} else {
|
|
|
|
|
common.PanicOnError(gitImporter(prj, pkg))
|
|
|
|
|
if out, err := git.GitExecWithOutput(pkg, "show-ref", "--branches"); err != nil || len(common.SplitStringNoEmpty(out, "\n")) == 0 {
|
|
|
|
|
log.Println(" *** no branches in package. removing")
|
|
|
|
|
develProjectPackages = slices.Delete(develProjectPackages, i, i+1)
|
|
|
|
|
i--
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// mark newer branch as main
|
|
|
|
|
branch := "factory"
|
|
|
|
|
if len(common.SplitStringNoEmpty(git.GitExecWithOutputOrPanic(pkg, "rev-list", "^factory", "devel"), "\n")) > 0 {
|
|
|
|
|
log.Println(" *** pool branch 'devel' ahead. Switching branches.")
|
|
|
|
|
branch = "devel"
|
|
|
|
|
}
|
|
|
|
|
log.Println("setting main to", branch)
|
|
|
|
|
git.GitExecOrPanic(pkg, "checkout", "-B", "main", branch)
|
|
|
|
|
if roots != 1 {
|
|
|
|
|
common.LogError("Expected 1 root in factory, but found", roots)
|
|
|
|
|
common.LogError("Ignoring current import")
|
|
|
|
|
common.PanicOnError(os.RemoveAll(path.Join(git.GetPath(), pkg)))
|
|
|
|
|
retErr = fmt.Errorf("Invalid factory repo -- treating as devel project only")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
slices.SortFunc(factoryRepos, func(a, b *models.Repository) int {
|
|
|
|
|
if a.Name == b.Name {
|
|
|
|
|
orgOrderNo := func(org string) int {
|
|
|
|
|
switch org {
|
|
|
|
|
case "pool":
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
return 0 // current devel to clone
|
|
|
|
|
}
|
|
|
|
|
devel_project, err := devel_projects.GetDevelProject(pkg)
|
|
|
|
|
common.LogDebug("Devel project:", devel_project, err)
|
|
|
|
|
if err == common.DevelProjectNotFound {
|
|
|
|
|
// assume it's this project, maybe removed from factory
|
|
|
|
|
devel_project = prj
|
|
|
|
|
}
|
|
|
|
|
common.LogDebug("finding missing branches in", pkg, devel_project)
|
|
|
|
|
findMissingDevelBranch(git, pkg, devel_project)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return orgOrderNo(a.Owner.UserName) - orgOrderNo(b.Owner.UserName)
|
|
|
|
|
}
|
|
|
|
|
return strings.Compare(a.Name, b.Name)
|
|
|
|
|
})
|
|
|
|
|
factoryRepos = slices.CompactFunc(factoryRepos, func(a, b *models.Repository) bool {
|
|
|
|
|
return a.Name == b.Name
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
for _, pkg := range factoryRepos {
|
|
|
|
|
log.Println("factory fork creator for develProjectPackage:", pkg.Name)
|
|
|
|
|
var repo *models.Repository
|
|
|
|
|
if repoData, err := client.Repository.RepoGet(repository.NewRepoGetParams().WithOwner(org).WithRepo(pkg.Name), r.DefaultAuthentication); err != nil {
|
|
|
|
|
// update package
|
|
|
|
|
fork, err := client.Repository.CreateFork(repository.NewCreateForkParams().
|
|
|
|
|
WithOwner(pkg.Owner.UserName).
|
|
|
|
|
WithRepo(pkg.Name).
|
|
|
|
|
WithBody(&models.CreateForkOption{
|
|
|
|
|
Organization: org,
|
|
|
|
|
}), r.DefaultAuthentication)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Panicln("Error while trying to create fork from", pkg.Owner.UserName, pkg.Name, "to", org, ":", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
repo = fork.Payload
|
|
|
|
|
} else {
|
|
|
|
|
repo = repoData.Payload
|
|
|
|
|
}
|
|
|
|
|
// branchName := repo.DefaultBranch
|
|
|
|
|
|
|
|
|
|
remotes := common.SplitStringNoEmpty(git.GitExecWithOutputOrPanic(pkg.Name, "remote", "show"), "\n")
|
|
|
|
|
if !slices.Contains(remotes, "develorigin") {
|
|
|
|
|
git.GitExecOrPanic(pkg.Name, "remote", "add", "develorigin", repo.SSHURL)
|
|
|
|
|
// git.GitExecOrPanic(pkgName, "fetch", "devel")
|
|
|
|
|
}
|
|
|
|
|
if slices.Contains(remotes, "origin") {
|
|
|
|
|
git.GitExecOrPanic(pkg.Name, "lfs", "fetch", "--all")
|
|
|
|
|
git.GitExecOrPanic(pkg.Name, "lfs", "push", "develorigin", "--all")
|
|
|
|
|
}
|
|
|
|
|
git.GitExecOrPanic(pkg.Name, "push", "develorigin", "main", "-f")
|
|
|
|
|
branches := common.SplitStringNoEmpty(git.GitExecWithOutputOrPanic(pkg.Name, "branch", "-r"), "\n")
|
|
|
|
|
for _, b := range branches {
|
|
|
|
|
if len(b) > 12 && b[0:12] == "develorigin/" {
|
|
|
|
|
b = b[12:]
|
|
|
|
|
if b == "factory" || b == "devel" {
|
|
|
|
|
git.GitExec(pkg.Name, "push", "develorigin", "--delete", b)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// git.GitExecOrPanic(pkg.ame, "checkout", "-B", "main", "devel/main")
|
|
|
|
|
_, err := client.Repository.RepoEdit(repository.NewRepoEditParams().WithOwner(org).WithRepo(giteaPackage(repo.Name)).WithBody(&models.EditRepoOption{
|
|
|
|
|
DefaultBranch: "main",
|
|
|
|
|
DefaultMergeStyle: "fast-forward-only",
|
|
|
|
|
func SetRepoOptions(repo *models.Repository) {
|
|
|
|
|
_, err := client.Repository.RepoEdit(repository.NewRepoEditParams().WithOwner(org).WithRepo(repo.Name).WithBody(
|
|
|
|
|
&models.EditRepoOption{
|
|
|
|
|
HasPullRequests: true,
|
|
|
|
|
HasPackages: false,
|
|
|
|
|
HasReleases: false,
|
|
|
|
@@ -536,91 +290,305 @@ func importRepos(packages []string) {
|
|
|
|
|
AllowRebaseUpdate: false,
|
|
|
|
|
AllowManualMerge: true,
|
|
|
|
|
AutodetectManualMerge: true,
|
|
|
|
|
DefaultMergeStyle: "fast-forward-only",
|
|
|
|
|
AllowRebase: false,
|
|
|
|
|
DefaultAllowMaintainerEdit: true,
|
|
|
|
|
}), r.DefaultAuthentication)
|
|
|
|
|
DefaultBranch: "main",
|
|
|
|
|
}),
|
|
|
|
|
r.DefaultAuthentication,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Panicln("Failed to adjust repository:", repo.Name, err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func CreatePoolFork(factoryRepo *models.Repository) *models.Repository {
|
|
|
|
|
pkg := factoryRepo.Name
|
|
|
|
|
log.Println("factory fork creator for develProjectPackage:", pkg)
|
|
|
|
|
if repoData, err := client.Repository.RepoGet(repository.NewRepoGetParams().WithOwner(org).WithRepo(pkg), r.DefaultAuthentication); err != nil {
|
|
|
|
|
// update package
|
|
|
|
|
fork, err := client.Repository.CreateFork(repository.NewCreateForkParams().
|
|
|
|
|
WithOwner("pool").
|
|
|
|
|
WithRepo(factoryRepo.Name).
|
|
|
|
|
WithBody(&models.CreateForkOption{
|
|
|
|
|
Organization: org,
|
|
|
|
|
}), r.DefaultAuthentication)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Panicln("Error while trying to create fork from 'pool'", pkg, "to", org, ":", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
repo := fork.Payload
|
|
|
|
|
return repo
|
|
|
|
|
} else {
|
|
|
|
|
return repoData.Payload
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func CreateDevelOnlyPackage(pkg string) *models.Repository {
|
|
|
|
|
log.Println("repo creator for develProjectPackage:", pkg)
|
|
|
|
|
if repoData, err := client.Repository.RepoGet(repository.NewRepoGetParams().WithOwner(org).WithRepo(giteaPackage(pkg)), r.DefaultAuthentication); err != nil {
|
|
|
|
|
giteaPkg := giteaPackage(pkg)
|
|
|
|
|
repoData, err := client.Organization.CreateOrgRepo(organization.NewCreateOrgRepoParams().WithOrg(org).WithBody(
|
|
|
|
|
&models.CreateRepoOption{
|
|
|
|
|
ObjectFormatName: "sha256",
|
|
|
|
|
AutoInit: false,
|
|
|
|
|
Name: &giteaPkg,
|
|
|
|
|
DefaultBranch: "main",
|
|
|
|
|
}),
|
|
|
|
|
r.DefaultAuthentication,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Panicln("Failed to set default branch for package fork:", repo.Owner.UserName, "/", repo.Name, err)
|
|
|
|
|
log.Panicln("Error creating new package repository:", pkg, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
repo := repoData.Payload
|
|
|
|
|
return repo
|
|
|
|
|
} else {
|
|
|
|
|
return repoData.Payload
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, pkg := range develProjectPackages {
|
|
|
|
|
log.Println("repo creator for develProjectPackage:", pkg)
|
|
|
|
|
var repo *models.Repository
|
|
|
|
|
if repoData, err := client.Repository.RepoGet(repository.NewRepoGetParams().WithOwner(org).WithRepo(giteaPackage(pkg)), r.DefaultAuthentication); err != nil {
|
|
|
|
|
giteaPkg := giteaPackage(pkg)
|
|
|
|
|
_, err := client.Organization.CreateOrgRepo(organization.NewCreateOrgRepoParams().WithOrg(org).WithBody(
|
|
|
|
|
&models.CreateRepoOption{
|
|
|
|
|
ObjectFormatName: "sha256",
|
|
|
|
|
AutoInit: false,
|
|
|
|
|
Name: &giteaPkg,
|
|
|
|
|
DefaultBranch: "main",
|
|
|
|
|
}),
|
|
|
|
|
r.DefaultAuthentication,
|
|
|
|
|
)
|
|
|
|
|
func PushRepository(factoryRepo, develRepo *models.Repository, pkg string) (repo *models.Repository) {
|
|
|
|
|
// branchName := repo.DefaultBranch
|
|
|
|
|
if factoryRepo != nil {
|
|
|
|
|
repo = CreatePoolFork(factoryRepo)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Panicln("Error creating new package repository:", pkg, err)
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
devel
|
|
|
|
|
for _, b := range branches {
|
|
|
|
|
if len(b) > 12 && b[0:12] == "develorigin/" {
|
|
|
|
|
b = b[12:]
|
|
|
|
|
if b == "factory" || b == "devel" {
|
|
|
|
|
git.GitExec(pkg, "push", "develorigin", "--delete", b)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
ret, err := client.Repository.RepoEdit(repository.NewRepoEditParams().WithOwner(org).WithRepo(giteaPkg).WithBody(
|
|
|
|
|
&models.EditRepoOption{
|
|
|
|
|
HasPullRequests: true,
|
|
|
|
|
HasPackages: false,
|
|
|
|
|
HasReleases: false,
|
|
|
|
|
HasActions: false,
|
|
|
|
|
AllowMerge: true,
|
|
|
|
|
AllowRebaseMerge: false,
|
|
|
|
|
AllowSquash: false,
|
|
|
|
|
AllowFastForwardOnly: true,
|
|
|
|
|
AllowRebaseUpdate: false,
|
|
|
|
|
AllowManualMerge: true,
|
|
|
|
|
AutodetectManualMerge: true,
|
|
|
|
|
DefaultMergeStyle: "fast-forward-only",
|
|
|
|
|
AllowRebase: false,
|
|
|
|
|
DefaultAllowMaintainerEdit: true,
|
|
|
|
|
}),
|
|
|
|
|
r.DefaultAuthentication,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Panicln("Failed to adjust repository:", pkg, err)
|
|
|
|
|
}
|
|
|
|
|
repo = ret.Payload
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
repo = repoData.Payload
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
remotes := common.SplitStringNoEmpty(git.GitExecWithOutputOrPanic(pkg, "remote", "show"), "\n")
|
|
|
|
|
if !slices.Contains(remotes, "develorigin") {
|
|
|
|
|
git.GitExecOrPanic(pkg, "remote", "add", "develorigin", repo.SSHURL)
|
|
|
|
|
}
|
|
|
|
|
if slices.Contains(remotes, "origin") {
|
|
|
|
|
git.GitExecOrPanic(pkg, "lfs", "fetch", "--all")
|
|
|
|
|
git.GitExecOrPanic(pkg, "lfs", "push", "develorigin", "--all")
|
|
|
|
|
}
|
|
|
|
|
git.GitExecOrPanic(pkg, "push", "develorigin", "main", "-f")
|
|
|
|
|
branches := common.SplitStringNoEmpty(git.GitExecWithOutputOrPanic(pkg, "branch", "-r"), "\n")
|
|
|
|
|
//branches := common.SplitStringNoEmpty(git.GitExecWithOutputOrPanic(pkg.Name, "branch", "-r"), "\n")
|
|
|
|
|
/* factory
|
|
|
|
|
for _, b := range branches {
|
|
|
|
|
if len(b) > 12 && b[0:12] == "develorigin/" {
|
|
|
|
|
b = b[12:]
|
|
|
|
|
if b == "factory" || b == "devel" {
|
|
|
|
|
git.GitExec(pkg, "push", "develorigin", "--delete", b)
|
|
|
|
|
git.GitExec(pkg.Name, "push", "develorigin", "--delete", b)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
// git.GitExecOrPanic(pkg.ame, "checkout", "-B", "main", "devel/main")
|
|
|
|
|
} else {
|
|
|
|
|
repo = CreateDevelOnlyPackage(pkg)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err := client.Repository.RepoEdit(repository.NewRepoEditParams().WithOwner(org).WithRepo(giteaPackage(pkg)).WithBody(&models.EditRepoOption{
|
|
|
|
|
DefaultBranch: "main",
|
|
|
|
|
DefaultMergeStyle: "fast-forward-only",
|
|
|
|
|
}), r.DefaultAuthentication)
|
|
|
|
|
remotes := common.SplitStringNoEmpty(git.GitExecWithOutputOrPanic(pkg, "remote", "show"), "\n")
|
|
|
|
|
if !slices.Contains(remotes, "develorigin") {
|
|
|
|
|
git.GitExecOrPanic(pkg, "remote", "add", "develorigin", repo.SSHURL)
|
|
|
|
|
// git.GitExecOrPanic(pkgName, "fetch", "devel")
|
|
|
|
|
}
|
|
|
|
|
if slices.Contains(remotes, "origin") {
|
|
|
|
|
git.GitExecOrPanic(pkg, "lfs", "fetch", "--all")
|
|
|
|
|
git.GitExecOrPanic(pkg, "lfs", "push", "develorigin", "--all")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Panicln("Failed to set default branch for package fork:", repo.Owner.UserName, "/", repo.Name, err)
|
|
|
|
|
git.GitExecOrPanic(pkg, "push", "develorigin", "main", "-f")
|
|
|
|
|
SetRepoOptions(repo)
|
|
|
|
|
git.GitExec(pkg, "push", "develorigin", "--delete", "factory")
|
|
|
|
|
git.GitExec(pkg, "push", "develorigin", "--delete", "devel")
|
|
|
|
|
git.GitExec(pkg, "push", "develorigin", "--delete", "leap-16.0")
|
|
|
|
|
return repo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func importDevelRepoAndCheckHistory(pkg string, meta *common.PackageMeta) *models.Repository {
|
|
|
|
|
repo := CreateDevelOnlyPackage(pkg)
|
|
|
|
|
if _, err := os.Stat(filepath.Join(git.GetPath(), pkg)); os.IsNotExist(err) {
|
|
|
|
|
cloneDevel(git, "", pkg, repo.SSHURL, "develorigin", false) // in case we have imported
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if CloneScmsync(pkg, meta) {
|
|
|
|
|
return repo
|
|
|
|
|
}
|
|
|
|
|
var p, dp string
|
|
|
|
|
factory_branch, fhe := git.GitRemoteHead(pkg, "develorigin", "factory")
|
|
|
|
|
if fhe == nil {
|
|
|
|
|
p = strings.TrimSpace(git.GitExecWithOutputOrPanic(pkg, "rev-list", "--max-parents=0", "--count", factory_branch))
|
|
|
|
|
} else {
|
|
|
|
|
common.LogError(fhe)
|
|
|
|
|
}
|
|
|
|
|
devel_branch, dhe := git.GitRemoteHead(pkg, "develorigin", "devel")
|
|
|
|
|
if dhe != nil {
|
|
|
|
|
devel_project, err := devel_projects.GetDevelProject(pkg)
|
|
|
|
|
common.LogDebug("Devel project:", devel_project, err)
|
|
|
|
|
if err == common.DevelProjectNotFound {
|
|
|
|
|
// assume it's this project, maybe removed from factory
|
|
|
|
|
devel_project = prj
|
|
|
|
|
}
|
|
|
|
|
common.LogDebug("finding missing branches in", pkg, devel_project)
|
|
|
|
|
findMissingDevelBranch(git, pkg, devel_project)
|
|
|
|
|
devel_branch, dhe = git.GitBranchHead(pkg, "devel")
|
|
|
|
|
}
|
|
|
|
|
if dhe == nil {
|
|
|
|
|
dp = strings.TrimSpace(git.GitExecWithOutputOrPanic(pkg, "rev-list", "--max-parents=0", "--count", devel_branch))
|
|
|
|
|
} else {
|
|
|
|
|
common.LogError(dhe)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// even if one parent for both, we need common ancestry, or we are comparing different things.
|
|
|
|
|
mb, mb_err := git.GitExecWithOutput(pkg, "merge-base", factory_branch, devel_branch)
|
|
|
|
|
mb = strings.TrimSpace(mb)
|
|
|
|
|
|
|
|
|
|
if p != "1" || dp != "1" || mb_err != nil || mb != factory_branch || mb != devel_branch {
|
|
|
|
|
common.LogInfo("Bad export found ... clearing", p, dp)
|
|
|
|
|
common.LogInfo(" merge branch:", mb, factory_branch, devel_branch, mb_err)
|
|
|
|
|
common.PanicOnError(os.RemoveAll(path.Join(git.GetPath(), pkg)))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := gitImporter("openSUSE:Factory", pkg); err != nil {
|
|
|
|
|
common.PanicOnError(gitImporter(prj, pkg))
|
|
|
|
|
}
|
|
|
|
|
if p := strings.TrimSpace(git.GitExecWithOutputOrPanic(pkg, "rev-list", "--max-parents=0", "--count", "factory")); p != "1" {
|
|
|
|
|
common.LogError("Failed to import package:", pkg)
|
|
|
|
|
common.PanicOnError(fmt.Errorf("Expecting 1 root in after devel import, but have %s", p))
|
|
|
|
|
}
|
|
|
|
|
if out, err := git.GitExecWithOutput(pkg, "show-ref", "--branches"); err != nil || len(common.SplitStringNoEmpty(out, "\n")) == 0 {
|
|
|
|
|
common.LogError(" *** no branches in package. removing")
|
|
|
|
|
return repo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return repo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func SetMainBranch(pkg string, meta *common.PackageMeta) {
|
|
|
|
|
// scnsync, follow that and don't care
|
|
|
|
|
common.LogDebug("Setting main branch...")
|
|
|
|
|
remotes := common.SplitStringNoEmpty(git.GitExecWithOutputOrPanic(pkg, "remote", "show"), "\n")
|
|
|
|
|
if slices.Contains(remotes, "origin") {
|
|
|
|
|
u, err := url.Parse(meta.ScmSync)
|
|
|
|
|
common.PanicOnError(err)
|
|
|
|
|
if len(u.Fragment) == 0 {
|
|
|
|
|
u.Fragment = "HEAD"
|
|
|
|
|
}
|
|
|
|
|
if err := git.GitExec(pkg, "checkout", "-B", "main", u.Fragment); err != nil {
|
|
|
|
|
git.GitExecOrPanic(pkg, "checkout", "-B", "main", "origin/"+u.Fragment)
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// check if we have factory
|
|
|
|
|
if _, err := git.GitBranchHead(pkg, "factory"); err != nil {
|
|
|
|
|
if len(git.GitExecWithOutputOrPanic(pkg, "show-ref", "pool/factory")) > 20 {
|
|
|
|
|
git.GitExecOrPanic(pkg, "branch", "factory", "pool/factory")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// mark newer branch as main
|
|
|
|
|
branch := "factory"
|
|
|
|
|
if len(common.SplitStringNoEmpty(git.GitExecWithOutputOrPanic(pkg, "rev-list", "^factory", "devel"), "\n")) > 0 {
|
|
|
|
|
branch = "devel"
|
|
|
|
|
}
|
|
|
|
|
common.LogInfo("setting main to", branch)
|
|
|
|
|
git.GitExecOrPanic(pkg, "checkout", "-B", "main", branch)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ObsToRepoName(obspkg string) string {
|
|
|
|
|
return strings.ReplaceAll(obspkg, "+", "_")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ImportSha1Sync(pkg string, url *url.URL) {
|
|
|
|
|
common.LogDebug("Converting SHA1", url.String())
|
|
|
|
|
|
|
|
|
|
branch := url.Fragment
|
|
|
|
|
url.Fragment = ""
|
|
|
|
|
p := path.Join(pkg, "sha1stuff")
|
|
|
|
|
common.PanicOnError(os.RemoveAll(path.Join(git.GetPath(), p)))
|
|
|
|
|
git.GitExecOrPanic(pkg, "clone", "--mirror", url.String(), "sha1stuff")
|
|
|
|
|
git.GitExecOrPanic(p, "fetch", "origin", branch)
|
|
|
|
|
|
|
|
|
|
gitexport := exec.Command("/usr/bin/git", "fast-export", "--signed-tags=strip", "--tag-of-filtered-object=drop", "--all")
|
|
|
|
|
gitexport.Dir = path.Join(git.GetPath(), p)
|
|
|
|
|
gitexportData, err := gitexport.Output()
|
|
|
|
|
common.LogDebug("Got export data size:", len(gitexportData))
|
|
|
|
|
common.PanicOnError(err)
|
|
|
|
|
gitimport := exec.Command("/usr/bin/git", "fast-import", "--allow-unsafe-features")
|
|
|
|
|
gitimport.Dir = path.Join(git.GetPath(), pkg)
|
|
|
|
|
gitimport.Stdin = bytes.NewReader(gitexportData)
|
|
|
|
|
data, err := gitimport.CombinedOutput()
|
|
|
|
|
common.LogError(string(data))
|
|
|
|
|
common.PanicOnError(err)
|
|
|
|
|
common.PanicOnError(os.RemoveAll(path.Join(git.GetPath(), p)))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func LfsImport(pkg string) {
|
|
|
|
|
git.GitExecOrPanic(pkg, "lfs", "migrate", "import", "--everything",
|
|
|
|
|
"--include=*.7z,*.bsp,*.bz2,*.gem,*.gz,*.jar,*.lz,*.lzma,*.obscpio,*.oxt,*.pdf,*.png,*.rpm,*.tar,*.tbz,*.tbz2,*.tgz,*.ttf,*.txz,*.whl,*.xz,*.zip,*.zst")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func CloneScmsync(pkg string, meta *common.PackageMeta) bool {
|
|
|
|
|
if len(meta.ScmSync) > 0 {
|
|
|
|
|
u, _ := url.Parse(meta.ScmSync)
|
|
|
|
|
if remotes := common.SplitStringNoEmpty(git.GitExecWithOutputOrPanic(pkg, "remote", "show"), "\n"); !slices.Contains(remotes, "origin") {
|
|
|
|
|
branch := u.Fragment
|
|
|
|
|
if len(branch) == 0 {
|
|
|
|
|
branch = "HEAD"
|
|
|
|
|
}
|
|
|
|
|
u.Fragment = ""
|
|
|
|
|
git.GitExecOrPanic(pkg, "remote", "add", "origin", u.String())
|
|
|
|
|
u.Fragment = branch
|
|
|
|
|
}
|
|
|
|
|
if err := git.GitExec(pkg, "fetch", "origin"); err != nil && strings.Contains(err.Error(), "fatal: mismatched algorithms: client sha256; server sha1") {
|
|
|
|
|
ImportSha1Sync(pkg, u)
|
|
|
|
|
} else if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LfsImport(pkg)
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func importRepo(pkg string) (BrokenFactoryPackage, FailedImport bool) {
|
|
|
|
|
BrokenFactoryPackage = false
|
|
|
|
|
FailedImport = false
|
|
|
|
|
|
|
|
|
|
var develRepo, factoryRepo *models.Repository
|
|
|
|
|
|
|
|
|
|
src_pkg_name := strings.Split(pkg, ":")
|
|
|
|
|
pkg = src_pkg_name[0]
|
|
|
|
|
|
|
|
|
|
meta, err := obs.GetPackageMeta(prj, pkg)
|
|
|
|
|
if err != nil {
|
|
|
|
|
meta, err = obs.GetPackageMeta(prj, pkg)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Println("Error fetching pkg meta for:", prj, pkg, err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if err != nil {
|
|
|
|
|
common.PanicOnError(err)
|
|
|
|
|
}
|
|
|
|
|
if meta == nil {
|
|
|
|
|
panic("package meta is nil...")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
factoryRepo, err = importFactoryRepoAndCheckHistory(pkg, meta)
|
|
|
|
|
if factoryRepo != nil && err != nil {
|
|
|
|
|
BrokenFactoryPackage = true
|
|
|
|
|
}
|
|
|
|
|
if factoryRepo == nil && forceNonPoolPackages {
|
|
|
|
|
log.Println(" IGNORING and will create these as non-pool packages!")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if factoryRepo == nil || BrokenFactoryPackage {
|
|
|
|
|
develRepo = importDevelRepoAndCheckHistory(pkg, meta)
|
|
|
|
|
} else {
|
|
|
|
|
CloneScmsync(pkg, meta)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetMainBranch(pkg, meta)
|
|
|
|
|
PushRepository(factoryRepo, develRepo, pkg)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func syncOrgTeams(groupName string, origTeam []common.PersonRepoMeta) []string {
|
|
|
|
@@ -763,6 +731,11 @@ func syncMaintainersToGitea(pkgs []string) {
|
|
|
|
|
missingDevs := []string{}
|
|
|
|
|
devs := []string{}
|
|
|
|
|
|
|
|
|
|
if len(prjMeta.ScmSync) > 0 {
|
|
|
|
|
common.LogInfo("Project already in Git. Maintainers must have been already synced. Skipping...")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, group := range prjMeta.Groups {
|
|
|
|
|
if group.GroupID == "factory-maintainers" {
|
|
|
|
|
log.Println("Ignoring factory-maintainers")
|
|
|
|
@@ -881,6 +854,17 @@ func createPrjGit() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TrimMultibuildPackages(packages []string) []string {
|
|
|
|
|
for i := 0; i < len(packages); {
|
|
|
|
|
if strings.Contains(packages[i], ":") {
|
|
|
|
|
packages = slices.Delete(packages, i, i+1)
|
|
|
|
|
} else {
|
|
|
|
|
i++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return packages
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var client *apiclient.GiteaAPI
|
|
|
|
|
var r *transport.Runtime
|
|
|
|
|
var git common.Git
|
|
|
|
@@ -916,12 +900,18 @@ func main() {
|
|
|
|
|
flags.BoolVar(&forceBadPool, "bad-pool", false, "Force packages if pool has no branches due to bad import")
|
|
|
|
|
flags.BoolVar(&forceNonPoolPackages, "non-pool", false, "Allow packages that are not in pool to be created. WARNING: Can't add to factory later!")
|
|
|
|
|
specificPackages := flags.String("packages", "", "Process specific package, separated by commas, ignoring the others")
|
|
|
|
|
resumeAt := flags.String("resume", "", "Resume import at given pacakge")
|
|
|
|
|
syncPool := flags.Bool("sync-pool-only", false, "Force updates pool based on currrently imported project")
|
|
|
|
|
|
|
|
|
|
if help := flags.Parse(os.Args[1:]); help == flag.ErrHelp || flags.NArg() != 2 {
|
|
|
|
|
printHelp(helpString.String())
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if DebugMode {
|
|
|
|
|
common.SetLoggingLevel(common.LogLevelDebug)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
r = transport.New(*giteaHost, apiclient.DefaultBasePath, [](string){"https"})
|
|
|
|
|
r.DefaultAuthentication = transport.BearerToken(common.GetGiteaToken())
|
|
|
|
|
// r.SetDebug(true)
|
|
|
|
@@ -956,13 +946,7 @@ func main() {
|
|
|
|
|
prj = flags.Arg(0)
|
|
|
|
|
org = flags.Arg(1)
|
|
|
|
|
packages, err := runObsCommand("ls", prj)
|
|
|
|
|
for i := 0; i < len(packages); {
|
|
|
|
|
if strings.Contains(packages[i], ":") {
|
|
|
|
|
packages = slices.Delete(packages, i, i+1)
|
|
|
|
|
} else {
|
|
|
|
|
i++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
packages = TrimMultibuildPackages(packages)
|
|
|
|
|
|
|
|
|
|
git, err = gh.CreateGitHandler(org)
|
|
|
|
|
if err != nil {
|
|
|
|
@@ -971,6 +955,27 @@ func main() {
|
|
|
|
|
defer git.Close()
|
|
|
|
|
log.Println(" - working directory:" + git.GetPath())
|
|
|
|
|
|
|
|
|
|
if *syncPool {
|
|
|
|
|
factory_pkgs, err := runObsCommand("ls", "openSUSE:Factory")
|
|
|
|
|
common.PanicOnError(err)
|
|
|
|
|
common.LogInfo("Syncing pool only...")
|
|
|
|
|
factory_pkgs = TrimMultibuildPackages(factory_pkgs)
|
|
|
|
|
|
|
|
|
|
for _, pkg := range packages {
|
|
|
|
|
if !slices.Contains(factory_pkgs, pkg) {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
repo, err := client.Repository.RepoGet(repository.NewRepoGetParams().WithOwner(org).WithRepo(ObsToRepoName(pkg)), r.DefaultAuthentication)
|
|
|
|
|
common.PanicOnError(err)
|
|
|
|
|
|
|
|
|
|
if !slices.Contains(common.SplitLines(git.GitExecWithOutputOrPanic(pkg, "remote")), "pool") {
|
|
|
|
|
git.GitExecOrPanic(pkg, "remote", "add", "pool", repo.Payload.SSHURL)
|
|
|
|
|
}
|
|
|
|
|
git.GitExecOrPanic(pkg, "fetch", "pool")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
for _, pkg := range packages {
|
|
|
|
|
if _, err := client.Organization.CreateOrgRepo(organization.NewCreateOrgRepoParams().WithOrg(org).WithBody(
|
|
|
|
@@ -1011,16 +1016,42 @@ func main() {
|
|
|
|
|
|
|
|
|
|
if *purgeOnly {
|
|
|
|
|
log.Println("Purging repositories...")
|
|
|
|
|
for _, pkg := range packages {
|
|
|
|
|
pkgs := packages
|
|
|
|
|
if len(*specificPackages) > 0 {
|
|
|
|
|
pkgs = common.SplitStringNoEmpty(*specificPackages, ",")
|
|
|
|
|
}
|
|
|
|
|
for _, pkg := range pkgs {
|
|
|
|
|
client.Repository.RepoDelete(repository.NewRepoDeleteParams().WithOwner(org).WithRepo(giteaPackage(pkg)), r.DefaultAuthentication)
|
|
|
|
|
}
|
|
|
|
|
os.Exit(10)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(*specificPackages) != 0 {
|
|
|
|
|
importRepos(common.SplitStringNoEmpty(*specificPackages, ","))
|
|
|
|
|
return
|
|
|
|
|
packages = common.SplitStringNoEmpty(*specificPackages, ",")
|
|
|
|
|
}
|
|
|
|
|
importRepos(packages)
|
|
|
|
|
slices.Sort(packages)
|
|
|
|
|
|
|
|
|
|
BrokenOBSPackage := []string{}
|
|
|
|
|
FailedImport := []string{}
|
|
|
|
|
for _, pkg := range packages {
|
|
|
|
|
if len(*resumeAt) > 0 && strings.Compare(*resumeAt, pkg) > 0 {
|
|
|
|
|
common.LogDebug(pkg, "skipped due to resuming at", *resumeAt)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
b, f := importRepo(pkg)
|
|
|
|
|
if b {
|
|
|
|
|
BrokenOBSPackage = append(BrokenOBSPackage, pkg)
|
|
|
|
|
}
|
|
|
|
|
if f {
|
|
|
|
|
FailedImport = append(FailedImport, pkg)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
syncMaintainersToGitea(packages)
|
|
|
|
|
|
|
|
|
|
common.LogError("Have broken pool packages:", len(BrokenOBSPackage))
|
|
|
|
|
// common.LogError("Total pool packages:", len(factoryRepos))
|
|
|
|
|
common.LogError("Failed to import:", strings.Join(FailedImport, ","))
|
|
|
|
|
common.LogInfo("BROKEN Pool packages:", strings.Join(BrokenOBSPackage, "\n"))
|
|
|
|
|
}
|
|
|
|
|