@@ -51,7 +51,7 @@ def _get_curent_team(team_name, teams) -> Optional[github.Team.Team]:
5151def escape_description (str ):
5252 # https://github.com/github/markup/issues/1168#issuecomment-494946168
5353 str = html .escape (str , False )
54- return str .replace ("@" , "@<!-- -->" )
54+ return str .replace ("@" , "@<!-- -->" ). replace ( "#" , "#<!-- -->" )
5555
5656
5757class IssueSubscriber :
@@ -123,6 +123,11 @@ def run(self) -> bool:
123123 print (f"couldn't find team named { self .team_name } " )
124124 return False
125125
126+ # GitHub limits comments to 65,536 characters, let's limit the diff
127+ # and the file list to 20kB each.
128+ STAT_LIMIT = 20 * 1024
129+ DIFF_LIMIT = 20 * 1024
130+
126131 # Get statistics for each file
127132 diff_stats = f"{ self .pr .changed_files } Files Affected:\n \n "
128133 for file in self .pr .get_files ():
@@ -133,37 +138,40 @@ def run(self) -> bool:
133138 diff_stats += f"-{ file .deletions } "
134139 diff_stats += ") "
135140 if file .status == "renamed" :
136- print (f"(from { file .previous_filename } )" )
141+ print (f"(from { file .previous_filename } )"
137142 diff_stats += "\n "
138- diff_stats += "\n "
143+ if len (diff_stats ) > STAT_LIMIT )
144+ break
139145
140146 # Get the diff
141147 try :
142148 patch = html .escape (requests .get (self .pr .diff_url ).text )
143149 except :
144150 patch = ""
145- diff_stats += "\n <pre>\n " + patch
146151
147152 # GitHub limits comments to 65,536 characters, let's limit the diff to 20kB.
148- DIFF_LIMIT = 20 * 1024
149153 patch_link = f"Full diff: { self .pr .diff_url } \n "
150154 if len (patch ) > DIFF_LIMIT :
151155 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 "
152- diff_stats = html .escape (diff_stats [0 :DIFF_LIMIT ]) + "...\n <truncated>\n "
153- diff_stats += "</pre>"
156+ patch = html .escape (patch [0 :DIFF_LIMIT ]) + "...\n <truncated>\n "
154157 team_mention = "@llvm/{}" .format (team .slug )
155158
156- body = self .pr .body
159+ body = escape_description ( self .pr .body )
157160 comment = f"""
158161{ self .COMMENT_TAG }
159162{ team_mention }
160-
163+
161164<details>
162165<summary>Changes</summary>
163166{ body }
164167--
165168{ patch_link }
169+
166170{ diff_stats }
171+
172+ <pre lang="diff">
173+ { patch }
174+ </pre>
167175</details>
168176"""
169177
0 commit comments