Skip to content

Commit 47ad7a0

Browse files
committed
Use a markdown codeblock for the diff.
This way we can render < and & properly. This only work if there is a new line before the 3 ticks.
1 parent 8c0b3bc commit 47ad7a0

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

llvm/utils/git/github-automation.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ def escape_description(str):
5656
str = re.sub("#(?=\d+\s)", "#<!-- -->", str)
5757
return str
5858

59+
def sanitize_markdown_code_block(str):
60+
# remove codeblocks terminators
61+
return re.sub("^\s*```\s*$", r"` ` `", str)
5962

6063
class IssueSubscriber:
6164
@property
@@ -148,18 +151,21 @@ def run(self) -> bool:
148151

149152
# Get the diff
150153
try:
151-
patch = html.escape(requests.get(self.pr.diff_url).text)
154+
patch = requests.get(self.pr.diff_url).text
152155
except:
153156
patch = ""
154157

155-
# GitHub limits comments to 65,536 characters, let's limit the diff to 20kB.
158+
patch = sanitize_markdown_code_block(patch)
159+
156160
patch_link = f"Full diff: {self.pr.diff_url}\n"
157161
if len(patch) > DIFF_LIMIT:
158162
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"
159-
patch = html.escape(patch[0:DIFF_LIMIT]) + "...\n<truncated>\n"
163+
patch = patch[0:DIFF_LIMIT] + "...\n[truncated]\n"
160164
team_mention = "@llvm/{}".format(team.slug)
161165

162166
body = escape_description(self.pr.body)
167+
# Note: the comment is in markdown and the code below
168+
# is sensible to line break
163169
comment = f"""
164170
{self.COMMENT_TAG}
165171
{team_mention}
@@ -172,9 +178,10 @@ def run(self) -> bool:
172178
173179
{diff_stats}
174180
175-
<pre lang="diff">
181+
```diff
176182
{patch}
177-
</pre>
183+
```
184+
178185
</details>
179186
"""
180187

0 commit comments

Comments
 (0)