mirror of
https://github.com/gentoo-mirror/guru.git
synced 2026-07-20 20:43:09 -04:00
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>
This commit is contained in:
29
.github/workflows/emails.yml
vendored
29
.github/workflows/emails.yml
vendored
@@ -6,5 +6,34 @@ jobs:
|
|||||||
bugzilla:
|
bugzilla:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
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
|
- name: Checkout code
|
||||||
uses: actions/checkout@v2
|
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 }}
|
||||||
|
|||||||
51
scripts/email-checker.py
Executable file
51
scripts/email-checker.py
Executable file
@@ -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))
|
||||||
Reference in New Issue
Block a user