Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/rift/Controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ def make_parser():
help='Make Gerrit automatic review')
subprs.add_argument('--change', help="Gerrit Change-Id", required=True)
subprs.add_argument('--patchset', help="Gerrit patchset ID", required=True)
subprs.add_argument('-F', '--formats', nargs='+',
choices=RIFT_SUPPORTED_FORMATS,
help='restrict command to specific package formats')
subprs.add_argument('patch', metavar='PATCH', type=argparse.FileType('r'))

# sync
Expand Down Expand Up @@ -976,6 +979,14 @@ def action_gerrit(args, config, staff, modules):
if names[0] == config.get('packages_dir'):
pkgs = ProjectPackages.get(names[1], config, staff, modules)
for pkg in pkgs:
# Skip package if format is not selected by user
if args.formats and pkg.format not in args.formats:
logging.info(
"Skipping gerrit review on %s package %s due to "
"restriction on package formats",
pkg.format, pkg.name
)
continue
if (filepath == os.path.relpath(pkg.buildfile) and
not patchedfile.is_deleted_file):
pkg.load()
Expand Down
61 changes: 53 additions & 8 deletions tests/Controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2128,14 +2128,6 @@ class ControllerProjectActionGerritTest(RiftProjectTestCase):
Tests class for Controller action gerrit
"""

def test_gerrit_missing_patch_change_patchset(self):
"""gerrit without patch, change or patchset fails"""
for cmd in (['gerrit', '--change', '1', '--patchset', '2'],
['gerrit', '--patchset', '2', '/dev/null'],
['gerrit', '--change', '1', '/dev/null']):
with self.assertRaisesRegex(SystemExit, "2"):
main(cmd)

@patch('rift.package.rpm.Mock')
@patch('rift.Controller.Review')
def test_gerrit(self, mock_review, mock_mock):
Expand Down Expand Up @@ -2164,6 +2156,35 @@ def test_gerrit(self, mock_review, mock_mock):
mock_review.return_value.invalidate.assert_not_called()
mock_review.return_value.push.assert_called_once()

@patch('rift.package.rpm.Mock')
@patch('rift.Controller.Review')
def test_gerrit_formats(self, mock_review, mock_mock):
"""gerrit with formats restriction"""
self.make_pkg()
patch_file = make_temp_file(
textwrap.dedent("""
diff --git a/packages/pkg/pkg.spec b/packages/pkg/pkg.spec
index d1a0d0e7..b3e36379 100644
--- a/packages/pkg/pkg.spec
+++ b/packages/pkg/pkg.spec
@@ -1,6 +1,6 @@
Name: pkg
Version: 1.0
-Release: 1
+Release: 2
Summary: A package
Group: System Environment/Base
License: GPL
"""))
# mock Mock.read_spec to return spec file content directly read on host
mock_mock.return_value.read_spec = read_file
with patch.object(mock_mock.return_value, 'rpmlint', host_rpmlint):
main(['gerrit', '--change', '1', '--patchset', '2', patch_file.name,
'--formats', 'rpm'])
# Check review has not been invalidated and pushed
mock_review.return_value.invalidate.assert_not_called()
mock_review.return_value.push.assert_called_once()

@patch('rift.package.rpm.Mock')
@patch('rift.Controller.Review')
def test_gerrit_review_invalidated(self, mock_review, mock_mock):
Expand Down Expand Up @@ -2374,6 +2395,30 @@ def test_parse_args_changelog(self):
with self.assertRaises(SystemExit):
opts = parser.parse_args(args)

def test_parse_args_gerrit(self):
""" Test gerrit command options parsing """
parser = make_parser()

for args in (['gerrit', '--change', '1', '--patchset', '2'],
['gerrit', '--patchset', '2', '/dev/null'],
['gerrit', '--change', '1', '/dev/null']):
with self.assertRaisesRegex(SystemExit, "2"):
opts = parser.parse_args(args)

args = ['gerrit', '--change', '1', '--patchset', '2', '/dev/null']
opts = parser.parse_args(args)
self.assertIsNone(opts.formats)

args = ['gerrit', '--change', '1', '--patchset', '2', '/dev/null',
'--formats', 'rpm']
opts = parser.parse_args(args)
self.assertCountEqual(opts.formats, ['rpm'])

args = ['gerrit', '--change', '1', '--patchset', '2', '/dev/null',
'--formats', 'fail']
with self.assertRaises(SystemExit):
opts = parser.parse_args(args)

def test_make_parser_vm(self):
""" Test vm command options parsing """
parser = make_parser()
Expand Down
Loading