Repository: buildbot/buildbot

Issue:
GerritEventLogPoller
Support for the events-log gerrit plugin

This is a first PR.

The second PR should be a GerritEventLogChangeSource, which should combine ssh and eventlog REST API to be sure not to miss events in case of ssh disconnection.
Multiple inheritence should make that pretty trivial.

A third PR will be the GerritKafkaChangeSource which will connect to a kafka server


Discussion:

Resolving patch:
diff --git a/master/buildbot/steps/source/git.py b/master/buildbot/steps/source/git.py
--- a/master/buildbot/steps/source/git.py
+++ b/master/buildbot/steps/source/git.py
@@ -15,6 +15,7 @@
 
 from twisted.python import log
 from twisted.internet import defer, reactor
+from distutils.version import StrictVersion
 
 from buildbot import config as bbconfig
 from buildbot.process import buildstep
@@ -118,6 +119,7 @@ def __init__(self, repourl=None, branch='HEAD', mode='incremental', method=None,
         self.mode = mode
         self.getDescription = getDescription
         self.config = config
+        self.supportsBranch = True
         Source.__init__(self, **kwargs)
 
         if self.mode not in ['incremental', 'full']:
@@ -138,8 +140,7 @@ def startVC(self, branch, revision, patch):
         self.method = self._getMethod()
         self.stdio_log = self.addLogForRemoteCommands("stdio")
 
-
-        d = self.checkGit()
+        d = self.checkBranchSupport()
         def checkInstall(gitInstalled):
             if not gitInstalled:
                 raise BuildSlaveTooOldError("git is not installed on slave")
@@ -389,7 +390,7 @@ def _clone(self, shallowClone):
         """Retry if clone failed"""
 
         args = []
-        if self.branch != 'HEAD':
+        if self.supportsBranch and self.branch != 'HEAD':
             args += ['--branch', self.branch]
         if shallowClone:
             args += ['--depth', '1']
@@ -504,12 +505,15 @@ def _getMethod(self):
         elif self.method is None and self.mode == 'full':
             return 'fresh'
 
-    def checkGit(self):
-        d = self._dovccmd(['--version'])
-        def check(res):
-            if res == 0:
-                return True
-            return False
-
-        d.addCallback(check)
+    def checkBranchSupport(self):
+        d = self._dovccmd(['--version'], collectStdout=True)
+        def checkSupport(stdout):
+            gitInstalled = False
+            if 'git' in stdout:
+                gitInstalled = True
+            version = stdout.strip().split(' ')[2]
+            if StrictVersion(version) < StrictVersion("1.6.5"):
+                self.supportsBranch = False
+            return gitInstalled
+        d.addCallback(checkSupport)
         return d


Test patch:
diff --git a/master/buildbot/test/unit/test_steps_source_git.py b/master/buildbot/test/unit/test_steps_source_git.py
--- a/master/buildbot/test/unit/test_steps_source_git.py
+++ b/master/buildbot/test/unit/test_steps_source_git.py
@@ -36,6 +36,8 @@ def test_mode_full_clean(self):
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -72,6 +74,8 @@ def test_mode_full_clean_win32path(self):
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir\.buildbot-patched',
                                 logEnviron=True))
