.
This commit is contained in:
parent
4c1617f3d4
commit
8cdb196164
@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -30,6 +31,19 @@ func runObsCommand(args ...string) ([]byte, error) {
|
|||||||
return cmd.Output()
|
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() {
|
func main() {
|
||||||
if err := common.RequireGiteaSecretToken(); err != nil {
|
if err := common.RequireGiteaSecretToken(); err != nil {
|
||||||
fmt.Println("Missing GITEA_TOKEN")
|
fmt.Println("Missing GITEA_TOKEN")
|
||||||
@ -47,8 +61,8 @@ func main() {
|
|||||||
os.Exit(100)
|
os.Exit(100)
|
||||||
}
|
}
|
||||||
|
|
||||||
var purgeOnly bool
|
purgeOnly := flag.Bool("purge", false, "Purges package repositories. Use with caution")
|
||||||
flag.BoolVar(&purgeOnly, "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()
|
flag.Parse()
|
||||||
|
|
||||||
if flag.NArg() != 2 {
|
if flag.NArg() != 2 {
|
||||||
@ -72,7 +86,7 @@ func main() {
|
|||||||
// r.SetDebug(true)
|
// r.SetDebug(true)
|
||||||
client := apiclient.New(r, nil)
|
client := apiclient.New(r, nil)
|
||||||
|
|
||||||
if purgeOnly {
|
if *purgeOnly {
|
||||||
fmt.Printf("Purging repositories...\n")
|
fmt.Printf("Purging repositories...\n")
|
||||||
for _, pkg := range packages {
|
for _, pkg := range packages {
|
||||||
client.Repository.RepoDelete(repository.NewRepoDeleteParams().WithOwner(org).WithRepo(pkg), r.DefaultAuthentication)
|
client.Repository.RepoDelete(repository.NewRepoDeleteParams().WithOwner(org).WithRepo(pkg), r.DefaultAuthentication)
|
||||||
@ -115,7 +129,7 @@ func main() {
|
|||||||
for _, hook := range hooks {
|
for _, hook := range hooks {
|
||||||
fmt.Printf("hook %d: %#v", hook.ID, hook.Config)
|
fmt.Printf("hook %d: %#v", hook.ID, hook.Config)
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
hookActive := true
|
hookActive := true
|
||||||
hookType := models.CreateHookOptionTypeGitea
|
hookType := models.CreateHookOptionTypeGitea
|
||||||
client.Organization.OrgCreateHook(
|
client.Organization.OrgCreateHook(
|
||||||
@ -132,12 +146,60 @@ func main() {
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
r.DefaultAuthentication)
|
r.DefaultAuthentication)
|
||||||
|
*/
|
||||||
|
|
||||||
// fork packags from pool
|
// 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 {
|
for i := range oldPackageRepos {
|
||||||
pkg := oldPackageRepos[i]
|
pkg := oldPackageRepos[i]
|
||||||
fork, err := client.Repository.CreateFork(
|
dir := path.Join("repos", pkg.Name)
|
||||||
repository.NewCreateForkParams().
|
|
||||||
|
// 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").
|
WithOwner("pool").
|
||||||
WithRepo(pkg.Name).
|
WithRepo(pkg.Name).
|
||||||
WithBody(&models.CreateForkOption{
|
WithBody(&models.CreateForkOption{
|
||||||
@ -180,10 +242,13 @@ func main() {
|
|||||||
os.Exit(12)
|
os.Exit(12)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
// create new repositories
|
// create new repositories
|
||||||
for _, pkg := range newPackages {
|
for _, pkg := range newPackages {
|
||||||
|
fmt.Printf(" %s\n", pkg)
|
||||||
|
/*
|
||||||
_, err := client.Organization.CreateOrgRepo(
|
_, err := client.Organization.CreateOrgRepo(
|
||||||
organization.NewCreateOrgRepoParams().
|
organization.NewCreateOrgRepoParams().
|
||||||
WithOrg(org).
|
WithOrg(org).
|
||||||
@ -199,5 +264,6 @@ func main() {
|
|||||||
fmt.Printf("Cannot create %s/%s. Err: %v", org, pkg, err)
|
fmt.Printf("Cannot create %s/%s. Err: %v", org, pkg, err)
|
||||||
os.Exit(13)
|
os.Exit(13)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user