Skip to content

Commit

Permalink
Merge branch 'bug2485-squash' of git://github.com/srinupiits/buildbot
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche committed Aug 1, 2013
2 parents 3152107 + 5a2b8ee commit e4e40a2
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 0 deletions.
39 changes: 39 additions & 0 deletions master/buildbot/steps/source/gerrit.py
@@ -0,0 +1,39 @@
# This file is part of Buildbot. Buildbot is free software: you can
# redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright Buildbot Team Members

from buildbot.steps.source.git import Git

class Gerrit(Git):
def __init__(self, **kwargs):
Git.__init__(self, **kwargs)


def startVC(self, branch, revision, patch):
gerrit_branch = None
if self.build.hasProperty("event.patchSet.ref"):
gerrit_branch = self.build.getProperty("event.patchSet.ref")
self.updateSourceProperty("gerrit_branch", gerrit_branch)
else:
try:
change = self.build.getProperty("gerrit_change", '').split('/')
if len(change) == 2:
gerrit_branch = "refs/changes/%2.2d/%d/%d" \
% (int(change[0]) % 100, int(change[0]), int(change[1]))
self.updateSourceProperty("gerrit_branch", gerrit_branch)
except:
pass

branch = gerrit_branch or branch
super(Gerrit, self).startVC(gerrit_branch, revision, patch)
108 changes: 108 additions & 0 deletions master/buildbot/test/unit/test_steps_source_gerrit.py
@@ -0,0 +1,108 @@
# This file is part of Buildbot. Buildbot is free software: you can
# redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright Buildbot Team Members

from twisted.trial import unittest
from buildbot.steps.source import gerrit
from buildbot.status.results import SUCCESS, FAILURE
from buildbot.test.util import config, sourcesteps
from buildbot.test.fake.remotecommand import ExpectRemoteRef, ExpectShell, Expect

class TestGerrit(sourcesteps.SourceStepMixin, config.ConfigErrorsMixin, unittest.TestCase):

def setUp(self):
return self.setUpSourceStep()

def tearDown(self):
return self.tearDownSourceStep()

def test_mode_full_clean(self):
self.setupStep(
gerrit.Gerrit(repourl='http://github.com/buildbot/buildbot.git',
mode='full', method='clean'))
self.build.setProperty("event.patchSet.ref", "gerrit_branch")

self.expectCommands(
ExpectShell(workdir='wkdir',
command=['git', '--version'])
+ 0,
Expect('stat', dict(file='wkdir/.buildbot-patched',
logEnviron=True))
+ 1,
Expect('stat', dict(file='wkdir/.git',
logEnviron=True))
+ 0,
ExpectShell(workdir='wkdir',
command=['git', 'clean', '-f', '-d'])
+ 0,
ExpectShell(workdir='wkdir',
command=['git', 'fetch', '-t',
'http://github.com/buildbot/buildbot.git',
'gerrit_branch'])
+ 0,
ExpectShell(workdir='wkdir',
command=['git', 'reset', '--hard', 'FETCH_HEAD', '--'])
+ 0,
ExpectShell(workdir='wkdir',
command=['git', 'branch', '-M', 'gerrit_branch'])
+ 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', 'Gerrit')
return self.runStep()

def test_mode_full_clean_force_build(self):
self.setupStep(
gerrit.Gerrit(repourl='http://github.com/buildbot/buildbot.git',
mode='full', method='clean'))
self.build.setProperty("gerrit_change", "1234/567")

self.expectCommands(
ExpectShell(workdir='wkdir',
command=['git', '--version'])
+ 0,
Expect('stat', dict(file='wkdir/.buildbot-patched',
logEnviron=True))
+ 1,
Expect('stat', dict(file='wkdir/.git',
logEnviron=True))
+ 0,
ExpectShell(workdir='wkdir',
command=['git', 'clean', '-f', '-d'])
+ 0,
ExpectShell(workdir='wkdir',
command=['git', 'fetch', '-t',
'http://github.com/buildbot/buildbot.git',
'refs/changes/34/1234/567'])
+ 0,
ExpectShell(workdir='wkdir',
command=['git', 'reset', '--hard', 'FETCH_HEAD', '--'])
+ 0,
ExpectShell(workdir='wkdir',
command=['git', 'branch', '-M', 'refs/changes/34/1234/567'])
+ 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', 'Gerrit')
return self.runStep()
17 changes: 17 additions & 0 deletions master/docs/manual/cfg-buildsteps.rst
Expand Up @@ -847,6 +847,23 @@ This feature allows integrators to build with several pending interdependent cha
which at the moment cannot be described properly in Gerrit, and can only be described
by humans.

.. _Step-Gerrit:

Gerrit
++++++

.. py:class:: buildbot.steps.source.gerrit.Gerrit
This Source step is exactly like the :bb:step:`Git` checkout step , except that
it integrates with :bb:chsrc:`GerritChangeSource`, and will automatically checkout
the additional changes.

Gerrit integration can be also triggered using forced build with property named
``gerrit_change`` with values in format ``change_number/patchset_number``. This property
will be translated into a branch name. This feature allows integrators to build with
several pending interdependent changes, which at the moment cannot be described properly
in Gerrit, and can only be described by humans.

.. _Source-Checkout-Slave-Side:

Source Checkout (Slave-Side)
Expand Down
2 changes: 2 additions & 0 deletions master/docs/relnotes/index.rst
Expand Up @@ -64,6 +64,8 @@ Features

* The SVN step now obfuscates the password in status logs, fixing :bb:bug:`2468`.

* Gerrit integration with Git Source step on master side.

Deprecations, Removals, and Non-Compatible Changes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down

0 comments on commit e4e40a2

Please sign in to comment.