Skip to content

Commit bc1d2f6

Browse files
authored
merge(#33): contexts are optional
add: optional context to angular/karma and co-author generation
2 parents 075f367 + e6535fd commit bc1d2f6

File tree

6 files changed

+49
-26
lines changed

6 files changed

+49
-26
lines changed

conventions/changelog.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from os import system
22
from utils import get_text
3-
from utils import change_if_none
3+
from utils import sanitize_as_empty_string
4+
from utils import gen_co_author
45

56

6-
def changelog_convention(co_author=''):
7+
def changelog_convention(co_author):
78
tag, msg = get_text()
89
tag = tag.upper()
9-
co_author = change_if_none(co_author)
10-
composed_message = """%s: %s\n\nCo-authored-by: """ % (tag, msg)
11-
system("git commit -m '%s%s'" % (composed_message, co_author))
10+
composed_message = "%s: %s\n" % (tag, msg)
11+
composed_message += gen_co_author(co_author)
12+
system("git commit -m '%s'" % composed_message)

conventions/karma_angular.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
from os import system
22
from utils import get_text
3-
from utils import change_if_none
3+
from utils import sanitize_as_empty_string
4+
from utils import gen_co_author
45

56

6-
def angular_convention(co_author=''):
7+
def angular_convention(co_author):
78
tag, msg, context = get_text(context=True)
89
tag = tag.lower()
9-
co_author = change_if_none(co_author)
10-
composed_message = """%s(%s): %s\n\nCo-authored-by:
11-
""" % (tag, context, msg)
12-
system('git commit -m "%s%s"' % (composed_message, co_author))
10+
co_author = sanitize_as_empty_string(co_author)
11+
if context is '':
12+
composed_message = composed_message = "%s: %s\n" % (tag, msg)
13+
composed_message = "%s(%s): %s\n" % (tag, context, msg)
14+
composed_message += gen_co_author(co_author)
15+
system('git commit -m "%s"' % composed_message)

conventions/no_convention.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from os import system
2-
from utils import change_if_none
2+
from utils import sanitize_as_empty_string
3+
from utils import gen_co_author
34

45

5-
def just_message(co_author=''):
6+
def just_message(co_author):
67
msg = str(input("commit message: "))
7-
co_author = change_if_none(co_author)
8-
composed = """%s\n\nCo-authored-by: """ % msg.capitalize()
9-
system("git commit -m '%s%s'" % (composed, co_author))
8+
composed = "%s\n" % msg.capitalize()
9+
composed += gen_co_author(co_author)
10+
system("git commit -m '%s'" % composed)

conventions/symphony_cmf.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from os import system
22
from utils import get_text
3-
from utils import change_if_none
3+
from utils import sanitize_as_empty_string
4+
from utils import gen_co_author
45

56

6-
def symphony_convention(co_author=''):
7+
def symphony_convention(co_author):
78
tag, msg = get_text()
89
tag = tag.capitalize()
9-
co_author = change_if_none(co_author)
10-
composed = """[%s] %s\n\nCo-authored-by: """ % (tag, msg)
11-
system("git commit -m '%s%s'" % (composed, co_author))
10+
composed = "[%s] %s\n" % (tag, msg)
11+
composed += gen_co_author(co_author)
12+
system("git commit -m '%s'" % composed)

test/test_utils.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,24 @@ def mock_input(s):
3737
raise AssertionError()
3838

3939

40-
def test_change_if_none():
40+
def test_sanitize_as_empty_string():
4141
string = 'asopdfha'
4242
string2 = None
43-
string = utils.change_if_none(string)
44-
string2 = utils.change_if_none(string2)
43+
string = utils.sanitize_as_empty_string(string)
44+
string2 = utils.sanitize_as_empty_string(string2)
4545
if not (string == 'asopdfha' and string2 == ''):
4646
raise AssertionError()
4747

48+
49+
def test_gen_co_author():
50+
arg = utils.gen_co_author('kiryto <[email protected]>')
51+
if not arg == "Co-authored-by: kiryto <[email protected]>":
52+
raise AssertionError()
53+
54+
arg2 = utils.gen_co_author('')
55+
if not arg2 == '':
56+
raise AssertionError()
57+
4858
# FIXME
4959
# def test_create_file(tmpdir):
5060
# test_file = tmpdir.mkdir('test').join('commiter.yml')

utils.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
supported_conventions = [
55
"angular",
6+
"karma",
67
"changelog",
78
"symphony",
89
"message",
@@ -23,14 +24,20 @@ def get_text(context=False):
2324
if context:
2425
tag = str(input("type the tag: "))
2526
msg = str(input("type the commit message: ")).lower()
26-
context = str(input('type the context: ')).lower()
27+
context = str(input('type the context: ') or '').lower()
2728
return tag, msg, context
2829
else:
2930
tag = str(input("type the tag: "))
3031
msg = str(input("type the commit message: ")).lower()
3132
return tag, msg
3233

3334

35+
def gen_co_author(co_author):
36+
if co_author is '':
37+
return ''
38+
return "Co-authored-by: %s" % co_author
39+
40+
3441
def create_file(convention_name, dont_create=False):
3542
if not dont_create:
3643
data = dict(
@@ -62,7 +69,7 @@ def parser_cli():
6269
return parser
6370

6471

65-
def change_if_none(string):
72+
def sanitize_as_empty_string(string):
6673
if string is None:
6774
return ''
6875
return string

0 commit comments

Comments
 (0)