summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Westphahl <simon.westphahl@bmw.de>2023-03-03 08:49:18 +0100
committerSimon Westphahl <simon.westphahl@bmw.de>2023-03-03 10:54:58 +0100
commitb372575b62158b89ef608c8a556f433f15c3375a (patch)
tree5fbbc46c4d7d11146fb32c7806d318034396f944
parent36e81916f0b3b560ad672f2100daec25c56e3f94 (diff)
downloadzuul-b372575b62158b89ef608c8a556f433f15c3375a.tar.gz
Truncate Github file annotation message to 64 KB
File annotations that are posted to a PR as part of a check run have a size limit of 64KB for the message field. Since it's unclear if this should be 64KiB or 64KB, we'll use KB as a unit to be on the safe side. Change-Id: I43e4cfbc3a96bf1e8a9828c55150216940a64728
-rw-r--r--zuul/driver/github/githubconnection.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/zuul/driver/github/githubconnection.py b/zuul/driver/github/githubconnection.py
index 182c83bae..b5a7800c0 100644
--- a/zuul/driver/github/githubconnection.py
+++ b/zuul/driver/github/githubconnection.py
@@ -81,6 +81,10 @@ ANNOTATION_LEVELS = {
"warning": "warning",
"error": "failure",
}
+# The maximum size for the 'message' field is 64 KB. Since it's unclear
+# from the Github docs if the unit is KiB or KB we'll use KB to be on
+# the safe side.
+ANNOTATION_MAX_MESSAGE_SIZE = 64 * 1000
EventTuple = collections.namedtuple(
"EventTuple", [
@@ -2428,7 +2432,9 @@ class GithubConnection(ZKChangeCacheMixin, ZKBranchCacheMixin, BaseConnection):
raw_annotation = {
"path": fn,
"annotation_level": annotation_level,
- "message": comment["message"],
+ "message": comment["message"].encode(
+ "utf8")[:ANNOTATION_MAX_MESSAGE_SIZE].decode(
+ "utf8", "ignore"),
"start_line": start_line,
"end_line": end_line,
"start_column": start_column,