Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make GerritStatusPush also work with GitPoller source #5956

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 matching 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)
1 change: 1 addition & 0 deletions master/docs/spelling_wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ refactoring
Refactoring
refactorings
refspec
refspecs
regex
regexp
regexps
Expand Down