[llvm] [Github] Improve formating of PR diffs in bot notifications (PR #66118)

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 18 06:14:48 PDT 2023


================
@@ -125,35 +143,41 @@ def run(self) -> bool:
             if file.status == "renamed":
                 print(f"(from {file.previous_filename})")
             diff_stats += "\n"
-        diff_stats += "\n"
+            if len(diff_stats) > STAT_LIMIT:
+                break
 
         # Get the diff
         try:
-            patch = html.escape(requests.get(self.pr.diff_url).text)
+            patch = requests.get(self.pr.diff_url).text
         except:
             patch = ""
-        diff_stats += "\n<pre>\n" + html.escape(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<truncated>\n"
-        diff_stats += "</pre>"
+            patch = patch[0:DIFF_LIMIT] + "...\n[truncated]\n"
         team_mention = "@llvm/{}".format(team.slug)
 
-        body = self.pr.body
+        body = escape_description(self.pr.body)
+        # Note: the comment is in markdown and the code below
+        # is sensible to line break
         comment = f"""
 {self.COMMENT_TAG}
 {team_mention}
-            
+
 <details>
 <summary>Changes</summary>
+
 {body}
---
+---
----------------
jayfoad wrote:

This change (three dashes) causes the last paragraph of the body to be rendered like a title, which looks awful, e.g.: the "After legalization is done" paragraph in this issue: https://github.com/llvm/llvm-project/pull/66567#issuecomment-1722108154

https://github.com/llvm/llvm-project/pull/66118


More information about the llvm-commits mailing list