|
19 | 19 | from pylint.reporters import JSONReporter
|
20 | 20 | from pylint.testutils.primer import PackageToLint
|
21 | 21 |
|
| 22 | +MAX_GITHUB_COMMENT_LENGTH = 65536 |
22 | 23 | TESTS_DIR = Path(__file__).parent.parent
|
23 | 24 | PRIMER_DIRECTORY = TESTS_DIR / ".pylint_primer_tests/"
|
24 | 25 | PACKAGES_TO_PRIME_PATH = Path(__file__).parent / "packages_to_prime.json"
|
@@ -189,6 +190,9 @@ def _create_comment(
|
189 | 190 | ) -> None:
|
190 | 191 | comment = ""
|
191 | 192 | for package, missing_messages in all_missing_messages.items():
|
| 193 | + if len(comment) >= MAX_GITHUB_COMMENT_LENGTH: |
| 194 | + break |
| 195 | + |
192 | 196 | new_messages = all_new_messages[package]
|
193 | 197 | package_data = self.packages[package]
|
194 | 198 |
|
@@ -255,14 +259,29 @@ def _create_comment(
|
255 | 259 | comment += "\n</details>\n\n"
|
256 | 260 |
|
257 | 261 | if comment == "":
|
258 |
| - comment = "🤖 According to the primer, this change has **no effect** on the checked open source code. 🤖🎉" |
| 262 | + comment = ( |
| 263 | + "🤖 According to the primer, this change has **no effect** on the" |
| 264 | + " checked open source code. 🤖🎉\n\n" |
| 265 | + ) |
259 | 266 | else:
|
260 | 267 | comment = (
|
261 |
| - "🤖 **Effect of this PR on checked open source code:** 🤖\n\n" + comment |
| 268 | + f"🤖 **Effect of this PR on checked open source code:** 🤖\n\n{comment}" |
262 | 269 | )
|
263 |
| - |
264 |
| - comment += f"*This comment was generated for commit {self.config.commit}*" |
265 |
| - |
| 270 | + hash_information = ( |
| 271 | + f"*This comment was generated for commit {self.config.commit}*" |
| 272 | + ) |
| 273 | + if len(comment) + len(hash_information) >= MAX_GITHUB_COMMENT_LENGTH: |
| 274 | + truncation_information = ( |
| 275 | + f"*This comment was truncated because GitHub allows only" |
| 276 | + f"{MAX_GITHUB_COMMENT_LENGTH} characters in a comment.*" |
| 277 | + ) |
| 278 | + max_len = ( |
| 279 | + MAX_GITHUB_COMMENT_LENGTH |
| 280 | + - len(hash_information) |
| 281 | + - len(truncation_information) |
| 282 | + ) |
| 283 | + comment = f"{comment[:max_len - 10]}...\n\n{truncation_information}\n\n" |
| 284 | + comment += hash_information |
266 | 285 | with open(PRIMER_DIRECTORY / "comment.txt", "w", encoding="utf-8") as f:
|
267 | 286 | f.write(comment)
|
268 | 287 |
|
|
0 commit comments