diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index 6fcd29301230a..7df20ea845715 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -65,6 +65,14 @@ def run(self) -> bool:
return False
+def human_readable_size(size, decimal_places=2):
+ for unit in ["B", "KiB", "MiB", "GiB", "TiB", "PiB"]:
+ if size < 1024.0 or unit == "PiB":
+ break
+ size /= 1024.0
+ return f"{size:.{decimal_places}f} {unit}"
+
+
class PRSubscriber:
@property
def team_name(self) -> str:
@@ -77,23 +85,62 @@ def __init__(self, token: str, repo: str, pr_number: int, label_name: str):
self._team_name = "pr-subscribers-{}".format(label_name).lower()
def run(self) -> bool:
- for team in self.org.get_teams():
- if self.team_name != team.name.lower():
- continue
- try:
- # GitHub limits comments to 65,536 characters, let's limit our comments to 20,000.
- patch = requests.get(self.pr.diff_url).text[0:20000]
- except:
- patch = ""
- comment = (
- "@llvm/{}".format(team.slug)
- + "\n\nChanges
\n"
- + patch
- + "\n
\n" + patch + + # GitHub limits comments to 65,536 characters, let's limit the diff to 20kB. + DIFF_LIMIT = 20 * 1024 + patch_link = f"Full diff: {self.pr.diff_url}\n" + if len(patch) > DIFF_LIMIT: + patch_link = f"\nPatch is {human_readable_size(len(patch))}, truncated to {human_readable_size(DIFF_LIMIT)} below, full version: {self.pr.diff_url}\n" + diff_stats = diff_stats[0:DIFF_LIMIT] + "...\n" + + body = self.pr.body + comment = ( + "@llvm/{}".format(team.slug) + + "\n\n\n" + diff_stats += "