.
This commit is contained in:
parent
8cdb196164
commit
cc6304b96e
@ -9,6 +9,7 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"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"
|
||||||
@ -79,7 +80,7 @@ func main() {
|
|||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
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, ","))
|
fmt.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())
|
||||||
@ -162,6 +163,8 @@ func main() {
|
|||||||
fmt.Printf("Error returned by importer. Err: %v\n", err)
|
fmt.Printf("Error returned by importer. Err: %v\n", err)
|
||||||
os.Exit(14)
|
os.Exit(14)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reposOK := true
|
||||||
for i := range oldPackageRepos {
|
for i := range oldPackageRepos {
|
||||||
pkg := oldPackageRepos[i]
|
pkg := oldPackageRepos[i]
|
||||||
dir := path.Join("repos", pkg.Name)
|
dir := path.Join("repos", pkg.Name)
|
||||||
@ -175,7 +178,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !slices.Contains(strings.Split(out, "\n"), "rpm") {
|
if !slices.Contains(strings.Split(out, "\n"), "rpm") {
|
||||||
out := gitExec(dir, "remote", "add", "rpm", "https://src.opensuse.org/rpm/" + pkg.Name + ".git")
|
out := gitExec(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)
|
fmt.Println(out)
|
||||||
}
|
}
|
||||||
@ -194,11 +197,30 @@ func main() {
|
|||||||
out = gitExec(dir, "rev-list", "factory", "^rpm/factory")
|
out = gitExec(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 revl-ist for (len %d): %s\n", len(added_revs), pkg.Name)
|
fmt.Printf("Something is wrong with rev-ist for (len %d): %s\n", len(added_revs), pkg.Name)
|
||||||
|
reposOK = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
args := make([]string, 2, len(newPackages)+2)
|
||||||
|
args[0] = "-p"
|
||||||
|
args[1] = prj
|
||||||
|
args = append(args, newPackages...)
|
||||||
|
cmd = exec.Command("./git-importer", args...)
|
||||||
|
out, err = cmd.CombinedOutput()
|
||||||
|
fmt.Print(string(out))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error returned by importer. Err: %v\n", err)
|
||||||
|
os.Exit(15)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reposOK {
|
||||||
|
fmt.Printf("aborting import due to broken repos above...\n")
|
||||||
|
os.Exit(100)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, pkg := range oldPackageRepos {
|
||||||
// update package
|
// update package
|
||||||
/*
|
|
||||||
fork, err := client.Repository.CreateFork(repository.NewCreateForkParams().
|
fork, err := client.Repository.CreateFork(repository.NewCreateForkParams().
|
||||||
WithOwner("pool").
|
WithOwner("pool").
|
||||||
WithRepo(pkg.Name).
|
WithRepo(pkg.Name).
|
||||||
@ -231,9 +253,19 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if idx < len(priorityBranches) {
|
branchName := priorityBranches[idx]
|
||||||
_, err := client.Repository.RepoEdit(repository.NewRepoEditParams().WithOwner(repo.Owner.UserName).WithRepo(repo.Name).WithBody(&models.EditRepoOption{
|
dir := path.Join("repos", pkg.Name)
|
||||||
DefaultBranch: priorityBranches[idx],
|
remotes := gitExec(dir, "remote", "show")
|
||||||
|
if !slices.Contains(strings.Split(remotes, "\n"), "devel") {
|
||||||
|
gitExec(dir, "remote", "add", "devel", repo.SSHURL)
|
||||||
|
}
|
||||||
|
gitExec(dir, "branch", "main", "-f", branchName)
|
||||||
|
time.Sleep(2 * time.Second)
|
||||||
|
gitExec(dir, "push", "devel", "main")
|
||||||
|
time.Sleep(2 * time.Second)
|
||||||
|
|
||||||
|
_, err = client.Repository.RepoEdit(repository.NewRepoEditParams().WithOwner(org).WithRepo(repo.Name).WithBody(&models.EditRepoOption{
|
||||||
|
DefaultBranch: "main",
|
||||||
DefaultMergeStyle: "fast-forward-only",
|
DefaultMergeStyle: "fast-forward-only",
|
||||||
}), r.DefaultAuthentication)
|
}), r.DefaultAuthentication)
|
||||||
|
|
||||||
@ -242,28 +274,42 @@ func main() {
|
|||||||
os.Exit(12)
|
os.Exit(12)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
// create new repositories
|
|
||||||
for _, pkg := range newPackages {
|
for _, pkg := range newPackages {
|
||||||
fmt.Printf(" %s\n", pkg)
|
ret, err := client.Organization.CreateOrgRepo(organization.NewCreateOrgRepoParams().WithOrg(org).WithBody(
|
||||||
/*
|
|
||||||
_, err := client.Organization.CreateOrgRepo(
|
|
||||||
organization.NewCreateOrgRepoParams().
|
|
||||||
WithOrg(org).
|
|
||||||
WithBody(
|
|
||||||
&models.CreateRepoOption{
|
&models.CreateRepoOption{
|
||||||
Name: &pkg,
|
|
||||||
AutoInit: false,
|
|
||||||
ObjectFormatName: "sha256",
|
ObjectFormatName: "sha256",
|
||||||
|
AutoInit: false,
|
||||||
|
Name: &pkg,
|
||||||
|
DefaultBranch: "main",
|
||||||
}),
|
}),
|
||||||
r.DefaultAuthentication)
|
r.DefaultAuthentication,
|
||||||
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Cannot create %s/%s. Err: %v", org, pkg, err)
|
fmt.Printf("Error creating new package repository: %s Err: %v", pkg, err)
|
||||||
os.Exit(13)
|
os.Exit(13)
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
repo := ret.Payload
|
||||||
|
dir := path.Join("repos", pkg)
|
||||||
|
remotes := gitExec(dir, "remote", "show")
|
||||||
|
if !slices.Contains(strings.Split(remotes, "\n"), "devel") {
|
||||||
|
gitExec(dir, "remote", "add", "devel", repo.SSHURL)
|
||||||
|
}
|
||||||
|
gitExec(dir, "branch", "main", "-f", "factory")
|
||||||
|
time.Sleep(2 * time.Second)
|
||||||
|
gitExec(dir, "push", "devel", "main")
|
||||||
|
time.Sleep(2 * time.Second)
|
||||||
|
|
||||||
|
_, err = client.Repository.RepoEdit(repository.NewRepoEditParams().WithOwner(org).WithRepo(pkg).WithBody(&models.EditRepoOption{
|
||||||
|
DefaultBranch: "main",
|
||||||
|
DefaultMergeStyle: "fast-forward-only",
|
||||||
|
}), r.DefaultAuthentication)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Failed to set default branch for package fork: %s/%s Err: %v", repo.Owner.UserName, repo.Name, err)
|
||||||
|
os.Exit(14)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,7 @@ func processPullRequest(h *common.RequestHandler) error {
|
|||||||
req := h.Data.(*common.PullRequestAction)
|
req := h.Data.(*common.PullRequestAction)
|
||||||
|
|
||||||
switch req.Action {
|
switch req.Action {
|
||||||
case "opened":
|
case "opened", "reopened":
|
||||||
return processPullRequestOpened(h)
|
return processPullRequestOpened(h)
|
||||||
case "synchronized":
|
case "synchronized":
|
||||||
return processPullRequestSync(h)
|
return processPullRequestSync(h)
|
||||||
|
Loading…
Reference in New Issue
Block a user