Push zuul-merged refs to gerrit.
Only merge changes if there is a refspec involved (not a ref-only change
like ref-updated). Also, only merge a change and launch jobs if a pipeline
actually supplies jobs for that change.
Add a test that ref-updated (eg, post) queues work.
Change-Id: Ic9d3089cc745aac21a6cf97a060a5181935abee9
Reviewed-on: https://review.openstack.org/11445
Reviewed-by: Clark Boylan <clark.boylan@gmail.com>
Approved: James E. Blair <corvus@inaugust.com>
Tested-by: Jenkins
diff --git a/zuul/merger.py b/zuul/merger.py
index 3efc98e..d058a56 100644
--- a/zuul/merger.py
+++ b/zuul/merger.py
@@ -65,11 +65,17 @@
def setZuulRef(self, ref, commit):
self.repo.refs[ref].commit = commit
+ def push(self, local, remote):
+ self.log.debug("Pushing %s:%s to %s " % (local, remote,
+ self.remote_url))
+ self.repo.remotes.origin.push('%s:%s' % (local, remote))
+
class Merger(object):
log = logging.getLogger("zuul.Merger")
- def __init__(self, working_root):
+ def __init__(self, trigger, working_root):
+ self.trigger = trigger
self.repos = {}
self.working_root = working_root
if not os.path.exists(working_root):
@@ -123,4 +129,19 @@
self.log.info("Unable to merge %s" % change)
return False
+ # Push the results upstream to the zuul ref
+ for project, branches in projects.items():
+ repo = self.getRepo(project)
+ for branch in branches:
+ ref = 'refs/zuul/' + branch + '/' + target_ref
+ try:
+ repo.push(ref, ref)
+ complete = self.trigger.waitForRefSha(project, ref)
+ except:
+ self.log.exception("Unable to push %s" % ref)
+ return False
+ if not complete:
+ self.log.error("Ref %s did not show up in repo" % ref)
+ return False
+
return True