Skip to content
Snippets Groups Projects
Commit 2a8755d0 authored by Marco Clemencic's avatar Marco Clemencic
Browse files

Prefetch all MRs of each project, then filter

parent acaa28fd
No related branches found
No related tags found
No related merge requests found
......@@ -65,24 +65,26 @@ def getMRCommit(project_id, mr_iid):
@cached
def _getAllProjectMRs(project_id):
return _getGitlabProject(project_id).mergerequests.list(
state='opened', all=True)
def getMergeRequests(project_id, labels=None, wip=None, target_branch=None):
from gitlab import GitlabGetError
wip_condition = (lambda _: True) if wip is None else (
lambda mr: mr.work_in_progress == wip)
label_condition = (lambda _: True) if not labels else ()
if labels:
labels = set(labels)
label_condition = lambda (mr): labels.intersection(mr.labels)
else:
label_condition = lambda _: True
condition = lambda mr: (mr.target_branch == target_branch and wip_condition(mr) and label_condition(mr))
try:
project = _getGitlabProject(project_id)
return sorted((mr.iid, getMRCommit(project_id, mr.iid))
for mr in project.mergerequests.list(
state='opened',
all=True,
target_branch=target_branch,
labels=labels,
wip={
True: 'yes',
False: 'no'
}.get(wip, wip)))
except (ImportError, KeyError):
pass
for mr in _getAllProjectMRs(project_id) if condition(mr))
except GitlabGetError:
_logger.warning('problem getting MRs for %s', project_id)
return []
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment