Commit dde9e3a0 authored by Lorenz Huedepohl's avatar Lorenz Huedepohl
Browse files

Transfer maintainer state into branches

parent 4c06a8b3
Pipeline #67029 passed with stage
in 15 seconds
......@@ -85,6 +85,15 @@ def project_meta(api_url, project):
return ElementTree.fromstringlist(osc.core.show_project_meta(api_url, project))
def package_meta(api_url, project, package):
return ElementTree.fromstringlist(osc.core.show_package_meta(api_url, project, package))
def maintainers(api_url, project, package):
root = package_meta(api_url, project, package)
return {e.get("userid") for e in root.findall("./person[@role='maintainer']")}
class UnsetAttributeException(Exception):
......@@ -175,7 +184,7 @@ def mpcdf_enable_repositories(api_url, project, package, verbose=False, filter_r
if filter_repos is None:
filter_repos = ()
root = ElementTree.fromstringlist(osc.core.show_package_meta(api_url, project, package))
root = package_meta(api_url, project, package)
build = root.find("./build")
if build is None:
build = ElementTree.SubElement(root, "build")
......@@ -555,6 +564,19 @@ def sync_projects(api_url, package=None, from_project="software", to_projects=No
set_attribute(api_url, to_project, orig_package, attr)
from_maintainers = maintainers(api_url, from_project, orig_package)
if from_maintainers:
to_maintainers = maintainers(api_url, to_project, orig_package)
if from_maintainers - to_maintainers:
new_maintainers = from_maintainers - to_maintainers
to_meta = package_meta(api_url, to_project, orig_package)
for userid in new_maintainers:
person = ElementTree.Element("person")
person.set("userid", userid)
person.set("role", "maintainer")
to_meta.insert(2, person)
osc.core.edit_meta("pkg", (to_project, orig_package), data=ElementTree.tostring(to_meta))
if package is None and redo_all:
# Check if distribution is already set in to_project
to_prj_meta = project_meta(api_url, to_project)
......@@ -74,8 +74,7 @@ def do_mpcdf_push(self, subcmd, opts, *args):
package_attributes = ["MPCDF:enable_repositories"] + project_attributes
root = ElementTree.fromstringlist(osc.core.show_package_meta(api_url, to_project, package))
existing_maintainers = {e.get("userid") for e in root.findall("./person[@role='maintainer']")}
existing_maintainers = mpcdf_common.maintainers(api_url, to_project, package)
except osc.core.HTTPError as e:
if e.code == 404:
existing_maintainers = set()
......@@ -108,12 +107,12 @@ def do_mpcdf_push(self, subcmd, opts, *args):
user = osc.conf.get_apiurl_usr(api_url)
if user not in existing_maintainers:
print("Adding you to the list of maintainers for this package")
r = osc.core.Request()
r.add_action("add_role", tgt_project=to_project, tgt_package=package, person_name=user, person_role="maintainer")
r.description = "Add user {0} as maintainer due to 'osc mpcdf_push'".format(user)
result = osc.core.change_request_state(api_url, r.reqid, 'accepted', "Accepted on the command line via 'osc mpcdf_push'")
print(" Accepting request {0}:".format(r.reqid), result)
to_meta = mpcdf_common.package_meta(api_url, to_project, package)
person = ElementTree.Element("person")
person.set("userid", user)
person.set("role", "maintainer")
to_meta.insert(2, person)
osc.core.edit_meta("pkg", (to_project, package), data=ElementTree.tostring(to_meta))
# Give the system some time, sadly there is no transactional guarantee
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment