@@ -56,6 +56,9 @@ def escape_description(str):
56
56
str = re .sub ("#(?=\d+\s)" , "#<!-- -->" , str )
57
57
return str
58
58
59
+ def sanitize_markdown_code_block (str ):
60
+ # remove codeblocks terminators
61
+ return re .sub ("^\s*```\s*$" , r"` ` `" , str )
59
62
60
63
class IssueSubscriber :
61
64
@property
@@ -148,18 +151,21 @@ def run(self) -> bool:
148
151
149
152
# Get the diff
150
153
try :
151
- patch = html . escape ( requests .get (self .pr .diff_url ).text )
154
+ patch = requests .get (self .pr .diff_url ).text
152
155
except :
153
156
patch = ""
154
157
155
- # GitHub limits comments to 65,536 characters, let's limit the diff to 20kB.
158
+ patch = sanitize_markdown_code_block (patch )
159
+
156
160
patch_link = f"Full diff: { self .pr .diff_url } \n "
157
161
if len (patch ) > DIFF_LIMIT :
158
162
patch_link = f"\n Patch is { human_readable_size (len (patch ))} , truncated to { human_readable_size (DIFF_LIMIT )} below, full version: { self .pr .diff_url } \n "
159
- patch = html . escape ( patch [0 :DIFF_LIMIT ]) + "...\n < truncated> \n "
163
+ patch = patch [0 :DIFF_LIMIT ] + "...\n [ truncated] \n "
160
164
team_mention = "@llvm/{}" .format (team .slug )
161
165
162
166
body = escape_description (self .pr .body )
167
+ # Note: the comment is in markdown and the code below
168
+ # is sensible to line break
163
169
comment = f"""
164
170
{ self .COMMENT_TAG }
165
171
{ team_mention }
@@ -172,9 +178,10 @@ def run(self) -> bool:
172
178
173
179
{ diff_stats }
174
180
175
- <pre lang=" diff">
181
+ ``` diff
176
182
{ patch }
177
- </pre>
183
+ ```
184
+
178
185
</details>
179
186
"""
180
187
0 commit comments