devel-importer: migrate logging to log module
also remove webhook stuff, since we use RabbitMQ now
This commit is contained in:
parent
d36c0c407f
commit
6b40bf7bbf
@ -21,7 +21,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -43,7 +42,7 @@ const commandLineHelp = `
|
|||||||
devel-importer <obs-project> <gitea-org>`
|
devel-importer <obs-project> <gitea-org>`
|
||||||
|
|
||||||
func printHelp() {
|
func printHelp() {
|
||||||
fmt.Println(commandLineHelp)
|
log.Println(commandLineHelp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func runObsCommand(args ...string) ([]byte, error) {
|
func runObsCommand(args ...string) ([]byte, error) {
|
||||||
@ -53,13 +52,11 @@ func runObsCommand(args ...string) ([]byte, error) {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if err := common.RequireGiteaSecretToken(); err != nil {
|
if err := common.RequireGiteaSecretToken(); err != nil {
|
||||||
fmt.Println("Missing GITEA_TOKEN")
|
log.Panicln("Missing GITEA_TOKEN")
|
||||||
os.Exit(100)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := common.RequireObsSecretToken(); err != nil {
|
if err := common.RequireObsSecretToken(); err != nil {
|
||||||
fmt.Printf("Missing OBS_PASSWORD and/or OBS_USER\n")
|
log.Panicln("Missing OBS_PASSWORD and/or OBS_USER")
|
||||||
os.Exit(100)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
git, err := common.CreateGitHandler("Autogits - Devel Importer", "not.exist", "devel-importer")
|
git, err := common.CreateGitHandler("Autogits - Devel Importer", "not.exist", "devel-importer")
|
||||||
@ -84,7 +81,13 @@ func main() {
|
|||||||
log.Printf("Cannot list packages for project '%s'. Err: %v\n", prj, err)
|
log.Printf("Cannot list packages for project '%s'. Err: %v\n", prj, err)
|
||||||
}
|
}
|
||||||
packages := strings.Split(strings.TrimSpace(string(packageList)), "\n")
|
packages := strings.Split(strings.TrimSpace(string(packageList)), "\n")
|
||||||
fmt.Printf("%d packages: %s\n\n", len(packages), strings.Join(packages, " "))
|
slices.Sort(packages)
|
||||||
|
for i := range packages {
|
||||||
|
packages[i] = strings.Split(packages[i], ":")[0]
|
||||||
|
}
|
||||||
|
packages = slices.Compact(packages)
|
||||||
|
|
||||||
|
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("src.opensuse.org", apiclient.DefaultBasePath, [](string){"https"})
|
||||||
r.DefaultAuthentication = transport.BearerToken(common.GetGiteaToken())
|
r.DefaultAuthentication = transport.BearerToken(common.GetGiteaToken())
|
||||||
@ -92,7 +95,7 @@ func main() {
|
|||||||
client := apiclient.New(r, nil)
|
client := apiclient.New(r, nil)
|
||||||
|
|
||||||
if *purgeOnly {
|
if *purgeOnly {
|
||||||
fmt.Printf("Purging repositories...\n")
|
log.Println("Purging repositories...")
|
||||||
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)
|
||||||
}
|
}
|
||||||
@ -102,38 +105,24 @@ func main() {
|
|||||||
oldPackageRepos := make([]*models.Repository, 0, len(packages))
|
oldPackageRepos := make([]*models.Repository, 0, len(packages))
|
||||||
newPackages := make([]string, 0, len(packages))
|
newPackages := make([]string, 0, len(packages))
|
||||||
for _, pkg := range packages {
|
for _, pkg := range packages {
|
||||||
|
src_pkg_name := strings.Split(pkg, ":")
|
||||||
repo, err := client.Repository.RepoGet(
|
repo, err := client.Repository.RepoGet(
|
||||||
repository.NewRepoGetParams().
|
repository.NewRepoGetParams().
|
||||||
WithDefaults().WithOwner("pool").WithRepo(pkg),
|
WithDefaults().WithOwner("pool").WithRepo(src_pkg_name[0]),
|
||||||
r.DefaultAuthentication)
|
r.DefaultAuthentication)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errors.Is(err, &repository.RepoGetNotFound{}) {
|
if !errors.Is(err, &repository.RepoGetNotFound{}) {
|
||||||
fmt.Println(err)
|
log.Panicln(err)
|
||||||
os.Exit(3)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Cannot find package: %s\n", pkg)
|
log.Println("Cannot find src package:", src_pkg_name)
|
||||||
newPackages = append(newPackages, pkg)
|
newPackages = append(newPackages, src_pkg_name[0])
|
||||||
} else {
|
} else {
|
||||||
oldPackageRepos = append(oldPackageRepos, repo.Payload)
|
oldPackageRepos = append(oldPackageRepos, repo.Payload)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Printf("Num repos found: %d\n", len(oldPackageRepos))
|
log.Println("Num repos found:", len(oldPackageRepos))
|
||||||
|
|
||||||
// add webhooks to prjgit-updater
|
|
||||||
hooksReponse, err := client.Organization.OrgListHooks(
|
|
||||||
organization.NewOrgListHooksParams().WithOrg(org),
|
|
||||||
r.DefaultAuthentication,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error fetching hooks for '%s'. Err: %v\n", org, err)
|
|
||||||
os.Exit(4)
|
|
||||||
}
|
|
||||||
hooks := hooksReponse.Payload
|
|
||||||
for _, hook := range hooks {
|
|
||||||
fmt.Printf("hook %d: %#v", hook.ID, hook.Config)
|
|
||||||
}
|
|
||||||
|
|
||||||
// fork packags from pool
|
// fork packags from pool
|
||||||
cmd := exec.Command("./git-importer", func(r []*models.Repository) []string {
|
cmd := exec.Command("./git-importer", func(r []*models.Repository) []string {
|
||||||
@ -144,10 +133,9 @@ func main() {
|
|||||||
return ret
|
return ret
|
||||||
}(oldPackageRepos)...)
|
}(oldPackageRepos)...)
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
fmt.Print(string(out))
|
log.Println(string(out))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error returned by importer. Err: %v\n", err)
|
log.Println("Error returned by importer.", err)
|
||||||
os.Exit(14)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
reposOK := true
|
reposOK := true
|
||||||
@ -160,19 +148,19 @@ func main() {
|
|||||||
if !slices.Contains(strings.Split(out, "\n"), "factory") {
|
if !slices.Contains(strings.Split(out, "\n"), "factory") {
|
||||||
out := git.GitExecWithOutputOrPanic(dir, "remote", "add", "factory", pkg.CloneURL)
|
out := git.GitExecWithOutputOrPanic(dir, "remote", "add", "factory", pkg.CloneURL)
|
||||||
if len(strings.TrimSpace(out)) > 1 {
|
if len(strings.TrimSpace(out)) > 1 {
|
||||||
fmt.Println(out)
|
log.Println(out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !slices.Contains(strings.Split(out, "\n"), "rpm") {
|
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(dir, "remote", "add", "rpm", "https://src.opensuse.org/rpm/"+pkg.Name+".git")
|
||||||
if len(strings.TrimSpace(out)) > 1 {
|
if len(strings.TrimSpace(out)) > 1 {
|
||||||
fmt.Println(out)
|
log.Println(out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out = git.GitExecWithOutputOrPanic(dir, "fetch", "--multiple", "factory", "rpm")
|
out = git.GitExecWithOutputOrPanic(dir, "fetch", "--multiple", "factory", "rpm")
|
||||||
if len(strings.TrimSpace(out)) > 1 {
|
if len(strings.TrimSpace(out)) > 1 {
|
||||||
fmt.Println(out)
|
log.Println(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
// check that nothing is broken with the update
|
// check that nothing is broken with the update
|
||||||
@ -183,7 +171,7 @@ func main() {
|
|||||||
out = git.GitExecWithOutputOrPanic(dir, "rev-list", "factory", "^rpm/factory")
|
out = git.GitExecWithOutputOrPanic(dir, "rev-list", "factory", "^rpm/factory")
|
||||||
added_rpm_revs := strings.Split(out, "\n")
|
added_rpm_revs := strings.Split(out, "\n")
|
||||||
if len(added_revs) == len(old_revs) && len(added_rpm_revs) == len(old_revs) {
|
if len(added_revs) == len(old_revs) && len(added_rpm_revs) == len(old_revs) {
|
||||||
fmt.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), pkg.Name)
|
||||||
reposOK = false
|
reposOK = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -194,15 +182,13 @@ func main() {
|
|||||||
args = append(args, newPackages...)
|
args = append(args, newPackages...)
|
||||||
cmd = exec.Command("./git-importer", args...)
|
cmd = exec.Command("./git-importer", args...)
|
||||||
out, err = cmd.CombinedOutput()
|
out, err = cmd.CombinedOutput()
|
||||||
fmt.Print(string(out))
|
log.Println(out)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error returned by importer. Err: %v\n", err)
|
log.Panicln("Error returned by importer.", err)
|
||||||
os.Exit(15)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !reposOK {
|
if !reposOK {
|
||||||
fmt.Printf("aborting import due to broken repos above...\n")
|
log.Println("aborting import due to broken repos above...")
|
||||||
os.Exit(100)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, pkg := range oldPackageRepos {
|
for _, pkg := range oldPackageRepos {
|
||||||
@ -214,8 +200,7 @@ func main() {
|
|||||||
Organization: org,
|
Organization: org,
|
||||||
}), r.DefaultAuthentication)
|
}), r.DefaultAuthentication)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error while trying to create fork from pool/%s. Err: %v\n", pkg.Name, err)
|
log.Panicln("Error while trying to create fork from pool/", pkg.Name, err)
|
||||||
os.Exit(10)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
repo := fork.Payload
|
repo := fork.Payload
|
||||||
@ -224,8 +209,7 @@ func main() {
|
|||||||
r.DefaultAuthentication,
|
r.DefaultAuthentication,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Cannot get list of branches for forked repo: %s/%s\n", org, pkg.Name)
|
log.Panicln("Cannot get list of branches for forked repo:", org, "/", pkg.Name)
|
||||||
os.Exit(11)
|
|
||||||
}
|
}
|
||||||
priorityBranches := []string{
|
priorityBranches := []string{
|
||||||
"devel",
|
"devel",
|
||||||
@ -256,8 +240,7 @@ func main() {
|
|||||||
}), r.DefaultAuthentication)
|
}), r.DefaultAuthentication)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Failed to set default branch for package fork: %s/%s Err: %v", repo.Owner.UserName, repo.Name, err)
|
log.Panicln("Failed to set default branch for package fork:", repo.Owner.UserName, "/", repo.Name, err)
|
||||||
os.Exit(12)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,8 +256,7 @@ func main() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error creating new package repository: %s Err: %v", pkg, err)
|
log.Panicln("Error creating new package repository:", pkg, err)
|
||||||
os.Exit(13)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
repo := ret.Payload
|
repo := ret.Payload
|
||||||
@ -294,8 +276,7 @@ func main() {
|
|||||||
}), r.DefaultAuthentication)
|
}), r.DefaultAuthentication)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Failed to set default branch for package fork: %s/%s Err: %v", repo.Owner.UserName, repo.Name, err)
|
log.Panicln("Failed to set default branch for package fork:", repo.Owner.UserName, "/", repo.Name, err)
|
||||||
os.Exit(14)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user