[llvm] [Github] Escape `@` and html in the <details> block (PR #66118)

via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 12 10:58:03 PDT 2023


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

>From a3709722e3e8293bca0c8f9853bd9ffea9d89c1d Mon Sep 17 00:00:00 2001
From: Corentin Jabot <corentinjabot at gmail.com>
Date: Tue, 12 Sep 2023 19:48:47 +0200
Subject: [PATCH 1/2] [Github] Escape `@` and html in the <details> block

* This avoid pinging folks on all issue when they got pinged on
bugzilla eaons ago

* Avoid formating bugs when there is html in the issue description
---
 llvm/utils/git/github-automation.py | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index c4c4848fbc5f8bc..66171cd7bd0144b 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -11,6 +11,7 @@
 import argparse
 from git import Repo  # type: ignore
 import github
+import html
 import os
 import re
 import requests
@@ -45,6 +46,9 @@ def _get_curent_team(team_name, teams) -> Optional[github.Team.Team]:
             return team
     return None
 
+def escape_description(str):
+    # https://github.com/github/markup/issues/1168#issuecomment-494946168
+    return html.escape(str.replace("@", "@<!-- -->"), False)
 
 class IssueSubscriber:
     @property
@@ -66,12 +70,15 @@ def run(self) -> bool:
         if team.slug == "issue-subscribers-good-first-issue":
             comment = "{}\n".format(beginner_comment)
 
-        comment = (
-            f"@llvm/{team.slug}"
-            + "\n\n<details>\n"
-            + f"{self.issue.body}\n"
-            + "</details>"
-        )
+        body = escape_description(self.issue.body)
+
+        comment = ( f"""
+ at llvm/{team.slug}
+
+<details>
+{body}
+</details>
+""" )
 
         self.issue.create_comment(comment)
         return True

>From f7a60f1b73db8ef677eb6f6c1b4d17822eeaf471 Mon Sep 17 00:00:00 2001
From: Corentin Jabot <corentinjabot at gmail.com>
Date: Tue, 12 Sep 2023 19:57:49 +0200
Subject: [PATCH 2/2] Fix order of operations: we should escape html first so
 the comment does not get escaped

---
 llvm/utils/git/github-automation.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index 66171cd7bd0144b..f7fa0eb920b130d 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -48,7 +48,8 @@ def _get_curent_team(team_name, teams) -> Optional[github.Team.Team]:
 
 def escape_description(str):
     # https://github.com/github/markup/issues/1168#issuecomment-494946168
-    return html.escape(str.replace("@", "@<!-- -->"), False)
+    str = html.escape(str, False)
+    return str.replace("@", "@<!-- -->")
 
 class IssueSubscriber:
     @property



More information about the llvm-commits mailing list