Merge "Return resulting commits from merger" into feature/zuulv3
diff --git a/zuul/executor/server.py b/zuul/executor/server.py
index 72c042c..7cdff9c 100644
--- a/zuul/executor/server.py
+++ b/zuul/executor/server.py
@@ -629,7 +629,8 @@
if ret is None:
result['commit'] = result['files'] = result['repo_state'] = None
else:
- result['commit'], result['files'], result['repo_state'] = ret
+ (result['commit'], result['files'], result['repo_state'],
+ recent) = ret
job.sendWorkComplete(json.dumps(result))
@@ -790,6 +791,11 @@
result = dict(result='MERGER_FAILURE')
self.job.sendWorkComplete(json.dumps(result))
return False
+ recent = ret[3]
+ for key, commit in recent.items():
+ (connection, project, branch) = key
+ repo = merger.getRepo(connection, project)
+ repo.setRef('refs/heads/' + branch, commit)
return True
def runPlaybooks(self, args):
diff --git a/zuul/merger/merger.py b/zuul/merger/merger.py
index ee83fa0..bc57ca0 100644
--- a/zuul/merger/merger.py
+++ b/zuul/merger/merger.py
@@ -129,6 +129,14 @@
repo = self.createRepoObject()
return repo.refs
+ def setRef(self, path, hexsha, repo=None):
+ if repo is None:
+ repo = self.createRepoObject()
+ binsha = gitdb.util.to_bin_sha(hexsha)
+ obj = git.objects.Object.new_from_sha(repo, binsha)
+ self.log.debug("Create reference %s", path)
+ git.refs.Reference.create(repo, path, obj, force=True)
+
def setRefs(self, refs):
repo = self.createRepoObject()
current_refs = {}
@@ -136,10 +144,7 @@
current_refs[ref.path] = ref
unseen = set(current_refs.keys())
for path, hexsha in refs.items():
- binsha = gitdb.util.to_bin_sha(hexsha)
- obj = git.objects.Object.new_from_sha(repo, binsha)
- self.log.debug("Create reference %s", path)
- git.refs.Reference.create(repo, path, obj, force=True)
+ self.setRef(path, hexsha, repo)
unseen.discard(path)
for path in unseen:
self.log.debug("Delete reference %s", path)
@@ -439,7 +444,10 @@
project=item['project'],
branch=item['branch'],
files=repo_files))
- return commit.hexsha, read_files, repo_state
+ ret_recent = {}
+ for k, v in recent.items():
+ ret_recent[k] = v.hexsha
+ return commit.hexsha, read_files, repo_state, ret_recent
def getFiles(self, connection_name, project_name, branch, files):
repo = self.getRepo(connection_name, project_name)
diff --git a/zuul/merger/server.py b/zuul/merger/server.py
index 15f1a41..1a32f96 100644
--- a/zuul/merger/server.py
+++ b/zuul/merger/server.py
@@ -110,7 +110,8 @@
if ret is None:
result['commit'] = result['files'] = result['repo_state'] = None
else:
- result['commit'], result['files'], result['repo_state'] = ret
+ (result['commit'], result['files'], result['repo_state'],
+ recent) = ret
job.sendWorkComplete(json.dumps(result))
def cat(self, job):