@@ -109,6 +113,8 @@ def test_mode_full_clean_timeout(self):
             ExpectShell(workdir='wkdir',
                         timeout=1,
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -149,6 +155,8 @@ def test_mode_full_clean_patch(self):
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -206,6 +214,8 @@ def test_mode_full_clean_patch_fail(self):
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -250,6 +260,8 @@ def test_mode_full_clean_branch(self):
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -288,6 +300,8 @@ def test_mode_full_clean_parsefail(self):
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -322,6 +336,8 @@ def test_mode_full_clean_no_existing_repo(self):
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -349,6 +365,8 @@ def test_mode_full_clean_no_existing_repo_with_reference(self):
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -376,6 +394,8 @@ def test_mode_full_clean_no_existing_repo_branch(self):
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -405,6 +425,8 @@ def test_mode_full_clobber(self):
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -436,6 +458,8 @@ def test_mode_full_clobber_branch(self):
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -460,6 +484,39 @@ def test_mode_full_clobber_branch(self):
         self.expectProperty('got_revision', 'f6ad368298bd941e934a41f3babc827b2aa95a1d', 'Git')
         return self.runStep()
 
+    def test_mode_full_clobber_no_branch_support(self):
+        self.setupStep(
+                git.Git(repourl='http://github.com/buildbot/buildbot.git',
+                        mode='full', method='clobber', progress=True, branch='test-branch'))
+
+        self.expectCommands(
+            ExpectShell(workdir='wkdir',
+                        command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.5.5')
+            + 0,
+            Expect('stat', dict(file='wkdir/.buildbot-patched',
+                                logEnviron=True))
+            + 1,
+            Expect('rmdir', dict(dir='wkdir',
+                                       logEnviron=True,
+                                       timeout=1200))
+            + 0,
+            ExpectShell(workdir='wkdir',
+                        command=['git', 'clone',
+                                 'http://github.com/buildbot/buildbot.git',
+                                 '.', '--progress'])
+            + 0,
+            ExpectShell(workdir='wkdir',
+                        command=['git', 'rev-parse', 'HEAD'])
+            + ExpectShell.log('stdio',
+                stdout='f6ad368298bd941e934a41f3babc827b2aa95a1d')
+            + 0,
+        )
+        self.expectOutcome(result=SUCCESS, status_text=["update"])
+        self.expectProperty('got_revision', 'f6ad368298bd941e934a41f3babc827b2aa95a1d', 'Git')
+        return self.runStep()
+
     def test_mode_incremental(self):
         self.setupStep(
                 git.Git(repourl='http://github.com/buildbot/buildbot.git',
@@ -467,6 +524,8 @@ def test_mode_incremental(self):
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -500,6 +559,8 @@ def test_mode_incremental_retry(self):
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -538,6 +599,8 @@ def test_mode_incremental_branch(self):
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -574,6 +637,8 @@ def test_mode_full_fresh(self):
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -611,6 +676,8 @@ def test_mode_incremental_given_revision(self):
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -641,6 +708,8 @@ def test_mode_full_fresh_submodule(self):
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -684,6 +753,8 @@ def test_mode_full_clobber_shallow(self):
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -715,6 +786,8 @@ def test_mode_full_clobber_no_shallow(self):
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -746,6 +819,8 @@ def test_mode_incremental_retryFetch(self):
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -787,6 +862,8 @@ def test_mode_incremental_retryFetch_branch(self):
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -831,6 +908,8 @@ def test_mode_incremental_clobberOnFailure(self):
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -873,6 +952,8 @@ def test_mode_incremental_clobberOnFailure_branch(self):
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -916,6 +997,8 @@ def test_mode_full_copy(self):
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -959,6 +1042,8 @@ def test_mode_incremental_no_existing_repo(self):
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -990,6 +1075,8 @@ def test_mode_full_clobber_given_revision(self):
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -1025,6 +1112,8 @@ def test_revparse_failure(self):
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -1059,6 +1148,8 @@ def test_mode_full_clobber_submodule(self):
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -1098,6 +1189,8 @@ def test_mode_full_fresh_revision(self):
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -1130,6 +1223,8 @@ def test_mode_full_fresh_retry(self):
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -1177,6 +1272,8 @@ def test_mode_full_fresh_clobberOnFailure(self):
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -1214,6 +1311,8 @@ def test_mode_full_no_method(self):
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -1250,6 +1349,8 @@ def test_mode_full_with_env(self):
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'],
                         env={'abc': '123'})
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -1290,6 +1391,8 @@ def test_mode_full_logEnviron(self):
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'],
                         logEnviron=False)
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=False))
@@ -1334,6 +1437,8 @@ def test_getDescription(self):
             ## copied from test_mode_incremental:
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -1382,6 +1487,8 @@ def test_getDescription_failed(self):
             ## copied from test_mode_incremental:
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -1433,6 +1540,8 @@ def setup_getDescription_test(self, setup_args, output_args, codebase=None):
             ## copied from test_mode_full_clobber:
             ExpectShell(workdir='wkdir',
                         command=['git', '--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))
@@ -1674,6 +1783,8 @@ def test_config_option(self):
         self.expectCommands(
             ExpectShell(workdir='wkdir',
                         command=prefix + ['--version'])
+            + ExpectShell.log('stdio',
+                stdout='git version 1.7.5')
             + 0,
             Expect('stat', dict(file='wkdir/.buildbot-patched',
                                 logEnviron=True))