diff --git a/deployer/src/deployer/analyze_pr.py b/deployer/src/deployer/analyze_pr.py index 8d18ba0c81c2..aa0fe33eb304 100644 --- a/deployer/src/deployer/analyze_pr.py +++ b/deployer/src/deployer/analyze_pr.py @@ -12,7 +12,7 @@ from .utils import log -MAX_COMMENT_BODY_LENGTH = 65500 +MAX_COMMENT_BODY_LENGTH = 65000 hidden_comment_regex = re.compile( r"" @@ -77,15 +77,20 @@ 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[:MAX_COMMENT_BODY_LENGTH]) + github_issue.create_comment(truncate_comment(combined_comment)) return combined_comment +# Truncates the content of a comment if it exceeds the maximum length of 64k (a GH API constraint). +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 = []