From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id CD22715808B for ; Wed, 6 Apr 2022 19:43:15 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id D6DECE0CE6; Wed, 6 Apr 2022 19:43:05 +0000 (UTC) Received: from smtp.gentoo.org (mail.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id B5818E0CA1 for ; Wed, 6 Apr 2022 19:43:03 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id CBE7B3411B3 for ; Wed, 6 Apr 2022 19:43:02 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 6697B391 for ; Wed, 6 Apr 2022 19:43:01 +0000 (UTC) From: "Michał Górny" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Michał Górny" Message-ID: <1649268520.5fa6ea3b1d1a78edc97608a3f92db07ab4ca19b7.mgorny@gentoo> Subject: [gentoo-commits] repo/proj/guru:master commit in: scripts/, .github/workflows/ X-VCS-Repository: repo/proj/guru X-VCS-Files: .github/workflows/emails.yml scripts/email-checker.py X-VCS-Directories: .github/workflows/ scripts/ X-VCS-Committer: mgorny X-VCS-Committer-Name: Michał Górny X-VCS-Revision: 5fa6ea3b1d1a78edc97608a3f92db07ab4ca19b7 X-VCS-Branch: master Date: Wed, 6 Apr 2022 19:43:01 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: eff8a112-1723-4b4b-a7c9-68e51e6958ae X-Archives-Hash: e241c6e249630c7b4020267067319a0a commit: 5fa6ea3b1d1a78edc97608a3f92db07ab4ca19b7 Author: Arthur Zamarin gentoo org> AuthorDate: Wed Apr 6 18:08:40 2022 +0000 Commit: Michał Górny gentoo org> CommitDate: Wed Apr 6 18:08:40 2022 +0000 URL: https://gitweb.gentoo.org/repo/proj/guru.git/commit/?id=5fa6ea3b 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 gentoo.org> .github/workflows/emails.yml | 29 +++++++++++++++++++++++++ scripts/email-checker.py | 51 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/.github/workflows/emails.yml b/.github/workflows/emails.yml index 6871760f4..e7791f558 100644 --- a/.github/workflows/emails.yml +++ b/.github/workflows/emails.yml @@ -6,5 +6,34 @@ jobs: bugzilla: runs-on: ubuntu-latest steps: + + - uses: nrwl/last-successful-commit-action@v1 + id: last_successful_commit + with: + branch: 'dev' + workflow_id: 'emails.yml' + github_token: ${{ secrets.GITHUB_TOKEN }} + + - name: Checkout compare ref + uses: actions/checkout@v2 + with: + ref: ${{ steps.last_successful_commit.outputs.commit_hash }} + - name: Checkout code uses: actions/checkout@v2 + + - uses: actions/setup-python@v3 + with: + python-version: '3.x' + + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v18.6 + with: + base_sha: ${{ steps.last_successful_commit.outputs.commit_hash }} + files: | + **/metadata.xml + + - name: Check Emails against bugzilla + run: | + python ./scripts/email-checker.py ${{ steps.changed-files.outputs.all_changed_files }} diff --git a/scripts/email-checker.py b/scripts/email-checker.py new file mode 100755 index 000000000..2b6e93a1d --- /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))