-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfile_handler.py
65 lines (53 loc) · 2.13 KB
/
file_handler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from os import system
from pathlib import Path
from yaml import safe_load
from yaml import YAMLError
from .text_utils import debug
from .text_utils import notify
from .text_utils import get_text
from .utils import gen_co_author
from .utils import dump_convention
from .utils import validate_commiter_file
from .utils import handle_conventioned_commit
from commit_helper.conventions.no_convention import just_message
from commit_helper.conventions.custom_convention import custom_convention
def handle_file_based_commit(file_path, debug_mode, args):
"""
Function that handles all the logic involved in commits with previous
configuration file.
"""
with open(str(file_path), 'r') as stream:
try:
config = safe_load(stream)
debug('convention from file', config['convention'], debug_mode)
convention = dump_convention(config)
if convention == 'none':
notify('You are not using a convention')
if args.message is not '':
commit_msg = just_message(msg=args.message)
else:
commit_msg = just_message()
elif convention == 'custom':
notify('You are using your custom convention')
validate_commiter_file(config)
tag, msg = get_text()
commit_msg = custom_convention(tag, msg, config, debug_mode)
else:
notify('You are using the %s convention' % convention)
commit_msg = handle_conventioned_commit(convention, args)
commit_msg += gen_co_author(args.co_author)
debug('commit message', commit_msg, debug_mode)
system('git commit -m "%s"' % commit_msg)
except YAMLError as err:
print(err)
def get_file_path(): # pragma: no cover
"""
Searchs on the folder the program was called if there is a commiter.yml
or a commit-helper.yml file and returns it's path if exists.
"""
commiter = Path('commiter.yml')
commit_h = Path('commit-helper.yml')
if commiter.exists():
return commiter
else:
return commit_h