From 4fb77452603d2c72f4278d016d4bce3f9aa1020b Mon Sep 17 00:00:00 2001 From: Andi Pieper Date: Thu, 12 Dec 2024 19:59:46 +0100 Subject: [PATCH] fix(deployer): limit comment length (#12294) * limit comment length in deployer --- deployer/src/deployer/analyze_pr.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/deployer/src/deployer/analyze_pr.py b/deployer/src/deployer/analyze_pr.py index f1e3ddcf20de..3e965d10d024 100644 --- a/deployer/src/deployer/analyze_pr.py +++ b/deployer/src/deployer/analyze_pr.py @@ -12,6 +12,8 @@ from .utils import log +MAX_COMMENT_BODY_LENGTH = 65000 + hidden_comment_regex = re.compile( r"" ) @@ -75,16 +77,22 @@ def analyze_pr(build_directory: Path, config): if hidden_comment_regex.search(comment.body): now = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S") combined_comment += f"\n\n*(comment last updated: {now})*" - comment.edit(body=combined_comment) + comment.edit(body=truncate_comment(combined_comment)) print(f"Updating existing comment ({comment})") break else: - github_issue.create_comment(combined_comment) + github_issue.create_comment(truncate_comment(combined_comment)) return combined_comment +def truncate_comment(comment): + if len(comment) > MAX_COMMENT_BODY_LENGTH: + return comment[:MAX_COMMENT_BODY_LENGTH] + "…\n\nTRUNCATED!" + return comment + + def post_about_deployment(build_directory: Path, **config): links = [] for doc in get_built_docs(build_directory):