Skip to content

Commit c0e99f4

Browse files
authored
merge(#48): introducing custom conventions
Introducing custom conventions
2 parents 351f5f5 + a38996f commit c0e99f4

18 files changed

+214
-114
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Sometimes we, the developers, go _full-loco_ while programming and make mistakes
3131
In order to install one of our older versions, check our [previous releases](PREVIOUS_VERSIONS). To install the latest (pip) version, just follow the commands below:
3232

3333
```bash
34-
$ pip3 install commit-helper
34+
$ pip3 install commit-helper
3535
```
3636

3737
## Usage and configuration
@@ -98,6 +98,11 @@ Supported conventions available:
9898
- changelog
9999
- symphony
100100
101+
## Troubleshooting
102+
If after you've installed commit-helper the `commit` or `commit-helper` commands are not usable at the command line, check if `$HOME/.local/bin` is on your PATH. If not, add it on your .bashrc file by running:
103+
``` bash
104+
$ echo "export PATH=$HOME/.local/bin:$PATH" >> .bashrc
105+
```
101106
102107
## Project's maintainers
103108
| **Name** | **Username** |

assets/--co-author.gif

124 KB
Loading

assets/--convention.gif

133 KB
Loading

assets/--debug.gif

112 KB
Loading

assets/--no-file.gif

123 KB
Loading

assets/--tudo.gif

107 KB
Loading

assets/commit helper.gif

280 KB
Loading

assets/commit.gif

91.7 KB
Loading

commit_helper/__main__.py

Lines changed: 5 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
# dependencies imports
22
from pathlib import Path
3-
from yaml import safe_load
4-
from yaml import YAMLError
5-
from os import system
6-
7-
# conventions imports
8-
from .conventions.karma_angular import angular_convention
9-
from .conventions.changelog import changelog_convention
10-
from .conventions.symphony_cmf import symphony_convention
11-
from .conventions.no_convention import just_message
12-
133
# utils imports
144
from .utils.utils import parser_cli
15-
from .utils.utils import create_file
16-
from .utils.utils import debug
17-
from .utils.utils import get_text
18-
from .utils.utils import get_context
19-
from .utils.utils import gen_co_author
5+
from .utils.text_utils import debug
6+
from .utils.file_handler import handle_file_based_commit
7+
from .utils.flag_commit_handler import convention_flag_handler
208

219

2210
def main():
@@ -27,67 +15,11 @@ def main():
2715
file_path = Path('commiter.yml')
2816
debug('file_path', file_path, debug_mode)
2917
if file_path.is_file():
30-
with open(str(file_path), 'r') as stream:
31-
try:
32-
config = safe_load(stream)
33-
debug('convention from file', config['convention'], debug_mode)
34-
if config['convention'] is not None:
35-
convention = str(config['convention']).lower()
36-
else:
37-
convention = 'none'
38-
39-
if convention == 'none':
40-
print('You are not using a convention')
41-
commit_message = just_message()
42-
43-
else:
44-
print('You are using the %s convention' % convention)
45-
tag, msg = get_text()
46-
if convention == 'angular' or convention == 'karma':
47-
context = get_context()
48-
commit_message = angular_convention(tag, msg, context)
49-
elif convention == 'changelog':
50-
commit_message = changelog_convention(tag, msg)
51-
elif convention == 'symphony':
52-
commit_message = symphony_convention(tag, msg)
53-
54-
commit_message += gen_co_author(args.co_author)
55-
debug('commit message', commit_message, debug_mode)
56-
system('git commit -m "%s"' % commit_message)
57-
58-
except YAMLError as exc:
59-
print(exc)
18+
handle_file_based_commit(file_path, debug_mode, args)
6019

6120
elif args.convention is not '':
62-
convention = str(args.convention)
63-
debug('convention flag', convention, debug_mode)
64-
65-
if convention == 'message':
66-
commit_message = just_message()
67-
create_file('none', args.no_file)
68-
69-
else:
70-
tag, msg = get_text()
71-
72-
if convention == 'angular' or convention == 'karma':
73-
context = get_context()
74-
commit_message = angular_convention(tag, msg, context)
75-
create_file(convention, args.no_file)
76-
elif convention == 'changelog':
77-
commit_message = changelog_convention(tag, msg)
78-
create_file(convention, args.no_file)
79-
elif convention == 'symphony':
80-
commit_message = symphony_convention(tag, msg)
81-
create_file(convention, args.no_file)
82-
83-
commit_message += gen_co_author(args.co_author)
84-
debug('commit message', commit_message, debug_mode)
85-
system('git commit -m "%s"' % commit_message)
21+
convention_flag_handler(args, debug_mode)
8622

8723
else:
8824
debug('parser full return', parser.parse_args(), debug_mode)
8925
parser.print_help()
90-
91-
92-
#
93-
# main(args.debug)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# custom commits are only acceptable when you have a config file
2+
from commit_helper.utils.text_utils import debug
3+
from commit_helper.utils.text_utils import get_context
4+
5+
6+
def custom_convention(tag, message, config_file, debug_mode):
7+
debug('tag', tag, debug_mode)
8+
debug('message', message, debug_mode)
9+
debug('pattern from file', config_file['commit_pattern'], debug_mode)
10+
11+
pattern = str(config_file['commit_pattern'] or '')
12+
debug('pattern acquired', pattern, debug_mode)
13+
14+
context = ''
15+
pattern = pattern.replace('tag', str(tag))
16+
pattern = pattern.replace('message', str(message))
17+
18+
if config_file['context']:
19+
context = get_context()
20+
pattern = pattern.replace('context', context)
21+
22+
debug('pattern post replace', pattern, debug_mode)
23+
pattern += '\n'
24+
return pattern

0 commit comments

Comments
 (0)