diff options
author | 2022-04-06 21:08:40 +0300 | |
---|---|---|
committer | 2022-04-06 21:08:40 +0300 | |
commit | 5fa6ea3b1d1a78edc97608a3f92db07ab4ca19b7 (patch) | |
tree | c71e353d0e44cb00b2c3c6c066747644d70652c9 /scripts | |
parent | Add new empty emails workflow (diff) | |
download | guru-5fa6ea3b1d1a78edc97608a3f92db07ab4ca19b7.tar.gz guru-5fa6ea3b1d1a78edc97608a3f92db07ab4ca19b7.tar.bz2 guru-5fa6ea3b1d1a78edc97608a3f92db07ab4ca19b7.zip |
Add emails checker against bugzilla workflow
A new check that checks that all new emails written in metadata.xml
correspond to existing user in bugzilla.
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/email-checker.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/scripts/email-checker.py b/scripts/email-checker.py new file mode 100755 index 0000000000..2b6e93a1de --- /dev/null +++ b/scripts/email-checker.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 + +from http.client import HTTPSConnection +import json +import sys +from typing import Dict, Iterator, NamedTuple +from urllib.parse import quote_plus +import xml.etree.ElementTree as ET + + +class Maintainer(NamedTuple): + name: str + email: str + + def check_details(self, client: HTTPSConnection): + try: + client.request("GET", f"/rest/user?names={quote_plus(self.email)}") + resp = client.getresponse() + resp.read() + return resp.status == 200 + except: + return False + + +def read_all_maintainers(files: Iterator[str]) -> Iterator[Maintainer]: + for file in files: + try: + tree = ET.parse(file) + for maintainer in tree.findall('./maintainer'): + values = {child.tag: child.text for child in maintainer} + yield Maintainer(name=values.get('name', ''), email=values.get('email', '')) + except FileNotFoundError: + print(file, 'not found') + + +def check_maintainers(maintainers: Iterator[Maintainer]) -> Iterator[Maintainer]: + try: + client = HTTPSConnection('bugs.gentoo.org') + for m in maintainers: + if m.check_details(client): + print(f'\033[92m\u2713 {m.name} <{m.email}>\033[0m') + else: + print(f'\033[91m\u2717 {m.name} <{m.email}>\033[0m') + yield m + finally: + client.close() + + +if __name__ == '__main__': + missing_maintainers = len(tuple(check_maintainers(set(read_all_maintainers(sys.argv[1:]))))) + sys.exit(int(missing_maintainers != 0)) |