Skip to content

Commit

Permalink
Make GerritStatusPush also work with GitPoller source
Browse files Browse the repository at this point in the history
It would previously work with GerritChangeSource and
GerritEventLogPoller only. But using events from these Gerrit specific
changesources can be problematic for some users, and so we support
GitPoller as well.

Reviews are sent back to the Gerrit server for builds with refspecs
matching: refs/changes/n/n/n
  • Loading branch information
muks committed Mar 28, 2021
1 parent 9e07314 commit 98db812
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
11 changes: 11 additions & 0 deletions master/buildbot/reporters/gerrit.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
Push events to Gerrit
"""

import re
import time
import warnings
from pkg_resources import parse_version
Expand Down Expand Up @@ -419,6 +420,16 @@ def getProperty(build, name):
self.sendCodeReview(project, revision, result)
return

# Gerrit + GitPoller (when configured with project argument)
build_refspec_re = r'^refs/changes/(\d+)/(\d+)/(\d+)$'
build_branch = getProperty(build, 'branch')
build_project = getProperty(build, 'project')
match = re.search(build_refspec_re, build_branch)
if match and len(build_project) > 0:
revision = '%s,%s' % (match.group(2), match.group(3))
self.sendCodeReview(build_project, revision, result)
return

def sendCodeReview(self, project, revision, result):
gerrit_version = self.getCachedVersion()
if gerrit_version is None:
Expand Down
27 changes: 27 additions & 0 deletions master/docs/manual/configuration/reporters/gerrit_status.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,30 @@ GerritStatusPush can send a separate review for each build that completes, or a
.. seealso::

:src:`master/docs/examples/git_gerrit.cfg` and :src:`master/docs/examples/repo_gerrit.cfg` in the Buildbot distribution provide a full example setup of Git+Gerrit or Repo+Gerrit of :bb:reporter:`GerritStatusPush`.

:class:`GerritStatusPush` is usually used with either :class:`GerritChangeSource` or :class:`GerritEventLogPoller`. But it can also work with a :class:`GitPoller` (when it is configured with the `project` argument). For example, with a :class:`GitPoller` configured as follows, reviews are sent back to the Gerrit server by :class:`GerritStatusPush` for refspecs maching the `refs/changes/n/n/n` syntax:

.. code-block:: python
def accept_branch(refspec):
# Allow the following forms:
# refs/heads/main
# refs/heads/master
# refs/heads/1.2
branch_re=r'^refs/heads/(main|master|\d+\.\d+)$'
if re.search(branch_re, refspec):
return True
# Allow the following forms:
# refs/changes/81/281/2
branch_re=r'^refs/changes/\d+/\d+/\d+$'
if re.search(branch_re, refspec):
return True
return False
cs = changes.GitPoller(
'git+ssh://[email protected]:29418/myproject',
project='myproject',
branches=accept_branch)
c['change_source'].append(cs)

0 comments on commit 98db812

Please sign in to comment.