[devel-importer] configurable import location
This commit is contained in:
parent
6b40bf7bbf
commit
a47d217ab3
@ -24,7 +24,6 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
@ -50,6 +49,8 @@ func runObsCommand(args ...string) ([]byte, error) {
|
||||
return cmd.Output()
|
||||
}
|
||||
|
||||
var DebugMode bool
|
||||
|
||||
func main() {
|
||||
if err := common.RequireGiteaSecretToken(); err != nil {
|
||||
log.Panicln("Missing GITEA_TOKEN")
|
||||
@ -59,14 +60,27 @@ func main() {
|
||||
log.Panicln("Missing OBS_PASSWORD and/or OBS_USER")
|
||||
}
|
||||
|
||||
//workflowConfig := flag.String("config", "", "Repository and workflow definition file")
|
||||
giteaHost := flag.String("gitea", "src.opensuse.org", "Gitea instance")
|
||||
//rabbitUrl := flag.String("url", "amqps://rabbit.opensuse.org", "URL for RabbitMQ instance")
|
||||
flag.BoolVar(&DebugMode, "debug", false, "Extra debugging information")
|
||||
// revNew := flag.Int("nrevs", 20, "Number of new revisions in factory branch. Indicator of broken history import")
|
||||
purgeOnly := flag.Bool("purge", false, "Purges package repositories. Use with caution")
|
||||
debugGitPath := flag.String("git-path", "", "Path for temporary git directory. Only used if DebugMode")
|
||||
flag.Parse()
|
||||
|
||||
git, err := common.CreateGitHandler("Autogits - Devel Importer", "not.exist", "devel-importer")
|
||||
if err != nil {
|
||||
log.Panicln("Failed to allocate git handler. Err:", err)
|
||||
}
|
||||
|
||||
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 DebugMode {
|
||||
log.Println(" - working directory:" + git.GitPath)
|
||||
if len(*debugGitPath) > 0 {
|
||||
git.GitPath = *debugGitPath
|
||||
}
|
||||
} else {
|
||||
defer git.Close()
|
||||
}
|
||||
|
||||
if flag.NArg() != 2 {
|
||||
printHelp()
|
||||
@ -89,7 +103,7 @@ func main() {
|
||||
|
||||
log.Printf("%d packages: %s\n\n", len(packages), strings.Join(packages, " "))
|
||||
|
||||
r := transport.New("src.opensuse.org", apiclient.DefaultBasePath, [](string){"https"})
|
||||
r := transport.New(*giteaHost, apiclient.DefaultBasePath, [](string){"https"})
|
||||
r.DefaultAuthentication = transport.BearerToken(common.GetGiteaToken())
|
||||
// r.SetDebug(true)
|
||||
client := apiclient.New(r, nil)
|
||||
@ -126,9 +140,11 @@ func main() {
|
||||
|
||||
// fork packags from pool
|
||||
cmd := exec.Command("./git-importer", func(r []*models.Repository) []string {
|
||||
ret := make([]string, len(r))
|
||||
ret := make([]string, len(r)+2)
|
||||
ret[0] = "-r"
|
||||
ret[1] = git.GitPath
|
||||
for i := range r {
|
||||
ret[i] = r[i].Name
|
||||
ret[i+2] = r[i].Name
|
||||
}
|
||||
return ret
|
||||
}(oldPackageRepos)...)
|
||||
@ -141,34 +157,33 @@ func main() {
|
||||
reposOK := true
|
||||
for i := range oldPackageRepos {
|
||||
pkg := oldPackageRepos[i]
|
||||
dir := path.Join("repos", pkg.Name)
|
||||
|
||||
// add remote repos
|
||||
out := git.GitExecWithOutputOrPanic(dir, "remote", "show", "-n")
|
||||
out := git.GitExecWithOutputOrPanic(pkg.Name, "remote", "show", "-n")
|
||||
if !slices.Contains(strings.Split(out, "\n"), "factory") {
|
||||
out := git.GitExecWithOutputOrPanic(dir, "remote", "add", "factory", pkg.CloneURL)
|
||||
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(dir, "remote", "add", "rpm", "https://src.opensuse.org/rpm/"+pkg.Name+".git")
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
out = git.GitExecWithOutputOrPanic(dir, "fetch", "--multiple", "factory", "rpm")
|
||||
out = git.GitExecWithOutputOrPanic(pkg.Name, "fetch", "--multiple", "factory", "rpm")
|
||||
if len(strings.TrimSpace(out)) > 1 {
|
||||
log.Println(out)
|
||||
}
|
||||
|
||||
// check that nothing is broken with the update
|
||||
out = git.GitExecWithOutputOrPanic(dir, "rev-list", "factory")
|
||||
out = git.GitExecWithOutputOrPanic(pkg.Name, "rev-list", "factory")
|
||||
old_revs := strings.Split(out, "\n")
|
||||
out = git.GitExecWithOutputOrPanic(dir, "rev-list", "factory", "^factory/factory")
|
||||
out = git.GitExecWithOutputOrPanic(pkg.Name, "rev-list", "factory", "^factory/factory")
|
||||
added_revs := strings.Split(out, "\n")
|
||||
out = git.GitExecWithOutputOrPanic(dir, "rev-list", "factory", "^rpm/factory")
|
||||
out = git.GitExecWithOutputOrPanic(pkg.Name, "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)
|
||||
@ -176,9 +191,11 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
args := make([]string, 2, len(newPackages)+2)
|
||||
args := make([]string, 4, len(newPackages)+4)
|
||||
args[0] = "-p"
|
||||
args[1] = prj
|
||||
args[2] = "-r"
|
||||
args[4] = git.GitPath
|
||||
args = append(args, newPackages...)
|
||||
cmd = exec.Command("./git-importer", args...)
|
||||
out, err = cmd.CombinedOutput()
|
||||
@ -224,14 +241,13 @@ func main() {
|
||||
}
|
||||
|
||||
branchName := priorityBranches[idx]
|
||||
dir := path.Join("repos", pkg.Name)
|
||||
remotes := git.GitExecWithOutputOrPanic(dir, "remote", "show")
|
||||
remotes := git.GitExecWithOutputOrPanic(pkg.Name, "remote", "show")
|
||||
if !slices.Contains(strings.Split(remotes, "\n"), "devel") {
|
||||
git.GitExecOrPanic(dir, "remote", "add", "devel", repo.SSHURL)
|
||||
git.GitExecOrPanic(pkg.Name, "remote", "add", "devel", repo.SSHURL)
|
||||
}
|
||||
git.GitExecOrPanic(dir, "branch", "main", "-f", branchName)
|
||||
git.GitExecOrPanic(pkg.Name, "branch", "main", "-f", branchName)
|
||||
time.Sleep(2 * time.Second)
|
||||
git.GitExecOrPanic(dir, "push", "devel", "main")
|
||||
git.GitExecOrPanic(pkg.Name, "push", "devel", "main")
|
||||
time.Sleep(2 * time.Second)
|
||||
|
||||
_, err = client.Repository.RepoEdit(repository.NewRepoEditParams().WithOwner(org).WithRepo(repo.Name).WithBody(&models.EditRepoOption{
|
||||
@ -260,14 +276,13 @@ func main() {
|
||||
}
|
||||
|
||||
repo := ret.Payload
|
||||
dir := path.Join("repos", pkg)
|
||||
remotes := git.GitExecWithOutputOrPanic(dir, "remote", "show")
|
||||
remotes := git.GitExecWithOutputOrPanic(pkg, "remote", "show")
|
||||
if !slices.Contains(strings.Split(remotes, "\n"), "devel") {
|
||||
git.GitExecOrPanic(dir, "remote", "add", "devel", repo.SSHURL)
|
||||
git.GitExecOrPanic(pkg, "remote", "add", "devel", repo.SSHURL)
|
||||
}
|
||||
git.GitExecOrPanic(dir, "branch", "main", "-f", "factory")
|
||||
git.GitExecOrPanic(pkg, "branch", "main", "-f", "factory")
|
||||
time.Sleep(2 * time.Second)
|
||||
git.GitExecOrPanic(dir, "push", "devel", "main")
|
||||
git.GitExecOrPanic(pkg, "push", "devel", "main")
|
||||
time.Sleep(2 * time.Second)
|
||||
|
||||
_, err = client.Repository.RepoEdit(repository.NewRepoEditParams().WithOwner(org).WithRepo(pkg).WithBody(&models.EditRepoOption{
|
||||
|
Loading…
Reference in New Issue
Block a user