Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deployer): limit comment length #12294

Merged
merged 5 commits into from
Dec 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading