Skip to content

Commit

Permalink
fix(deployer): limit comment length (#12294)
Browse files Browse the repository at this point in the history
* limit comment length in deployer
  • Loading branch information
argl authored Dec 12, 2024
1 parent a9daa1f commit e36c538
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions deployer/src/deployer/analyze_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

from .utils import log

MAX_COMMENT_BODY_LENGTH = 65000

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

0 comments on commit e36c538

Please sign in to comment.