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: 6 additions & 5 deletions conventions/changelog.py
Original file line number Diff line number Diff line change
@@ -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)
15 changes: 9 additions & 6 deletions conventions/karma_angular.py
Original file line number Diff line number Diff line change
@@ -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)
11 changes: 6 additions & 5 deletions conventions/no_convention.py
Original file line number Diff line number Diff line change
@@ -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)
11 changes: 6 additions & 5 deletions conventions/symphony_cmf.py
Original file line number Diff line number Diff line change
@@ -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)
16 changes: 13 additions & 3 deletions test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>')
if not arg == "Co-authored-by: kiryto <[email protected]>":
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')
Expand Down
11 changes: 9 additions & 2 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

supported_conventions = [
"angular",
"karma",
"changelog",
"symphony",
"message",
Expand All @@ -23,14 +24,20 @@ 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: "))
msg = str(input("type the commit message: ")).lower()
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(
Expand Down Expand Up @@ -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
Expand Down