summaryrefslogtreecommitdiff
path: root/zuul/merger
diff options
context:
space:
mode:
authorJames E. Blair <jim@acmegating.com>2022-10-17 14:27:05 -0700
committerJames E. Blair <jim@acmegating.com>2022-10-17 14:27:05 -0700
commit26b9b0e2fb167e27f1ba74f0d3a6542f37c69d55 (patch)
tree530f0ac0df3918b8d708fdfb924322141c04ec62 /zuul/merger
parente2a472bc9708c8f7b222b43a75540d64bef77d82 (diff)
downloadzuul-26b9b0e2fb167e27f1ba74f0d3a6542f37c69d55.tar.gz
Add rebase-merge merge mode
GitHub supports a "rebase" merge mode where it will rebase the PR onto the target branch and fast-forward the target branch to the result of the rebase. Add support for this process to the merger so that it can prepare an effective simulated repo, and map the merge-mode to the merge operation in the reporter so that gating behavior matches. This change also makes a few tweaks to the merger to improve consistency (including renaming a variable ref->base), and corrects some typos in the similar squash merge test methods. Change-Id: I9db1d163bafda38204360648bb6781800d2a09b4
Diffstat (limited to 'zuul/merger')
-rw-r--r--zuul/merger/merger.py24
1 files changed, 19 insertions, 5 deletions
diff --git a/zuul/merger/merger.py b/zuul/merger/merger.py
index 34b495fcc..09968eac6 100644
--- a/zuul/merger/merger.py
+++ b/zuul/merger/merger.py
@@ -582,7 +582,7 @@ class Repo(object):
repo.git.merge(*args)
return repo.head.commit
- def squash_merge(self, item, zuul_event_id=None):
+ def squashMerge(self, item, zuul_event_id=None):
log = get_annotated_logger(self.log, zuul_event_id)
repo = self.createRepoObject(zuul_event_id)
args = ['--squash', 'FETCH_HEAD']
@@ -594,6 +594,17 @@ class Repo(object):
'Merge change %s,%s' % (item['number'], item['patchset']))
return repo.head.commit
+ def rebaseMerge(self, item, base, zuul_event_id=None):
+ log = get_annotated_logger(self.log, zuul_event_id)
+ repo = self.createRepoObject(zuul_event_id)
+ args = [base]
+ ref = item['ref']
+ self.fetch(ref, zuul_event_id=zuul_event_id)
+ log.debug("Rebasing %s with args %s", ref, args)
+ repo.git.checkout('FETCH_HEAD')
+ repo.git.rebase(*args)
+ return repo.head.commit
+
def fetch(self, ref, zuul_event_id=None):
repo = self.createRepoObject(zuul_event_id)
# NOTE: The following is currently not applicable, but if we
@@ -1029,14 +1040,14 @@ class Merger(object):
for message in messages:
ref_log.debug(message)
- def _mergeChange(self, item, ref, zuul_event_id):
+ def _mergeChange(self, item, base, zuul_event_id):
log = get_annotated_logger(self.log, zuul_event_id)
repo = self.getRepo(item['connection'], item['project'],
zuul_event_id=zuul_event_id)
try:
- repo.checkout(ref, zuul_event_id=zuul_event_id)
+ repo.checkout(base, zuul_event_id=zuul_event_id)
except Exception:
- log.exception("Unable to checkout %s", ref)
+ log.exception("Unable to checkout %s", base)
return None, None
try:
@@ -1050,8 +1061,11 @@ class Merger(object):
commit = repo.cherryPick(item['ref'],
zuul_event_id=zuul_event_id)
elif mode == zuul.model.MERGER_SQUASH_MERGE:
- commit = repo.squash_merge(
+ commit = repo.squashMerge(
item, zuul_event_id=zuul_event_id)
+ elif mode == zuul.model.MERGER_REBASE:
+ commit = repo.rebaseMerge(
+ item, base, zuul_event_id=zuul_event_id)
else:
raise Exception("Unsupported merge mode: %s" % mode)
except git.GitCommandError: