Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 34 additions & 29 deletions lib/rift/Controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,38 @@ def action_sync(args, config):
)
synchronizer.run()

def action_changelog(args, config):
"""Action for 'changelog' command."""
staff, modules = staff_modules(config)
if args.maintainer is None:
raise RiftError("You must specify a maintainer")

pkg = Package(args.package, config, staff, modules)
pkg.load()

author = f"{args.maintainer} <{staff.get(args.maintainer)['email']}>"

# Format comment.
# Grab bullet, insert one if not found.
bullet = "-"
match = re.search(r'^([^\s\w])\s', args.comment, re.UNICODE)
if match:
bullet = match.group(1)
else:
args.comment = bullet + " " + args.comment

if args.comment.find("\n") == -1:
wrapopts = {"subsequent_indent": (len(bullet) + 1) * " ",
"break_long_words": False,
"break_on_hyphens": False}
args.comment = textwrap.fill(args.comment, 80, **wrapopts)

logging.info("Adding changelog record for '%s'", author)
Spec(pkg.specfile,
config=config).add_changelog_entry(author, args.comment,
bump=getattr(args, 'bump', False))
return 0

def create_staging_repo(config):
"""
Create and return staging temporary repository with a 2-tuple containing
Expand Down Expand Up @@ -1154,36 +1186,9 @@ def action(config, args):
'maintainers': ', '.join(pkg.maintainers)})
print(tbl)

# CHANGELOG
elif args.command == 'changelog':

staff, modules = staff_modules(config)
if args.maintainer is None:
raise RiftError("You must specify a maintainer")

pkg = Package(args.package, config, staff, modules)
pkg.load()

author = f"{args.maintainer} <{staff.get(args.maintainer)['email']}>"

# Format comment.
# Grab bullet, insert one if not found.
bullet = "-"
match = re.search(r'^([^\s\w])\s', args.comment, re.UNICODE)
if match:
bullet = match.group(1)
else:
args.comment = bullet + " " + args.comment

if args.comment.find("\n") == -1:
wrapopts = {"subsequent_indent": (len(bullet) + 1) * " ",
"break_long_words": False,
"break_on_hyphens": False}
args.comment = textwrap.fill(args.comment, 80, **wrapopts)

logging.info("Adding changelog record for '%s'", author)
Spec(pkg.specfile,
config=config).add_changelog_entry(author, args.comment,
bump=getattr(args, 'bump', False))
return action_changelog(args, config)

# GERRIT
elif args.command == 'gerrit':
Expand Down
59 changes: 58 additions & 1 deletion tests/Controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
make_parser,
)
from rift.Package import Package
from rift.RPM import RPM
from rift.RPM import RPM, Spec
from rift.run import RunResult
from rift import RiftError

Expand Down Expand Up @@ -653,6 +653,63 @@ def test_action_sync_missing_output_parent(self):
main(['sync'])


class ControllerProjectActionChangelogTest(RiftProjectTestCase):
"""
Tests class for Controller action changelog
"""

def test_action_changelog_without_pkg(self):
"""changelog without package fails """
with self.assertRaisesRegex(SystemExit, "2"):
main(['changelog'])

def test_action_changelog_without_comment(self):
"""changelog without comment fails """
with self.assertRaisesRegex(SystemExit, "2"):
main(['changelog', 'pkg'])

def test_action_changelog_without_maintainer(self):
"""changelog without maintainer """
with self.assertRaisesRegex(RiftError, "You must specify a maintainer"):
main(['changelog', 'pkg', '-c', 'basic change'])

def test_action_changelog_pkg_not_found(self):
"""changelog package not found"""
with self.assertRaisesRegex(
RiftError,
"Package 'pkg' directory does not exist"):
main(['changelog', 'pkg', '-c', 'basic change', '-t', 'Myself'])

def test_action_changelog(self):
"""simple changelog"""
self.make_pkg()
self.assertEqual(
main(['changelog', 'pkg', '-c', 'basic change', '-t', 'Myself']), 0)
spec = Spec(filepath=self.pkgspecs['pkg'])
spec.load()
self.assertEqual(spec.changelog_name, 'Myself <[email protected]> - 1.0-1')
self.assertEqual(spec.version, '1.0')
self.assertEqual(spec.release, '1')

def test_action_changelog_bump(self):
"""simple changelog with bump"""
self.make_pkg()
self.assertEqual(
main(['changelog', 'pkg', '-c', 'basic change', '-t', 'Myself', '--bump']),
0)
spec = Spec(filepath=self.pkgspecs['pkg'])
spec.load()
self.assertEqual(spec.changelog_name, 'Myself <[email protected]> - 1.0-2')
self.assertEqual(spec.version, '1.0')
self.assertEqual(spec.release, '2')

def test_action_changelog_unknown_maintainer(self):
"""changelog with unknown maintainer"""
self.make_pkg()
with self.assertRaises(TypeError):
main(['changelog', 'pkg', '-c', 'basic change', '-t', 'Fail'])


class ControllerArgumentsTest(RiftTestCase):
""" Arguments parsing tests for Controller module"""

Expand Down