From 75fe0eeec6880898968c1e7efed04411453b2185 Mon Sep 17 00:00:00 2001 From: Andi Pieper Date: Thu, 12 Dec 2024 10:58:41 +0100 Subject: [PATCH 1/4] limit comment length in deployer --- deployer/src/deployer/analyze_pr.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/deployer/src/deployer/analyze_pr.py b/deployer/src/deployer/analyze_pr.py index f1e3ddcf20de..8d18ba0c81c2 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 = 65500 + hidden_comment_regex = re.compile( r"" ) @@ -80,7 +82,7 @@ def analyze_pr(build_directory: Path, config): break else: - github_issue.create_comment(combined_comment) + github_issue.create_comment(combined_comment[:MAX_COMMENT_BODY_LENGTH]) return combined_comment From 1c1ad89aa4acf782908c813b1b1acb73c3f20ca7 Mon Sep 17 00:00:00 2001 From: Andi Pieper Date: Thu, 12 Dec 2024 18:29:02 +0100 Subject: [PATCH 2/4] truncate comment --- deployer/src/deployer/analyze_pr.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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 = [] From 75c352fe85d68436a8caff7329922b171ca55309 Mon Sep 17 00:00:00 2001 From: Andi Pieper Date: Thu, 12 Dec 2024 18:32:06 +0100 Subject: [PATCH 3/4] removed comment --- deployer/src/deployer/analyze_pr.py | 1 - 1 file changed, 1 deletion(-) diff --git a/deployer/src/deployer/analyze_pr.py b/deployer/src/deployer/analyze_pr.py index aa0fe33eb304..0159d2b0fa57 100644 --- a/deployer/src/deployer/analyze_pr.py +++ b/deployer/src/deployer/analyze_pr.py @@ -86,7 +86,6 @@ def analyze_pr(build_directory: Path, config): 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!" From 7f69bdb07130d37438e8ed19a3a49a9d485f0f2d Mon Sep 17 00:00:00 2001 From: Andi Pieper Date: Thu, 12 Dec 2024 18:34:07 +0100 Subject: [PATCH 4/4] linter --- deployer/src/deployer/analyze_pr.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/deployer/src/deployer/analyze_pr.py b/deployer/src/deployer/analyze_pr.py index 0159d2b0fa57..3e965d10d024 100644 --- a/deployer/src/deployer/analyze_pr.py +++ b/deployer/src/deployer/analyze_pr.py @@ -86,11 +86,13 @@ def analyze_pr(build_directory: Path, config): 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):