Rename variables
This commit is contained in:
parent
a47d217ab3
commit
3a2c590158
@ -116,8 +116,8 @@ func main() {
|
||||
os.Exit(10)
|
||||
}
|
||||
|
||||
oldPackageRepos := make([]*models.Repository, 0, len(packages))
|
||||
newPackages := make([]string, 0, len(packages))
|
||||
factoryRepos := make([]*models.Repository, 0, len(packages)*2)
|
||||
develProjectPackages := make([]string, 0, len(packages))
|
||||
for _, pkg := range packages {
|
||||
src_pkg_name := strings.Split(pkg, ":")
|
||||
repo, err := client.Repository.RepoGet(
|
||||
@ -125,29 +125,45 @@ func main() {
|
||||
WithDefaults().WithOwner("pool").WithRepo(src_pkg_name[0]),
|
||||
r.DefaultAuthentication)
|
||||
|
||||
rpm, rpmErr := client.Repository.RepoGet(
|
||||
repository.NewRepoGetParams().WithDefaults().WithOwner("rpm").WithRepo(src_pkg_name[0]),
|
||||
r.DefaultAuthentication)
|
||||
|
||||
if rpmErr == nil {
|
||||
factoryRepos = append(factoryRepos, rpm.Payload)
|
||||
} else {
|
||||
if !errors.Is(rpmErr, &repository.RepoGetNotFound{}) {
|
||||
log.Panicln(rpmErr)
|
||||
}
|
||||
|
||||
log.Println("No RPM package?", src_pkg_name)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if !errors.Is(err, &repository.RepoGetNotFound{}) {
|
||||
log.Panicln(err)
|
||||
}
|
||||
|
||||
log.Println("Cannot find src package:", src_pkg_name)
|
||||
newPackages = append(newPackages, src_pkg_name[0])
|
||||
develProjectPackages = append(develProjectPackages, src_pkg_name[0])
|
||||
} else {
|
||||
oldPackageRepos = append(oldPackageRepos, repo.Payload)
|
||||
factoryRepos = append(factoryRepos, repo.Payload)
|
||||
}
|
||||
|
||||
}
|
||||
log.Println("Num repos found:", len(oldPackageRepos))
|
||||
log.Println("Num repos found:", len(factoryRepos))
|
||||
|
||||
oldPackageNames := make([]string, 0, len(factoryRepos))
|
||||
for _, repo := range factoryRepos {
|
||||
oldPackageNames = append(oldPackageNames, repo.Name)
|
||||
}
|
||||
slices.Sort(oldPackageNames)
|
||||
oldPackageNames = slices.Compact(oldPackageNames)
|
||||
copy(oldPackageNames[2:], oldPackageNames)
|
||||
log.Println("Num of old packages:", len(oldPackageNames))
|
||||
|
||||
// fork packags from pool
|
||||
cmd := exec.Command("./git-importer", func(r []*models.Repository) []string {
|
||||
ret := make([]string, len(r)+2)
|
||||
ret[0] = "-r"
|
||||
ret[1] = git.GitPath
|
||||
for i := range r {
|
||||
ret[i+2] = r[i].Name
|
||||
}
|
||||
return ret
|
||||
}(oldPackageRepos)...)
|
||||
cmd := exec.Command("./git-importer", append([]string{"-r", git.GitPath}, oldPackageNames...)...)
|
||||
out, err := cmd.CombinedOutput()
|
||||
log.Println(string(out))
|
||||
if err != nil {
|
||||
@ -155,48 +171,56 @@ func main() {
|
||||
}
|
||||
|
||||
reposOK := true
|
||||
for i := range oldPackageRepos {
|
||||
pkg := oldPackageRepos[i]
|
||||
log.Println("adding remotes...")
|
||||
for i := range factoryRepos {
|
||||
pkg := factoryRepos[i]
|
||||
|
||||
// add remote repos
|
||||
out := git.GitExecWithOutputOrPanic(pkg.Name, "remote", "show", "-n")
|
||||
if !slices.Contains(strings.Split(out, "\n"), "factory") {
|
||||
out := git.GitExecWithOutputOrPanic(pkg.Name, "remote", "add", "factory", pkg.CloneURL)
|
||||
if len(strings.TrimSpace(out)) > 1 {
|
||||
log.Println(out)
|
||||
}
|
||||
}
|
||||
if !slices.Contains(strings.Split(out, "\n"), "rpm") {
|
||||
out := git.GitExecWithOutputOrPanic(pkg.Name, "remote", "add", "rpm", "https://src.opensuse.org/rpm/"+pkg.Name+".git")
|
||||
if len(strings.TrimSpace(out)) > 1 {
|
||||
log.Println(out)
|
||||
switch pkg.Owner.UserName {
|
||||
case "pool":
|
||||
if !slices.Contains(strings.Split(out, "\n"), "factory") {
|
||||
out := git.GitExecWithOutputOrPanic(pkg.Name, "remote", "add", "factory", pkg.CloneURL)
|
||||
if len(strings.TrimSpace(out)) > 1 {
|
||||
log.Println(out)
|
||||
}
|
||||
}
|
||||
case "rpm":
|
||||
if !slices.Contains(strings.Split(out, "\n"), "rpm") {
|
||||
out := git.GitExecWithOutputOrPanic(pkg.Name, "remote", "add", "rpm", pkg.CloneURL)
|
||||
if len(strings.TrimSpace(out)) > 1 {
|
||||
log.Println(out)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
out = git.GitExecWithOutputOrPanic(pkg.Name, "fetch", "--multiple", "factory", "rpm")
|
||||
for _, pkgName := range oldPackageNames {
|
||||
log.Println("fetching git:", pkgName)
|
||||
out := git.GitExecWithOutputOrPanic(pkgName, "fetch", "--multiple", "factory", "rpm")
|
||||
if len(strings.TrimSpace(out)) > 1 {
|
||||
log.Println(out)
|
||||
}
|
||||
|
||||
// check that nothing is broken with the update
|
||||
out = git.GitExecWithOutputOrPanic(pkg.Name, "rev-list", "factory")
|
||||
out = git.GitExecWithOutputOrPanic(pkgName, "rev-list", "factory")
|
||||
old_revs := strings.Split(out, "\n")
|
||||
out = git.GitExecWithOutputOrPanic(pkg.Name, "rev-list", "factory", "^factory/factory")
|
||||
out = git.GitExecWithOutputOrPanic(pkgName, "rev-list", "factory", "^factory/factory")
|
||||
added_revs := strings.Split(out, "\n")
|
||||
out = git.GitExecWithOutputOrPanic(pkg.Name, "rev-list", "factory", "^rpm/factory")
|
||||
out = git.GitExecWithOutputOrPanic(pkgName, "rev-list", "factory", "^rpm/factory")
|
||||
added_rpm_revs := strings.Split(out, "\n")
|
||||
if len(added_revs) == len(old_revs) && len(added_rpm_revs) == len(old_revs) {
|
||||
log.Printf("Something is wrong with rev-ist for (len %d): %s\n", len(added_revs), pkg.Name)
|
||||
log.Printf("Something is wrong with rev-ist for (len %d): %s\n", len(added_revs), pkgName)
|
||||
reposOK = false
|
||||
}
|
||||
}
|
||||
|
||||
args := make([]string, 4, len(newPackages)+4)
|
||||
args := make([]string, 4, len(develProjectPackages)+4)
|
||||
args[0] = "-p"
|
||||
args[1] = prj
|
||||
args[2] = "-r"
|
||||
args[4] = git.GitPath
|
||||
args = append(args, newPackages...)
|
||||
args = append(args, develProjectPackages...)
|
||||
cmd = exec.Command("./git-importer", args...)
|
||||
out, err = cmd.CombinedOutput()
|
||||
log.Println(out)
|
||||
@ -208,7 +232,7 @@ func main() {
|
||||
log.Println("aborting import due to broken repos above...")
|
||||
}
|
||||
|
||||
for _, pkg := range oldPackageRepos {
|
||||
for _, pkg := range factoryRepos {
|
||||
// update package
|
||||
fork, err := client.Repository.CreateFork(repository.NewCreateForkParams().
|
||||
WithOwner("pool").
|
||||
@ -260,7 +284,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
for _, pkg := range newPackages {
|
||||
for _, pkg := range develProjectPackages {
|
||||
ret, err := client.Organization.CreateOrgRepo(organization.NewCreateOrgRepoParams().WithOrg(org).WithBody(
|
||||
&models.CreateRepoOption{
|
||||
ObjectFormatName: "sha256",
|
||||
|
Loading…
Reference in New Issue
Block a user