Skip to content

Commit 631db6c

Browse files
arthur0496andre-filho
authored andcommitted
chore(conventions_formatting): Refatorates convention formatter (#37)
* chore(karma/angular): refatorates karma/angular convention * UPDATE: refatorates changelog convention * [Update] refatorates symphony convention * Refatorates just message convention * Fixes get_text test Co-authored-by: arthur assis <[email protected]>
1 parent afdd2b9 commit 631db6c

File tree

7 files changed

+67
-82
lines changed

7 files changed

+67
-82
lines changed

conventions/changelog.py

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
from os import system
2-
from utils import get_text
3-
from utils import sanitize_as_empty_string
4-
from utils import gen_co_author
5-
6-
7-
def changelog_convention(co_author):
8-
tag, msg = get_text()
1+
def changelog_convention(tag,msg):
92
tag = tag.upper()
103
composed_message = "%s: %s\n" % (tag, msg)
11-
composed_message += gen_co_author(co_author)
12-
system("git commit -m '%s'" % composed_message)
4+
return composed_message

conventions/karma_angular.py

+3-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
1-
from os import system
2-
from utils import get_text
3-
from utils import sanitize_as_empty_string
4-
from utils import gen_co_author
5-
6-
7-
def angular_convention(co_author):
8-
tag, msg, context = get_text(context=True)
1+
def angular_convention(tag,msg,context):
92
tag = tag.lower()
10-
co_author = sanitize_as_empty_string(co_author)
113
if context is '':
12-
composed_message = composed_message = "%s: %s\n" % (tag, msg)
4+
composed_message = "%s: %s\n" % (tag, msg)
135
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)
6+
return composed_message

conventions/no_convention.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
from os import system
2-
from utils import sanitize_as_empty_string
3-
from utils import gen_co_author
4-
5-
6-
def just_message(co_author):
1+
def just_message():
72
msg = str(input("commit message: "))
83
composed = "%s\n" % msg.capitalize()
9-
composed += gen_co_author(co_author)
10-
system("git commit -m '%s'" % composed)
4+
return composed

conventions/symphony_cmf.py

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
from os import system
2-
from utils import get_text
3-
from utils import sanitize_as_empty_string
4-
from utils import gen_co_author
5-
6-
7-
def symphony_convention(co_author):
8-
tag, msg = get_text()
1+
def symphony_convention(tag,msg):
92
tag = tag.capitalize()
103
composed = "[%s] %s\n" % (tag, msg)
11-
composed += gen_co_author(co_author)
12-
system("git commit -m '%s'" % composed)

generator.py

+46-22
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from pathlib import Path
55
from yaml import safe_load
66
from yaml import YAMLError
7+
from os import system
78

89
# conventions imports
910
from conventions.karma_angular import angular_convention
@@ -15,6 +16,9 @@
1516
from utils import parser_cli
1617
from utils import create_file
1718
from utils import debug
19+
from utils import get_text
20+
from utils import get_context
21+
from utils import gen_co_author
1822

1923

2024
def main(debug_mode=False):
@@ -29,36 +33,56 @@ def main(debug_mode=False):
2933
convention = str(config['convention']).lower()
3034
else:
3135
convention = 'none'
32-
if convention == 'angular' or convention == 'karma':
33-
print('You are using the %s convention' % convention)
34-
angular_convention(args.co_author)
35-
elif convention == 'changelog':
36-
print('You are using the %s convention' % convention)
37-
changelog_convention(args.co_author)
38-
elif convention == 'symphony':
39-
print('You are using the %s convention' % convention)
40-
symphony_convention(args.co_author)
41-
elif convention == 'none':
42-
just_message(args.co_author)
36+
37+
if convention == 'none':
38+
commit_message = just_message()
39+
40+
else:
41+
tag, msg = get_text()
42+
if convention == 'angular' or convention == 'karma':
43+
print('You are using the %s convention' % convention)
44+
context = get_context()
45+
commit_message = angular_convention(tag, msg, context)
46+
elif convention == 'changelog':
47+
print('You are using the %s convention' % convention)
48+
commit_message = changelog_convention(tag, msg)
49+
elif convention == 'symphony':
50+
print('You are using the %s convention' % convention)
51+
commit_message = symphony_convention(tag, msg)
52+
53+
commit_message += gen_co_author(args.co_author)
54+
debug('commit message', commit_message, debug_mode)
55+
system('git commit -m "%s"' % commit_message)
56+
4357
except YAMLError as exc:
4458
print(exc)
4559

4660
elif args.convention is not '':
4761
convention = str(args.convention)
4862
debug('convention flag', convention, debug_mode)
49-
if convention == 'angular' or convention == 'karma':
50-
angular_convention(args.co_author)
51-
create_file(convention, args.no_file)
52-
elif convention == 'changelog':
53-
changelog_convention(args.co_author)
54-
create_file(convention, args.no_file)
55-
elif convention == 'symphony':
56-
symphony_convention(args.co_author)
57-
create_file(convention, args.no_file)
58-
elif convention == 'message':
59-
just_message(convention)
63+
64+
if convention == 'message':
65+
commit_message = just_message()
6066
create_file('none', args.no_file)
6167

68+
else:
69+
tag, msg = get_text()
70+
71+
if convention == 'angular' or convention == 'karma':
72+
context = get_context()
73+
commit_message = angular_convention(tag, msg, context)
74+
create_file(convention, args.no_file)
75+
elif convention == 'changelog':
76+
commit_message = changelog_convention(tag, msg)
77+
create_file(convention, args.no_file)
78+
elif convention == 'symphony':
79+
commit_message = symphony_convention(tag, msg)
80+
create_file(convention, args.no_file)
81+
82+
commit_message += gen_co_author(args.co_author)
83+
debug('commit message', commit_message, debug_mode)
84+
system('git commit -m "%s"' % commit_message)
85+
6286
else:
6387
debug('parser full return', parser.parse_args(), debug_mode)
6488
parser.print_help()

test/test_utils.py

+5-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# import yaml
33

44

5-
def test_get_text_no_context():
5+
6+
def test_get_text():
67
inputs = [
78
"tag",
89
"message",
@@ -18,24 +19,17 @@ def mock_input(s):
1819
raise AssertionError()
1920

2021

21-
def test_get_text_context():
22+
def test_get_context():
2223
inputs = [
23-
"tag",
24-
"message",
2524
"context",
2625
]
2726

2827
def mock_input(s):
2928
return inputs.pop(0)
3029
utils.input = mock_input
31-
a, b, c = utils.get_text(context=True)
32-
if not a == 'tag':
30+
a = utils.get_context()
31+
if not a == 'context':
3332
raise AssertionError()
34-
if not b == 'message':
35-
raise AssertionError()
36-
if not c == 'context':
37-
raise AssertionError()
38-
3933

4034
def test_sanitize_as_empty_string():
4135
string = 'asopdfha'

utils.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,15 @@
2020
"""
2121

2222

23-
def get_text(context=False):
24-
if context:
25-
tag = str(input("type the tag: "))
26-
msg = str(input("type the commit message: ")).lower()
23+
def get_text():
24+
tag = str(input("type the tag: "))
25+
msg = str(input("type the commit message: ")).lower()
26+
return tag, msg
27+
28+
29+
def get_context():
2730
context = str(input('type the context: ') or '').lower()
28-
return tag, msg, context
29-
else:
30-
tag = str(input("type the tag: "))
31-
msg = str(input("type the commit message: ")).lower()
32-
return tag, msg
31+
return context
3332

3433

3534
def gen_co_author(co_author):

0 commit comments

Comments
 (0)