.
This commit is contained in:
parent
4c1617f3d4
commit
8cdb196164
@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
@ -30,6 +31,19 @@ func runObsCommand(args ...string) ([]byte, error) {
|
||||
return cmd.Output()
|
||||
}
|
||||
|
||||
func gitExec(pwd string, args ...string) string {
|
||||
cmd := exec.Command("git", args...)
|
||||
cmd.Dir = pwd
|
||||
str, err := cmd.CombinedOutput()
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("git command failed: %v\n", args)
|
||||
fmt.Println(" err: %v", err)
|
||||
os.Exit(10)
|
||||
}
|
||||
return string(str)
|
||||
}
|
||||
|
||||
func main() {
|
||||
if err := common.RequireGiteaSecretToken(); err != nil {
|
||||
fmt.Println("Missing GITEA_TOKEN")
|
||||
@ -47,8 +61,8 @@ func main() {
|
||||
os.Exit(100)
|
||||
}
|
||||
|
||||
var purgeOnly bool
|
||||
flag.BoolVar(&purgeOnly, "purge", false, "Purges package repositories. Use with caution")
|
||||
purgeOnly := flag.Bool("purge", false, "Purges package repositories. Use with caution")
|
||||
// revNew := flag.Int("nrevs", 20, "Number of new revisions in factory branch. Indicator of broken history import")
|
||||
flag.Parse()
|
||||
|
||||
if flag.NArg() != 2 {
|
||||
@ -72,7 +86,7 @@ func main() {
|
||||
// r.SetDebug(true)
|
||||
client := apiclient.New(r, nil)
|
||||
|
||||
if purgeOnly {
|
||||
if *purgeOnly {
|
||||
fmt.Printf("Purging repositories...\n")
|
||||
for _, pkg := range packages {
|
||||
client.Repository.RepoDelete(repository.NewRepoDeleteParams().WithOwner(org).WithRepo(pkg), r.DefaultAuthentication)
|
||||
@ -115,7 +129,7 @@ func main() {
|
||||
for _, hook := range hooks {
|
||||
fmt.Printf("hook %d: %#v", hook.ID, hook.Config)
|
||||
}
|
||||
|
||||
/*
|
||||
hookActive := true
|
||||
hookType := models.CreateHookOptionTypeGitea
|
||||
client.Organization.OrgCreateHook(
|
||||
@ -132,12 +146,60 @@ func main() {
|
||||
},
|
||||
}),
|
||||
r.DefaultAuthentication)
|
||||
*/
|
||||
|
||||
// fork packags from pool
|
||||
cmd := exec.Command("./git-importer", func(r []*models.Repository) []string {
|
||||
ret := make([]string, len(r))
|
||||
for i := range r {
|
||||
ret[i] = r[i].Name
|
||||
}
|
||||
return ret
|
||||
}(oldPackageRepos)...)
|
||||
out, err := cmd.CombinedOutput()
|
||||
fmt.Print(string(out))
|
||||
if err != nil {
|
||||
fmt.Printf("Error returned by importer. Err: %v\n", err)
|
||||
os.Exit(14)
|
||||
}
|
||||
for i := range oldPackageRepos {
|
||||
pkg := oldPackageRepos[i]
|
||||
fork, err := client.Repository.CreateFork(
|
||||
repository.NewCreateForkParams().
|
||||
dir := path.Join("repos", pkg.Name)
|
||||
|
||||
// add remote repos
|
||||
out := gitExec(dir, "remote", "show", "-n")
|
||||
if !slices.Contains(strings.Split(out, "\n"), "factory") {
|
||||
out := gitExec(dir, "remote", "add", "factory", pkg.CloneURL)
|
||||
if len(strings.TrimSpace(out)) > 1 {
|
||||
fmt.Println(out)
|
||||
}
|
||||
}
|
||||
if !slices.Contains(strings.Split(out, "\n"), "rpm") {
|
||||
out := gitExec(dir, "remote", "add", "rpm", "https://src.opensuse.org/rpm/" + pkg.Name + ".git")
|
||||
if len(strings.TrimSpace(out)) > 1 {
|
||||
fmt.Println(out)
|
||||
}
|
||||
}
|
||||
|
||||
out = gitExec(dir, "fetch", "--multiple", "factory", "rpm")
|
||||
if len(strings.TrimSpace(out)) > 1 {
|
||||
fmt.Println(out)
|
||||
}
|
||||
|
||||
// check that nothing is broken with the update
|
||||
out = gitExec(dir, "rev-list", "factory")
|
||||
old_revs := strings.Split(out, "\n")
|
||||
out = gitExec(dir, "rev-list", "factory", "^factory/factory")
|
||||
added_revs := strings.Split(out, "\n")
|
||||
out = gitExec(dir, "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) {
|
||||
fmt.Printf("Something is wrong with revl-ist for (len %d): %s\n", len(added_revs), pkg.Name)
|
||||
}
|
||||
|
||||
// update package
|
||||
/*
|
||||
fork, err := client.Repository.CreateFork(repository.NewCreateForkParams().
|
||||
WithOwner("pool").
|
||||
WithRepo(pkg.Name).
|
||||
WithBody(&models.CreateForkOption{
|
||||
@ -180,10 +242,13 @@ func main() {
|
||||
os.Exit(12)
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
// create new repositories
|
||||
for _, pkg := range newPackages {
|
||||
fmt.Printf(" %s\n", pkg)
|
||||
/*
|
||||
_, err := client.Organization.CreateOrgRepo(
|
||||
organization.NewCreateOrgRepoParams().
|
||||
WithOrg(org).
|
||||
@ -199,5 +264,6 @@ func main() {
|
||||
fmt.Printf("Cannot create %s/%s. Err: %v", org, pkg, err)
|
||||
os.Exit(13)
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user