diff --git a/conventions/changelog.py b/conventions/changelog.py index da9e411..42bbade 100644 --- a/conventions/changelog.py +++ b/conventions/changelog.py @@ -1,11 +1,12 @@ from os import system from utils import get_text -from utils import change_if_none +from utils import sanitize_as_empty_string +from utils import gen_co_author -def changelog_convention(co_author=''): +def changelog_convention(co_author): tag, msg = get_text() tag = tag.upper() - co_author = change_if_none(co_author) - composed_message = """%s: %s\n\nCo-authored-by: """ % (tag, msg) - system("git commit -m '%s%s'" % (composed_message, co_author)) + composed_message = "%s: %s\n" % (tag, msg) + composed_message += gen_co_author(co_author) + system("git commit -m '%s'" % composed_message) diff --git a/conventions/karma_angular.py b/conventions/karma_angular.py index 6dabb87..55260e4 100644 --- a/conventions/karma_angular.py +++ b/conventions/karma_angular.py @@ -1,12 +1,15 @@ from os import system from utils import get_text -from utils import change_if_none +from utils import sanitize_as_empty_string +from utils import gen_co_author -def angular_convention(co_author=''): +def angular_convention(co_author): tag, msg, context = get_text(context=True) tag = tag.lower() - co_author = change_if_none(co_author) - composed_message = """%s(%s): %s\n\nCo-authored-by: -""" % (tag, context, msg) - system('git commit -m "%s%s"' % (composed_message, co_author)) + co_author = sanitize_as_empty_string(co_author) + if context is '': + composed_message = composed_message = "%s: %s\n" % (tag, msg) + composed_message = "%s(%s): %s\n" % (tag, context, msg) + composed_message += gen_co_author(co_author) + system('git commit -m "%s"' % composed_message) diff --git a/conventions/no_convention.py b/conventions/no_convention.py index 9109933..6b45a23 100644 --- a/conventions/no_convention.py +++ b/conventions/no_convention.py @@ -1,9 +1,10 @@ from os import system -from utils import change_if_none +from utils import sanitize_as_empty_string +from utils import gen_co_author -def just_message(co_author=''): +def just_message(co_author): msg = str(input("commit message: ")) - co_author = change_if_none(co_author) - composed = """%s\n\nCo-authored-by: """ % msg.capitalize() - system("git commit -m '%s%s'" % (composed, co_author)) + composed = "%s\n" % msg.capitalize() + composed += gen_co_author(co_author) + system("git commit -m '%s'" % composed) diff --git a/conventions/symphony_cmf.py b/conventions/symphony_cmf.py index ed4a4f7..f6bd76e 100644 --- a/conventions/symphony_cmf.py +++ b/conventions/symphony_cmf.py @@ -1,11 +1,12 @@ from os import system from utils import get_text -from utils import change_if_none +from utils import sanitize_as_empty_string +from utils import gen_co_author -def symphony_convention(co_author=''): +def symphony_convention(co_author): tag, msg = get_text() tag = tag.capitalize() - co_author = change_if_none(co_author) - composed = """[%s] %s\n\nCo-authored-by: """ % (tag, msg) - system("git commit -m '%s%s'" % (composed, co_author)) + composed = "[%s] %s\n" % (tag, msg) + composed += gen_co_author(co_author) + system("git commit -m '%s'" % composed) diff --git a/test/test_utils.py b/test/test_utils.py index d48075f..634b5c1 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -37,14 +37,24 @@ def mock_input(s): raise AssertionError() -def test_change_if_none(): +def test_sanitize_as_empty_string(): string = 'asopdfha' string2 = None - string = utils.change_if_none(string) - string2 = utils.change_if_none(string2) + string = utils.sanitize_as_empty_string(string) + string2 = utils.sanitize_as_empty_string(string2) if not (string == 'asopdfha' and string2 == ''): raise AssertionError() + +def test_gen_co_author(): + arg = utils.gen_co_author('kiryto ') + if not arg == "Co-authored-by: kiryto ": + raise AssertionError() + + arg2 = utils.gen_co_author('') + if not arg2 == '': + raise AssertionError() + # FIXME # def test_create_file(tmpdir): # test_file = tmpdir.mkdir('test').join('commiter.yml') diff --git a/utils.py b/utils.py index be085c0..7371e88 100644 --- a/utils.py +++ b/utils.py @@ -3,6 +3,7 @@ supported_conventions = [ "angular", + "karma", "changelog", "symphony", "message", @@ -23,7 +24,7 @@ def get_text(context=False): if context: tag = str(input("type the tag: ")) msg = str(input("type the commit message: ")).lower() - context = str(input('type the context: ')).lower() + context = str(input('type the context: ') or '').lower() return tag, msg, context else: tag = str(input("type the tag: ")) @@ -31,6 +32,12 @@ def get_text(context=False): return tag, msg +def gen_co_author(co_author): + if co_author is '': + return '' + return "Co-authored-by: %s" % co_author + + def create_file(convention_name, dont_create=False): if not dont_create: data = dict( @@ -62,7 +69,7 @@ def parser_cli(): return parser -def change_if_none(string): +def sanitize_as_empty_string(string): if string is None: return '' return string