devel-importer: more fixes
This commit is contained in:
parent
86df1921e0
commit
d7bbe5695c
@ -150,14 +150,14 @@ func (h writeFunc) Close() error {
|
||||
func (e *GitHandler) GitExecWithOutputOrPanic(cwd string, params ...string) string {
|
||||
out, err := e.GitExecWithOutput(cwd, params...)
|
||||
if err != nil {
|
||||
log.Panicln("git command failed:", params, "err:", err)
|
||||
log.Panicln("git command failed:", params, "@", cwd, "err:", err)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (e *GitHandler) GitExecOrPanic(cwd string, params ...string) {
|
||||
if err := e.GitExec(cwd, params...); err != nil {
|
||||
log.Panicln("git command failed:", params, "err:", err)
|
||||
log.Panicln("git command failed:", params, "@", cwd, "err:", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,6 @@ import (
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
transport "github.com/go-openapi/runtime/client"
|
||||
"src.opensuse.org/autogits/common"
|
||||
@ -314,10 +313,30 @@ func main() {
|
||||
log.Panicln("aborting import due to broken repos above...")
|
||||
}
|
||||
|
||||
slices.SortFunc(factoryRepos, func(a, b *models.Repository) int {
|
||||
if a.Name == b.Name {
|
||||
orgOrderNo := func(org string) int {
|
||||
switch org {
|
||||
case "pool":
|
||||
return 1
|
||||
case "rpm":
|
||||
return 2
|
||||
}
|
||||
return 0 // current devel to clone
|
||||
}
|
||||
|
||||
return orgOrderNo(a.Owner.UserName) - orgOrderNo(b.Owner.UserName)
|
||||
}
|
||||
return strings.Compare(a.Name, b.Name)
|
||||
})
|
||||
factoryRepos = slices.CompactFunc(factoryRepos, func(a, b *models.Repository) bool {
|
||||
return a.Name == b.Name
|
||||
})
|
||||
|
||||
for _, pkg := range factoryRepos {
|
||||
// update package
|
||||
fork, err := client.Repository.CreateFork(repository.NewCreateForkParams().
|
||||
WithOwner("pool").
|
||||
WithOwner(pkg.Owner.UserName).
|
||||
WithRepo(pkg.Name).
|
||||
WithBody(&models.CreateForkOption{
|
||||
Organization: org,
|
||||
@ -327,34 +346,38 @@ func main() {
|
||||
}
|
||||
|
||||
repo := fork.Payload
|
||||
repoList, err := client.Repository.RepoListBranches(
|
||||
repository.NewRepoListBranchesParams().WithOwner(org).WithRepo(pkg.Name),
|
||||
r.DefaultAuthentication,
|
||||
)
|
||||
if err != nil {
|
||||
log.Panicln("Cannot get list of branches for forked repo:", org, "/", pkg.Name)
|
||||
}
|
||||
priorityBranches := []string{
|
||||
"devel",
|
||||
"factory",
|
||||
}
|
||||
idx := len(priorityBranches)
|
||||
for _, branch := range repoList.Payload {
|
||||
i := slices.Index(priorityBranches, branch.Name)
|
||||
if i > -1 && i < idx {
|
||||
idx = i
|
||||
branchName := repo.DefaultBranch
|
||||
|
||||
if pkg.Owner.UserName == "pool" || pkg.Owner.UserName == "rpm" {
|
||||
// forked a git-based devel project, so use the default branch name now
|
||||
repoList, err := client.Repository.RepoListBranches(
|
||||
repository.NewRepoListBranchesParams().WithOwner(org).WithRepo(pkg.Name),
|
||||
r.DefaultAuthentication,
|
||||
)
|
||||
if err != nil {
|
||||
log.Panicln("Cannot get list of branches for forked repo:", org, "/", pkg.Name)
|
||||
}
|
||||
priorityBranches := []string{
|
||||
"devel",
|
||||
"factory",
|
||||
}
|
||||
idx := len(priorityBranches)
|
||||
for _, branch := range repoList.Payload {
|
||||
i := slices.Index(priorityBranches, branch.Name)
|
||||
if i > -1 && i < idx {
|
||||
idx = i
|
||||
}
|
||||
}
|
||||
branchName = priorityBranches[idx]
|
||||
}
|
||||
|
||||
branchName := priorityBranches[idx]
|
||||
remotes := git.GitExecWithOutputOrPanic(pkg.Name, "remote", "show")
|
||||
if !slices.Contains(strings.Split(remotes, "\n"), "devel") {
|
||||
git.GitExecOrPanic(pkg.Name, "remote", "add", "devel", repo.SSHURL)
|
||||
git.GitExecOrPanic(pkg.Name, "fetch", "devel")
|
||||
}
|
||||
git.GitExecOrPanic(pkg.Name, "branch", "main", "-f", branchName)
|
||||
time.Sleep(2 * time.Second)
|
||||
git.GitExecOrPanic(pkg.Name, "branch", "main", "-f", "devel/"+branchName)
|
||||
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{
|
||||
DefaultBranch: "main",
|
||||
@ -387,9 +410,7 @@ func main() {
|
||||
git.GitExecOrPanic(pkg, "remote", "add", "devel", repo.SSHURL)
|
||||
}
|
||||
git.GitExecOrPanic(pkg, "branch", "main", "-f", "factory")
|
||||
time.Sleep(2 * time.Second)
|
||||
git.GitExecOrPanic(pkg, "push", "devel", "main")
|
||||
time.Sleep(2 * time.Second)
|
||||
|
||||
_, err = client.Repository.RepoEdit(repository.NewRepoEditParams().WithOwner(org).WithRepo(pkg).WithBody(&models.EditRepoOption{
|
||||
DefaultBranch: "main",
|
||||
|
Loading…
Reference in New Issue
Block a user