Skip to content

Commit

Permalink
truncate comment
Browse files Browse the repository at this point in the history
  • Loading branch information
argl committed Dec 12, 2024
1 parent 75fe0ee commit 1c1ad89
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions deployer/src/deployer/analyze_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from .utils import log

MAX_COMMENT_BODY_LENGTH = 65500
MAX_COMMENT_BODY_LENGTH = 65000

hidden_comment_regex = re.compile(
r"<!-- build_hash: ([a-f0-9]+) date: ([\d:\.\- ]+) -->"
Expand Down Expand Up @@ -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 = []
Expand Down

0 comments on commit 1c1ad89

Please sign in to comment.