Move makemergeritem into model
This function appears twice since something like it is used by
both the merger and executor clients. Centralize it in the model.
Change-Id: I376a263ef28373c94da5bf0cce41f8f761915e18
diff --git a/zuul/executor/client.py b/zuul/executor/client.py
index 55f6874..dc50617 100644
--- a/zuul/executor/client.py
+++ b/zuul/executor/client.py
@@ -24,45 +24,6 @@
from zuul.model import Build
-def make_merger_item(item):
- # Create a dictionary with all info about the item needed by
- # the merger.
- number = None
- patchset = None
- oldrev = None
- newrev = None
- refspec = None
- if hasattr(item.change, 'number'):
- number = item.change.number
- patchset = item.change.patchset
- refspec = item.change.refspec
- branch = item.change.branch
- elif hasattr(item.change, 'newrev'):
- oldrev = item.change.oldrev
- newrev = item.change.newrev
- branch = item.change.ref
- else:
- oldrev = None
- newrev = None
- branch = None
- source = item.change.project.source
- connection_name = source.connection.connection_name
- project = item.change.project.name
-
- return dict(project=project,
- url=source.getGitUrl(item.change.project),
- connection_name=connection_name,
- merge_mode=item.current_build_set.getMergeMode(),
- refspec=refspec,
- branch=branch,
- ref=item.current_build_set.ref,
- number=number,
- patchset=patchset,
- oldrev=oldrev,
- newrev=newrev,
- )
-
-
class GearmanCleanup(threading.Thread):
""" A thread that checks to see if outstanding builds have
completed without reporting back. """
@@ -288,7 +249,7 @@
# ZUUL_NEWREV
all_items = dependent_items + [item]
- merger_items = map(make_merger_item, all_items)
+ merger_items = [i.makeMergerItem() for i in all_items]
params['job'] = job.name
params['timeout'] = job.timeout
diff --git a/zuul/manager/__init__.py b/zuul/manager/__init__.py
index 3a4ea6a..bdfde48 100644
--- a/zuul/manager/__init__.py
+++ b/zuul/manager/__init__.py
@@ -437,40 +437,6 @@
canceled = True
return canceled
- def _makeMergerItem(self, item):
- # Create a dictionary with all info about the item needed by
- # the merger.
- number = None
- patchset = None
- refspec = None
- branch = None
- oldrev = None
- newrev = None
- if hasattr(item.change, 'number'):
- number = item.change.number
- patchset = item.change.patchset
- refspec = item.change.refspec
- branch = item.change.branch
- elif hasattr(item.change, 'newrev'):
- oldrev = item.change.oldrev
- newrev = item.change.newrev
- source = item.change.project.source
- connection_name = source.connection.connection_name
-
- project = item.change.project.name
- return dict(project=project,
- url=source.getGitUrl(item.change.project),
- connection_name=connection_name,
- merge_mode=item.current_build_set.getMergeMode(),
- refspec=refspec,
- branch=branch,
- ref=item.current_build_set.ref,
- number=number,
- patchset=patchset,
- oldrev=oldrev,
- newrev=newrev,
- )
-
def _loadDynamicLayout(self, item):
# Load layout
# Late import to break an import loop
@@ -539,7 +505,7 @@
dependent_items = self.getDependentItems(item)
dependent_items.reverse()
all_items = dependent_items + [item]
- merger_items = map(self._makeMergerItem, all_items)
+ merger_items = [i.makeMergerItem() for i in all_items]
build_set = item.current_build_set
build_set.merge_state = build_set.PENDING
self.sched.merger.mergeChanges(merger_items,
diff --git a/zuul/model.py b/zuul/model.py
index 4880be1..ce552b4 100644
--- a/zuul/model.py
+++ b/zuul/model.py
@@ -1690,6 +1690,44 @@
ret += '\n'
return ret
+ def makeMergerItem(self):
+ # Create a dictionary with all info about the item needed by
+ # the merger.
+ number = None
+ patchset = None
+ oldrev = None
+ newrev = None
+ refspec = None
+ if hasattr(self.change, 'number'):
+ number = self.change.number
+ patchset = self.change.patchset
+ refspec = self.change.refspec
+ branch = self.change.branch
+ elif hasattr(self.change, 'newrev'):
+ oldrev = self.change.oldrev
+ newrev = self.change.newrev
+ branch = self.change.ref
+ else:
+ oldrev = None
+ newrev = None
+ branch = None
+ source = self.change.project.source
+ connection_name = source.connection.connection_name
+ project = self.change.project.name
+
+ return dict(project=project,
+ url=source.getGitUrl(self.change.project),
+ connection_name=connection_name,
+ merge_mode=self.current_build_set.getMergeMode(),
+ refspec=refspec,
+ branch=branch,
+ ref=self.current_build_set.ref,
+ number=number,
+ patchset=patchset,
+ oldrev=oldrev,
+ newrev=newrev,
+ )
+
class Ref(object):
"""An existing state of a Project."""