From 5eeb541533ae8b93f5ee7b65a47f685ac28310e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Meusel?= Date: Mon, 22 Jul 2024 12:36:56 +0200 Subject: [PATCH] Provide list of approvers in yaml rendering This will simplify the classification of patches after the auto-update bot has extracted them from the upstream changes. --- tools/auditinfo/auditinfo/auditor.py | 8 ++++++++ tools/auditupdate/auditupdate/cli.py | 2 +- tools/genaudit/genaudit/refs.py | 28 +++++++++++++++++++++++----- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/tools/auditinfo/auditinfo/auditor.py b/tools/auditinfo/auditinfo/auditor.py index c7f725d1..90696233 100644 --- a/tools/auditinfo/auditinfo/auditor.py +++ b/tools/auditinfo/auditinfo/auditor.py @@ -7,6 +7,14 @@ def __init__(self, name: str, github_handle: str): self.name = name self.github_handle = github_handle[1:] if github_handle.startswith('@') else github_handle + def __eq__(self, other): + if not isinstance(other, type(self)): + return NotImplemented + return self.github_handle == other.github_handle + + def __hash__(self): + return self.github_handle.__hash__() + def authorative_auditors() -> list[Auditor]: auditors_file = auditors_file_path() strm = open(auditors_file, 'r') diff --git a/tools/auditupdate/auditupdate/cli.py b/tools/auditupdate/auditupdate/cli.py index e5181ef7..1b1c2a38 100644 --- a/tools/auditupdate/auditupdate/cli.py +++ b/tools/auditupdate/auditupdate/cli.py @@ -48,7 +48,7 @@ def update_uncategorized_patches(audit: genaudit.Audit, repo: genaudit.GitRepo, ])) # render all found unreferenced patches - rendered_unrefed_patches = ''.join([f"\n{patch.render_patch(repo, True)}\n" for patch in unrefed_patches]) + rendered_unrefed_patches = ''.join([f"\n{patch.render_patch(repo, yaml=True, approvers=True)}\n" for patch in unrefed_patches]) unrefed_topic.write(rendered_unrefed_patches) return True diff --git a/tools/genaudit/genaudit/refs.py b/tools/genaudit/genaudit/refs.py index 5db5fca8..3904fb1a 100644 --- a/tools/genaudit/genaudit/refs.py +++ b/tools/genaudit/genaudit/refs.py @@ -5,6 +5,8 @@ from enum import IntEnum from functools import total_ordering +import auditinfo + from github.PullRequest import PullRequest as GithubPullRequest from github.Commit import Commit as GithubCommit @@ -58,9 +60,9 @@ def __init__(self, commit_ref: str, classification: Classification, auditer: str self.auditer = auditer self.comment = comment - def render_patch(self, repo, yaml: bool = False): + def render_patch(self, repo, yaml: bool = False, approvers: bool = False): if isinstance(self, PullRequest): - return self.render(repo.pull_request_info(self), yaml) + return self.render(repo.pull_request_info(self), yaml, approvers) elif isinstance(self, Commit): return self.render(repo.commit_info(self), yaml) else: @@ -86,10 +88,25 @@ def __lt__(self, other): def merge_commit(self): return Commit(self.ref) if self.ref else None - def render(self, pr_info: GithubPullRequest, yaml: bool = False) -> str: + def render(self, pr_info: GithubPullRequest, yaml: bool = False, render_approvers: bool = False) -> str: + if render_approvers: + all_approvers = list(set([auditinfo.Auditor(review.user.name, review.user.login) for review in pr_info.get_reviews() if review.state == "APPROVED"])) + authorative_auditors = [auditor for auditor in all_approvers if auditor in auditinfo.authorative_auditors()] + other_approvers = [approver for approver in all_approvers if approver not in auditinfo.authorative_auditors()] + if yaml: out = [ - f"# {pr_info.title} (@{pr_info.user.login})", + f"# {pr_info.title}", + f"# Author: @{pr_info.user.login}" + ] + if render_approvers: + approvers = [f'@{auditor.github_handle}' for auditor in authorative_auditors] + approvers += [f'(@{approver.github_handle})' for approver in other_approvers] + if approvers: + out += [ + f"# Approvals: {', '.join(approvers)}", + ] + out += [ f"- pr: {pr_info.number} # {pr_info.html_url}", f" merge_commit: {self.ref}", f" classification: {self.classification.to_string()}", @@ -127,7 +144,8 @@ def render(self, co_info: GithubCommit, yaml: bool = False) -> str: author = co_info.commit.author.name if yaml: out = [ - f"# {msg} ({author})", + f"# {msg}", + f"# Author: {author}", f"- commit: {co_info.sha} # {co_info.html_url}", f" classification: {self.classification.to_string()}", ]