summaryrefslogtreecommitdiff
path: root/zuul/driver/github
diff options
context:
space:
mode:
authorTobias Henkel <tobias.henkel@bmw.de>2020-11-16 17:20:41 +0100
committerJames E. Blair <jim@acmegating.com>2021-03-15 15:49:24 -0700
commit808db0aec95c7376969d261b16b5bd25b74f7a8c (patch)
tree58e289070e3fd812fbe2aa11073afe8056867ebf /zuul/driver/github
parentab9e808def69a306253db71827ae8289f94e94be (diff)
downloadzuul-808db0aec95c7376969d261b16b5bd25b74f7a8c.tar.gz
Report max 50 file comments to github
The github api limits us to report 50 file comments per api request. Since the check run reporting is in the critical path don't do paging but limit this to 50 comments. In order to get a diverse feedback sort the messages by 'uniqueness' first so that 100 equal comments don't push out 5 other comments that are valuable. Change-Id: If5a7c246a58b510d8fcfa31bd71d74c84acbc278
Diffstat (limited to 'zuul/driver/github')
-rw-r--r--zuul/driver/github/githubconnection.py28
1 files changed, 26 insertions, 2 deletions
diff --git a/zuul/driver/github/githubconnection.py b/zuul/driver/github/githubconnection.py
index 2d1db034c..c7943fa6b 100644
--- a/zuul/driver/github/githubconnection.py
+++ b/zuul/driver/github/githubconnection.py
@@ -22,7 +22,8 @@ import queue
import threading
import time
import json
-from collections import OrderedDict
+from collections import OrderedDict, defaultdict
+from itertools import chain
from json.decoder import JSONDecodeError
from typing import List, Optional
@@ -2165,7 +2166,30 @@ class GithubConnection(CachedBranchConnection):
continue
annotations.append(annotation)
- return annotations
+
+ def _sortUniqueness(annotations):
+ """
+ This method is intended to spread the annotations by uniqueness
+ so we have an as diverse as possible list of annotations.
+ """
+ # First group
+ per_message = defaultdict(list)
+ for annotation in annotations:
+ per_message[annotation['message']].append(annotation)
+
+ # Sort the lists by length. This way we get the messages that
+ # occur less frequently at first.
+ annotation_lists = sorted(list(per_message.values()),
+ key=lambda l: len(l))
+
+ return list(chain(*annotation_lists))
+
+ if len(annotations) > 50:
+ # We cannot report more than 50 file comments so sort them by
+ # uniqueness in order to give the user a diverse set of annotations
+ annotations = _sortUniqueness(annotations)
+
+ return annotations[:50]
def getPushedFileNames(self, event):
files = set()