post_gerrit_comment.sh: Add a helper to limit size of Gerrit comment
Trim the comment to be posted to be under 16K, which appears to be
Gerrit's limit (violating it causes error and build failure).
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
Change-Id: I645b84b5e6d931004f526a3463044af77151e7b5
(cherry picked from commit cf3f73c97f69c7454f155c42f00dd06de255d46d)
diff --git a/eclair/prepare_gerrit_comment.py b/eclair/prepare_gerrit_comment.py
new file mode 100755
index 0000000..1ef0052
--- /dev/null
+++ b/eclair/prepare_gerrit_comment.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python3
+#
+# Copyright (c) 2022 Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+
+# Script to prepare a textual body of a comment to pass on the command line
+# to Gerrit: limit it to acceptable size and quote properly.
+
+import sys
+import shlex
+
+
+SIZE_LIMIT = 16000
+
+
+body = ""
+
+with open(sys.argv[1], "r") as f:
+ for l in f:
+ body += l
+ if len(body) >= SIZE_LIMIT:
+ body += """\
+[...]
+
+WARNING: The report was trimmed due to size limit of a Gerrit comment.
+Follow the link at the beginning to see the full report.
+"""
+ break
+
+sys.stdout.write(shlex.quote(body))