From fd2d7cdb36e483623b0c46d1beda5f65232c73f4 Mon Sep 17 00:00:00 2001 From: Arthur Zamarin Date: Fri, 29 Dec 2023 13:24:31 +0200 Subject: bugs: auto extend maintainers with projects When ``--projects`` is passed, fetch ``projects.xml``, and extent the maintainers list with projects whose members include maintainers. Resolves: https://github.com/pkgcore/pkgdev/issues/157 Signed-off-by: Arthur Zamarin --- data/share/bash-completion/completions/pkgdev | 1 + src/pkgdev/scripts/pkgdev_bugs.py | 30 ++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/data/share/bash-completion/completions/pkgdev b/data/share/bash-completion/completions/pkgdev index acb4f68..98c2001 100644 --- a/data/share/bash-completion/completions/pkgdev +++ b/data/share/bash-completion/completions/pkgdev @@ -247,6 +247,7 @@ _pkgdev() { --api-key --auto-cc-arches --find-by-maintainer + --projects --filter-stablereqs --stabletime --blocks diff --git a/src/pkgdev/scripts/pkgdev_bugs.py b/src/pkgdev/scripts/pkgdev_bugs.py index a3c6c3a..fb60ff1 100644 --- a/src/pkgdev/scripts/pkgdev_bugs.py +++ b/src/pkgdev/scripts/pkgdev_bugs.py @@ -20,13 +20,14 @@ from pkgcore.ebuild.atom import atom from pkgcore.ebuild.ebuild_src import package from pkgcore.ebuild.errors import MalformedAtom from pkgcore.ebuild.misc import sort_keywords -from pkgcore.ebuild.repo_objs import LocalMetadataXml +from pkgcore.ebuild.repo_objs import LocalMetadataXml, ProjectsXml from pkgcore.repository import multiplex from pkgcore.restrictions import boolean, packages, values from pkgcore.test.misc import FakePkg from pkgcore.util import commandline, parserestrict from snakeoil.cli import arghparse from snakeoil.cli.input import userquery +from snakeoil.data_source import bytes_data_source from snakeoil.formatters import Formatter from snakeoil.osutils import pjoin @@ -77,6 +78,18 @@ bugs.add_argument( to find matches, which can be slow (between 1 to 3 seconds). """, ) +bugs.add_argument( + "--projects", + action="store_true", + help="include packages maintained by projects", + docs=""" + Include packages maintained by projects, whose members include the + emails of maintainers passed to ``--find-by-maintainer``. + + Note that this flag requires to fetch the ``projects.xml`` file from + ``https://api.gentoo.org``. + """, +) bugs.add_argument( "--filter-stablereqs", action="store_true", @@ -340,8 +353,23 @@ class DependencyGraph: except (ValueError, IndexError): self.err.write(f"Unable to find match for {pkg.unversioned_atom}") + def _extend_projects(self, disabled, enabled): + members = defaultdict(set) + self.out.write("Fetching projects.xml") + self.out.flush() + with urllib.urlopen("https://api.gentoo.org/metastructure/projects.xml", timeout=30) as f: + for email, project in ProjectsXml(bytes_data_source(f.read())).projects.items(): + for member in project.members: + members[member.email].add(email) + + disabled = frozenset(disabled).union(*(members[email] for email in disabled)) + enabled = frozenset(enabled).union(*(members[email] for email in enabled)) + return disabled, enabled + def extend_maintainers(self): disabled, enabled = self.options.find_by_maintainer + if self.options.projects: + disabled, enabled = self._extend_projects(disabled, enabled) emails = frozenset(enabled).difference(disabled) if not emails: return -- cgit v1.2.3-65-gdbad