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