Skip to content

Commit 7331c9a

Browse files
authored
merge(#51): Fast paced line commit
Fast paced line commit
2 parents fe57f89 + 1fc1554 commit 7331c9a

File tree

10 files changed

+146
-54
lines changed

10 files changed

+146
-54
lines changed

VERSION.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.2.2
1+
3.3.2

commit_helper/__main__.py

+4
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ def main():
1111
parser = parser_cli()
1212
args = parser.parse_args()
1313
debug_mode = args.debug
14+
1415
debug('args variable', args, debug_mode)
16+
1517
file_path = Path('commiter.yml')
18+
1619
debug('file_path', file_path, debug_mode)
20+
1721
if file_path.is_file():
1822
handle_file_based_commit(file_path, debug_mode, args)
1923

commit_helper/conventions/no_convention.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
from commit_helper.utils.colors import RESET
33

44

5-
def just_message():
6-
msg = str(input(INPUT_COLOR + "commit message: " + RESET))
7-
composed = "%s\n" % msg.capitalize()
5+
def just_message(msg=''):
6+
if msg is '':
7+
message = str(input(INPUT_COLOR + "commit message: " + RESET))
8+
else:
9+
message = msg
10+
11+
composed = "%s\n" % message.capitalize()
812
return composed

commit_helper/utils/file_handler.py

+3-18
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from .utils import gen_co_author
66
from .utils import dump_convention
77
from .utils import validate_commiter_file
8+
from .utils import handle_conventioned_commit
89
from .colors import RESET
910
from .colors import NOTIFY_COLOR
1011
from .text_utils import debug
@@ -37,28 +38,12 @@ def handle_file_based_commit(file_path, debug_mode, args):
3738
commit_msg = custom_convention(tag, msg, config, debug_mode)
3839

3940
else:
40-
commit_msg = handle_conventioned_commit(convention)
41+
notify('You are using the %s convention' % convention)
42+
commit_msg = handle_conventioned_commit(convention, args)
4143

4244
commit_msg += gen_co_author(args.co_author)
4345
debug('commit message', commit_msg, debug_mode)
4446
system('git commit -m "%s"' % commit_msg)
4547

4648
except YAMLError as err:
4749
print(err)
48-
49-
50-
def handle_conventioned_commit(convention):
51-
notify('You are using the %s convention' % convention)
52-
tag, msg = get_text()
53-
54-
if convention == 'angular' or convention == 'karma':
55-
context = get_context()
56-
commit_message = angular_convention(tag, msg, context)
57-
58-
elif convention == 'changelog':
59-
commit_message = changelog_convention(tag, msg)
60-
61-
elif convention == 'symphony':
62-
commit_message = symphony_convention(tag, msg)
63-
64-
return commit_message

commit_helper/utils/flag_commit_handler.py

+8-12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# utils imports
33
from .utils import create_file
44
from .utils import gen_co_author
5+
from .utils import handle_conventioned_commit
56
from .text_utils import debug
67
from .text_utils import get_text
78
from .text_utils import get_context
@@ -17,22 +18,17 @@ def convention_flag_handler(args, debug_mode):
1718
debug('convention flag', convention, debug_mode)
1819

1920
if convention == 'message':
20-
commit_message = just_message()
21+
if args.message is not '':
22+
commit_message = just_message(msg=args.message)
23+
else:
24+
commit_message = just_message()
25+
2126
create_file('none', args.no_file)
2227

2328
else:
24-
tag, msg = get_text()
25-
if convention == 'angular' or convention == 'karma':
26-
context = get_context()
27-
commit_message = angular_convention(tag, msg, context)
28-
create_file(convention, args.no_file)
29-
elif convention == 'changelog':
30-
commit_message = changelog_convention(tag, msg)
31-
create_file(convention, args.no_file)
32-
elif convention == 'symphony':
33-
commit_message = symphony_convention(tag, msg)
34-
create_file(convention, args.no_file)
29+
commit_message = handle_conventioned_commit(convention, args)
3530

31+
create_file(convention, args.no_file)
3632
commit_message += gen_co_author(args.co_author)
3733
debug('commit message', commit_message, debug_mode)
3834
system('git commit -m "%s"' % commit_message)

commit_helper/utils/text_utils.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from commit_helper.utils.colors import RESET
2-
from commit_helper.utils.colors import DEBUG_COLOR
3-
from commit_helper.utils.colors import INPUT_COLOR
4-
from commit_helper.utils.colors import NOTIFY_COLOR
1+
from .colors import RESET
2+
from .colors import DEBUG_COLOR
3+
from .colors import INPUT_COLOR
4+
from .colors import NOTIFY_COLOR
55

66

77
def get_text():
@@ -30,3 +30,15 @@ def debug(message, value, show=False):
3030
if show:
3131
mid = 'DEBUG: ' + str(message) + ' ~> ' + str(value)
3232
print(DEBUG_COLOR + mid + RESET)
33+
34+
35+
def handle_tag_message_args(tag='', message=''):
36+
if tag + message is not '':
37+
return tag, message
38+
return get_text()
39+
40+
41+
def handle_context_arg(context=''):
42+
if context is not '':
43+
return context
44+
return get_context()

commit_helper/utils/utils.py

+47-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import sys
22
import argparse
33
from yaml import dump
4+
from .text_utils import handle_context_arg
5+
from .text_utils import handle_tag_message_args
6+
from commit_helper.conventions.karma_angular import angular_convention
7+
from commit_helper.conventions.changelog import changelog_convention
8+
from commit_helper.conventions.symphony_cmf import symphony_convention
9+
410

511
supported_conventions = [
612
"angular",
@@ -24,7 +30,7 @@
2430
def gen_co_author(co_author):
2531
if co_author is '':
2632
return ''
27-
return "\nCo-authored-by: %s" % co_author
33+
return '\nCo-authored-by: %s' % co_author
2834

2935

3036
def create_file(convention_name, dont_create=False): # pragma: no cover
@@ -38,23 +44,36 @@ def create_file(convention_name, dont_create=False): # pragma: no cover
3844

3945

4046
def parser_cli():
41-
desc = "A commit formatter tool to help you follow commit conventions."
47+
desc = 'A commit formatter tool to help you follow commit conventions.'
4248
help_convention = \
4349
"""
4450
Selects a convention to be used for the commit.
4551
Required if there's no commiter.yml file.
4652
"""
4753
parser = argparse.ArgumentParser(description=desc)
48-
parser.add_argument("-ca", "--co-author",
49-
help="Make your friend an co-author to the commit",
50-
dest="co_author", default='')
51-
parser.add_argument("-nf", "--no-file", dest="no_file",
52-
help="Disables the creation of a commiter.yml file",
53-
action="store_true")
54-
parser.add_argument("-c", "--convention", choices=supported_conventions,
55-
dest="convention", default='', help=help_convention)
56-
parser.add_argument("-d", "--debug", action="store_true", dest="debug",
57-
help="Toggles debug option")
54+
parser.add_argument('-t', '--tag', dest='tag', default='',
55+
help='Pass your commit tag directly')
56+
57+
parser.add_argument('-m', '--message', dest='message', default='',
58+
help='Pass your commit message directly')
59+
60+
parser.add_argument('-ct', '--context', dest='context', default='',
61+
help='Pass your commit context directly')
62+
63+
parser.add_argument('-ca', '--co-author',
64+
help='Make your friend an co-author to the commit',
65+
dest='co_author', default='')
66+
67+
parser.add_argument('-nf', '--no-file', dest='no_file',
68+
help='Disables the creation of a commiter.yml file',
69+
action='store_true')
70+
71+
parser.add_argument('-c', '--convention', choices=supported_conventions,
72+
dest='convention', default='', help=help_convention)
73+
74+
parser.add_argument('-d', '--debug', action='store_true', dest='debug',
75+
help='Toggles debug option')
76+
5877
return parser
5978

6079

@@ -69,3 +88,19 @@ def validate_commiter_file(stream_file): # pragma: no cover
6988
if stream_file['commit_pattern'] is None or stream_file['context'] is None:
7089
print("Error: Your commiter file lacks a commit_pattern or context!")
7190
sys.exit(0)
91+
92+
93+
def handle_conventioned_commit(convention, args):
94+
tag, msg = handle_tag_message_args(args.tag, args.message)
95+
96+
if convention == 'angular' or convention == 'karma':
97+
context = handle_context_arg(args.context)
98+
commit_message = angular_convention(tag, msg, context)
99+
100+
elif convention == 'changelog':
101+
commit_message = changelog_convention(tag, msg)
102+
103+
elif convention == 'symphony':
104+
commit_message = symphony_convention(tag, msg)
105+
106+
return commit_message

release.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#! /bin/bash
2+
3+
python3 setup.py sdist bdist_wheel
4+
5+
if "$1" == "test"; then
6+
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
7+
fi
8+
9+
if "$1" == "deploy"; then
10+
twine upload dist/*
11+
fi

test/test_conventions.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,21 @@ def test_custom_convention():
4444
raise AssertionError()
4545

4646

47-
def test_no_convention():
47+
def test_no_convention_without_args():
4848
inputs = [
4949
"message",
5050
]
5151

5252
def mock_input(s):
5353
return inputs.pop(0)
54+
5455
no_convention.input = mock_input
5556
message = no_convention.just_message()
5657
if not message == 'Message\n':
5758
raise AssertionError()
59+
60+
61+
def test_no_convention_with_args():
62+
message = no_convention.just_message('Message')
63+
if not message == 'Message\n':
64+
raise AssertionError()

test/test_utils.py

+41-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import yaml
22
import commit_helper.utils.utils as utils
33
import commit_helper.utils.text_utils as text_utils
4+
45
from commit_helper.utils.colors import RESET
56
from commit_helper.utils.colors import DEBUG_COLOR
67
from commit_helper.utils.colors import NOTIFY_COLOR
7-
# from commit_helper.utils.utils import validate_commiter_file
8-
# import commit_helper.utils.file_handler as file_utils
9-
# import commit_helper.utils.flag_commit_handler as flag_utils
108

119

1210
def test_get_text():
@@ -91,3 +89,43 @@ def test_notify(capsys):
9189
captured = capsys.readouterr()
9290
if not captured.out == NOTIFY_COLOR + "msg" + RESET + "\n":
9391
raise AssertionError()
92+
93+
94+
def test_handle_tag_message_args_with_args():
95+
tag, msg = text_utils.handle_tag_message_args('tag', 'msg')
96+
97+
if not (tag is 'tag' and msg is 'msg'):
98+
raise AssertionError()
99+
100+
101+
def test_handle_tag_message_args_without_args():
102+
inputs = ['tag', 'msg']
103+
104+
def mock_input(s):
105+
return inputs.pop(0)
106+
107+
text_utils.input = mock_input
108+
tag, msg = text_utils.handle_tag_message_args()
109+
110+
if not (tag == 'tag' and msg == 'msg'):
111+
raise AssertionError()
112+
113+
114+
def test_handle_context_arg_with_args():
115+
context = text_utils.handle_context_arg('context')
116+
117+
if not context is 'context':
118+
raise AssertionError()
119+
120+
121+
def test_handle_context_arg_without_args():
122+
inputs = ['context']
123+
124+
def mock_input(s):
125+
return inputs.pop(0)
126+
127+
text_utils.input = mock_input
128+
context = text_utils.handle_context_arg()
129+
130+
if not context == 'context':
131+
raise AssertionError()

0 commit comments

Comments
 (0)