remove rpm and re-org user queries

This commit is contained in:
Adam Majer 2025-02-26 18:10:42 +01:00
parent 5b84f9d5ce
commit e1313105d1

View File

@ -66,46 +66,72 @@ func runObsCommand(args ...string) ([]string, error) {
var DebugMode bool var DebugMode bool
func listMaintainers(obs *common.ObsClient, prj string, pkgs []string) { func projectMaintainer(obs *common.ObsClient, prj string) ([]string, []string) { // users, groups
meta, err := obs.GetProjectMeta(prj) meta, err := obs.GetProjectMeta(prj)
if err != nil { if err != nil {
log.Panicln(err) log.Panicln(err)
} }
uids := []string{} uids := []string{}
gids := []string{}
for _, p := range meta.Persons { for _, p := range meta.Persons {
log.Println(p.UserID, p.Role)
if !slices.Contains(uids, p.UserID) { if !slices.Contains(uids, p.UserID) {
uids = append(uids, p.UserID) uids = append(uids, p.UserID)
} }
} }
for _, g := range meta.Groups { for _, g := range meta.Groups {
log.Println(g.GroupID, g.Role) if !slices.Contains(gids, g.GroupID) {
gids = append(gids, g.GroupID)
}
} }
return uids, gids
}
func packageMaintainers(obs *common.ObsClient, prj, pkg string) ([]string, []string) { // users, groups
meta, err := obs.GetPackageMeta(prj, pkg)
if err != nil {
log.Panicln(err, "FOR:", prj, "/", pkg)
}
uids := []string{}
gids := []string{}
for _, p := range meta.Persons {
if !slices.Contains(uids, p.UserID) {
uids = append(uids, p.UserID)
}
}
for _, g := range meta.Groups {
if !slices.Contains(gids, g.GroupID) {
gids = append(gids, g.GroupID)
}
}
return uids, gids
}
func listMaintainers(obs *common.ObsClient, prj string, pkgs []string) {
users, groups := projectMaintainer(obs, prj)
for _, pkg := range pkgs { for _, pkg := range pkgs {
meta, err := obs.GetPackageMeta(prj, pkg) u, g := packageMaintainers(obs, prj, pkg)
if err != nil { users = append(users, u...)
log.Panicln(err, "FOR:", prj, "/", pkg) groups = append(groups, g...)
}
for _, p := range meta.Persons {
log.Println(" +", pkg, "=>", p.UserID)
if !slices.Contains(uids, p.UserID) {
uids = append(uids, p.UserID)
}
}
} }
slices.Sort(uids) slices.Sort(users)
log.Println("need to contact following:", strings.Join(uids, ", ")) slices.Sort(groups)
users = slices.Compact(users)
groups = slices.Compact(groups)
log.Println("need to contact following:", strings.Join(users, ", "))
contact_email := []string{} contact_email := []string{}
for _, uid := range uids { for _, uid := range users {
user, err := obs.GetUserMeta(uid) user, err := obs.GetUserMeta(uid)
if err != nil { if err != nil {
log.Panicln(err); log.Panicln(err)
} }
contact_email = append(contact_email, fmt.Sprintf("%s <%s>", user.Name, user.Email)) contact_email = append(contact_email, fmt.Sprintf("%s <%s>", user.Name, user.Email))
@ -131,7 +157,7 @@ func main() {
//rabbitUrl := flag.String("url", "amqps://rabbit.opensuse.org", "URL for RabbitMQ instance") //rabbitUrl := flag.String("url", "amqps://rabbit.opensuse.org", "URL for RabbitMQ instance")
flags.BoolVar(&DebugMode, "debug", false, "Extra debugging information") flags.BoolVar(&DebugMode, "debug", false, "Extra debugging information")
// revNew := flag.Int("nrevs", 20, "Number of new revisions in factory branch. Indicator of broken history import") // revNew := flag.Int("nrevs", 20, "Number of new revisions in factory branch. Indicator of broken history import")
purgeOnly := flags.Bool("purge", false, "Purges package repositories. Use with caution") purgeOnly := flags.Bool("purge-only", false, "Purges package repositories on Gitea. Use with caution")
debugGitPath := flags.String("git-path", "", "Path for temporary git directory. Only used if DebugMode") debugGitPath := flags.String("git-path", "", "Path for temporary git directory. Only used if DebugMode")
getMaintainers := flags.Bool("maintainer-only", false, "Get maintainers only and exit") getMaintainers := flags.Bool("maintainer-only", false, "Get maintainers only and exit")
@ -150,7 +176,10 @@ func main() {
if DebugMode { if DebugMode {
if len(*debugGitPath) > 0 { if len(*debugGitPath) > 0 {
git.Close() git.Close()
gh.ReadExistingPath("Autogits - Devel Importer", "not.exist", *debugGitPath) git, err = gh.ReadExistingPath("Autogits - Devel Importer", "not.exist", *debugGitPath)
if err != nil {
log.Panicln(err)
}
} }
log.Println(" - working directory:" + git.GetPath()) log.Println(" - working directory:" + git.GetPath())
} else { } else {
@ -200,20 +229,6 @@ func main() {
WithDefaults().WithOwner("pool").WithRepo(src_pkg_name[0]), WithDefaults().WithOwner("pool").WithRepo(src_pkg_name[0]),
r.DefaultAuthentication) r.DefaultAuthentication)
rpm, rpmErr := client.Repository.RepoGet(
repository.NewRepoGetParams().WithDefaults().WithOwner("rpm").WithRepo(src_pkg_name[0]),
r.DefaultAuthentication)
if rpmErr == nil {
factoryRepos = append(factoryRepos, rpm.Payload)
} else {
if !errors.Is(rpmErr, &repository.RepoGetNotFound{}) {
log.Panicln(rpmErr)
}
log.Println("No RPM package?", src_pkg_name)
}
if err != nil { if err != nil {
if !errors.Is(err, &repository.RepoGetNotFound{}) { if !errors.Is(err, &repository.RepoGetNotFound{}) {
log.Panicln(err) log.Panicln(err)
@ -232,17 +247,19 @@ func main() {
for _, repo := range factoryRepos { for _, repo := range factoryRepos {
oldPackageNames = append(oldPackageNames, repo.Name) oldPackageNames = append(oldPackageNames, repo.Name)
} }
slices.Sort(oldPackageNames)
oldPackageNames = slices.Compact(oldPackageNames)
copy(oldPackageNames[2:], oldPackageNames)
log.Println("Num of old packages:", len(oldPackageNames))
// fork packags from pool // fork packags from pool
cmd := exec.Command("./git-importer", append([]string{"-r", git.GetPath()}, oldPackageNames...)...) for _, pkg := range oldPackageNames {
out, err := cmd.CombinedOutput() log.Println(" + package:", pkg)
log.Println(string(out)) cmd := exec.Command("./git-importer", "-r", git.GetPath(), pkg)
if err != nil { if idx := slices.IndexFunc(cmd.Env, func(val string) bool { return val[0:12] == "GITEA_TOKEN=" }); idx != -1 {
log.Println("Error returned by importer.", err) cmd.Env = slices.Delete(cmd.Env, idx, idx+1)
}
out, err := cmd.CombinedOutput()
log.Println(string(out))
if err != nil {
log.Println("Error returned by importer.", err)
}
} }
reposOK := true reposOK := true
@ -291,13 +308,8 @@ func main() {
log.Println(out) log.Println(out)
} }
} }
case "rpm": default:
if !slices.Contains(strings.Split(out, "\n"), "rpm") { log.Panicln(pkg.Owner.UserName)
out := git.GitExecWithOutputOrPanic(pkg.Name, "remote", "add", "rpm", pkg.CloneURL)
if len(strings.TrimSpace(out)) > 1 {
log.Println(out)
}
}
} }
} }
@ -323,13 +335,8 @@ func main() {
added_revs := []string{} added_revs := []string{}
out = git.GitExecWithOutputOrPanic(pkgName, "rev-list", head_branch, "^factory/factory") out = git.GitExecWithOutputOrPanic(pkgName, "rev-list", head_branch, "^factory/factory")
added_revs = strings.Split(out, "\n") added_revs = strings.Split(out, "\n")
added_rpm_revs := old_revs
if slices.Contains(remotes, "rpm") {
out = git.GitExecWithOutputOrPanic(pkgName, "rev-list", head_branch, "^rpm/factory")
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) {
log.Printf("Something is wrong with rev-ist for (len %d): %s\n", len(added_revs), pkgName) log.Printf("Something is wrong with rev-ist for (len %d): %s\n", len(added_revs), pkgName)
// check if we have broken history in OBS and that Tree objects are still matching // check if we have broken history in OBS and that Tree objects are still matching
@ -369,17 +376,16 @@ func main() {
} }
} }
args := make([]string, 4, len(develProjectPackages)+4) for _, pkg := range develProjectPackages {
args[0] = "-p" cmd := exec.Command("./git-importer", "-p", prj, "-r", git.GetPath(), pkg)
args[1] = prj if idx := slices.IndexFunc(cmd.Env, func(val string) bool { return val[0:12] == "GITEA_TOKEN=" }); idx != -1 {
args[2] = "-r" cmd.Env = slices.Delete(cmd.Env, idx, idx+1)
args[3] = git.GetPath() }
args = append(args, develProjectPackages...) out, err := cmd.CombinedOutput()
cmd = exec.Command("./git-importer", args...) log.Println(string(out))
out, err = cmd.CombinedOutput() if err != nil {
log.Println(string(out)) log.Panicln("Error returned by importer.", err)
if err != nil { }
log.Panicln("Error returned by importer.", err)
} }
if !reposOK { if !reposOK {
@ -392,8 +398,6 @@ func main() {
switch org { switch org {
case "pool": case "pool":
return 1 return 1
case "rpm":
return 2
} }
return 0 // current devel to clone return 0 // current devel to clone
} }
@ -421,7 +425,7 @@ func main() {
repo := fork.Payload repo := fork.Payload
branchName := repo.DefaultBranch branchName := repo.DefaultBranch
if pkg.Owner.UserName == "pool" || pkg.Owner.UserName == "rpm" { if pkg.Owner.UserName == "pool" {
// forked a git-based devel project, so use the default branch name now // forked a git-based devel project, so use the default branch name now
repoList, err := client.Repository.RepoListBranches( repoList, err := client.Repository.RepoListBranches(
repository.NewRepoListBranchesParams().WithOwner(org).WithRepo(pkg.Name), repository.NewRepoListBranchesParams().WithOwner(org).WithRepo(pkg.Name),
@ -463,7 +467,7 @@ func main() {
} }
for _, pkg := range develProjectPackages { for _, pkg := range develProjectPackages {
ret, err := client.Organization.CreateOrgRepo(organization.NewCreateOrgRepoParams().WithOrg(org).WithBody( _, err := client.Organization.CreateOrgRepo(organization.NewCreateOrgRepoParams().WithOrg(org).WithBody(
&models.CreateRepoOption{ &models.CreateRepoOption{
ObjectFormatName: "sha256", ObjectFormatName: "sha256",
AutoInit: false, AutoInit: false,
@ -477,6 +481,29 @@ func main() {
log.Panicln("Error creating new package repository:", pkg, err) log.Panicln("Error creating new package repository:", pkg, err)
} }
ret, err := client.Repository.RepoEdit(repository.NewRepoEditParams().WithOwner(org).WithRepo(pkg).WithBody(
&models.EditRepoOption{
HasPullRequests: true,
HasPackages: false,
HasReleases: false,
HasActions: false,
AllowMerge: true,
AllowRebaseMerge: false,
AllowSquash: false,
AllowFastForwardOnly: true,
AllowRebaseUpdate: false,
AllowManualMerge: false,
DefaultMergeStyle: "fast-forward-only",
AllowRebase: false,
DefaultAllowMaintainerEdit: true,
}),
r.DefaultAuthentication,
)
if err != nil {
log.Panicln("Failed to adjust repository:", pkg, err)
}
repo := ret.Payload repo := ret.Payload
remotes := git.GitExecWithOutputOrPanic(pkg, "remote", "show") remotes := git.GitExecWithOutputOrPanic(pkg, "remote", "show")
if !slices.Contains(strings.Split(remotes, "\n"), "devel") { if !slices.Contains(strings.Split(remotes, "\n"), "devel") {
@ -494,4 +521,7 @@ func main() {
log.Panicln("Failed to set default branch for package fork:", repo.Owner.UserName, "/", repo.Name, err) log.Panicln("Failed to set default branch for package fork:", repo.Owner.UserName, "/", repo.Name, err)
} }
} }
// set maintainership from OBS ....
} }