Add strip_branch_ref compat option
This adds a compatability option to deal with a Gerrit behavior
change between 2.11 and 2.13.
Change-Id: I012485065e0fd8692e4f2ef787dd0a62be303314
diff --git a/doc/source/connections.rst b/doc/source/connections.rst
index 298100a..34b8f94 100644
--- a/doc/source/connections.rst
+++ b/doc/source/connections.rst
@@ -42,6 +42,13 @@
Optional: Keepalive timeout, 0 means no keepalive.
``keepalive=60``
+**strip_branch_ref**
+ Optional: Earlier versions of Gerrit reported branch refs in the
+ form "master" and later forms as "refs/heads/master". Set this to 1
+ to enable compatibility with the earlier form by stripping the
+ "refs/heads/" portion of the ref.
+ ``strip_branch_ref=1``
+
Gerrit Configuration
~~~~~~~~~~~~~~~~~~~~
diff --git a/zuul/connection/gerrit.py b/zuul/connection/gerrit.py
index c247700..a5b0e25 100644
--- a/zuul/connection/gerrit.py
+++ b/zuul/connection/gerrit.py
@@ -75,6 +75,9 @@
if refupdate:
event.project_name = refupdate.get('project')
event.ref = refupdate.get('refName')
+ if (self.connection.strip_branch_ref and
+ event.ref.startswith('refs/heads/')):
+ event.ref = event.ref[len('refs/heads/'):]
event.oldrev = refupdate.get('oldRev')
event.newrev = refupdate.get('newRev')
# Map the event types to a field name holding a Gerrit
@@ -231,6 +234,8 @@
self.port = int(self.connection_config.get('port', 29418))
self.keyfile = self.connection_config.get('sshkey', None)
self.keepalive = int(self.connection_config.get('keepalive', 60))
+ self.strip_branch_ref = bool(self.connection_config.get(
+ 'strip_branch_ref'))
self.watcher_thread = None
self.event_queue = None
self.client = None