From b372575b62158b89ef608c8a556f433f15c3375a Mon Sep 17 00:00:00 2001 From: Simon Westphahl Date: Fri, 3 Mar 2023 08:49:18 +0100 Subject: 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 --- zuul/driver/github/githubconnection.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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, -- cgit v1.2.1