Skip to content

Commit

Permalink
Provide list of approvers in yaml rendering
Browse files Browse the repository at this point in the history
This will simplify the classification of patches after the auto-update
bot has extracted them from the upstream changes.
  • Loading branch information
reneme committed Jul 22, 2024
1 parent 5929bb7 commit 5eeb541
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
8 changes: 8 additions & 0 deletions tools/auditinfo/auditinfo/auditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion tools/auditupdate/auditupdate/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 23 additions & 5 deletions tools/genaudit/genaudit/refs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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()}",
Expand Down Expand Up @@ -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()}",
]
Expand Down

0 comments on commit 5eeb541

Please sign in to comment.