Skip to content

Commit 1e01d38

Browse files
committed
chore(refactoring): organizing code
1 parent 034d89c commit 1e01d38

File tree

6 files changed

+36
-31
lines changed

6 files changed

+36
-31
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
charset = utf-8
33
indent_style = space
44
end_of_line = lf
5-
trim_trailing_whitespace = false
5+
trim_trailing_whitespace = true
66
indent_size = 2
77

88
[*.py]

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
.vscode/
22
commiter.yml
33
__pycache__/
4+
package.json
5+
package-lock.json

generator.py

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#! /usr/bin/env python3
22

3+
# dependencies imports
34
from pathlib import Path
45
from yaml import safe_load
56
from yaml import YAMLError
@@ -10,33 +11,23 @@
1011
from conventions.symphony_cmf import symphony_convention
1112
from conventions.no_convention import just_message
1213

14+
# utils imports
1315
from utils import create_file
14-
from utils import supported_conventions as convention_list
16+
from utils import menu
17+
from utils import parser_cli
1518

16-
import argparse
1719

18-
parser = argparse.ArgumentParser()
19-
parser.add_argument("--co-author",
20-
help="make your friend an co-author to the commit",
21-
dest="co_author", default=None)
22-
parser.add_argument("--no-generate",
23-
help="disables the creation of a commiter.yml file",
24-
default=True, type=bool)
25-
parser.add_argument('--convention', choices=convention_list,
26-
help="selects a convention to be used for the commit")
27-
parser.parse_args()
20+
parser = parser_cli()
2821

2922
file_path = Path('commiter.yml')
3023
if file_path.is_file():
3124
with open(str(file_path), 'r') as stream:
3225
try:
3326
config = safe_load(stream)
34-
3527
if config['convention'] is not None:
3628
convention = str(config['convention']).lower()
3729
else:
3830
convention = 'none'
39-
4031
if convention == 'angular' or convention == 'karma':
4132
print('You are using the %s convention' % convention)
4233
angular_convention()
@@ -48,23 +39,11 @@
4839
symphony_convention()
4940
elif convention == 'none':
5041
just_message()
51-
elif convention == 'custom':
52-
custom_convention()
53-
5442
except YAMLError as exc:
5543
print(exc)
5644
else:
5745
print("No config files found!\nRunning default script...")
58-
opt = int(input("""
59-
what type of commit convention are you using?
60-
61-
default: Just the message
62-
1: Karma/Angular
63-
2: Conventional changelog
64-
3: Symfony CMF
65-
66-
""") or 4)
67-
46+
opt = int(input(menu) or 4)
6847
if opt == 1:
6948
print("You're using the angular convention")
7049
angular_convention()

test/test_conventions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import pytest
1+
# import pytest
22
# import conventions.karma_angular as angular
33
# import conventions.changelog as changelog
44
# import convention.symphony_cmf as symphony

test/test_utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import pytest
21
import utils
32
import yaml
43

utils.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
1+
import argparse
12
from yaml import dump
23

34
supported_conventions = [
45
"angular",
56
"changelog",
6-
"symphony",
7+
"symphony",
78
"message_only",
89
]
910

11+
menu = """
12+
what type of commit convention are you using?
13+
14+
default: Just the message
15+
1: Karma/Angular
16+
2: Conventional changelog
17+
3: Symfony CMF
18+
19+
"""
20+
1021
def get_text(context=False):
1122
if context:
1223
tag = str(input("type the tag: "))
@@ -25,3 +36,17 @@ def create_file(convention_name):
2536
)
2637
with open('commiter.yml', 'w') as output_file:
2738
dump(data, output_file, default_flow_style=False)
39+
40+
41+
def parser_cli():
42+
parser = argparse.ArgumentParser()
43+
parser.add_argument("--co-author",
44+
help="make your friend an co-author to the commit",
45+
dest="co_author", default=None)
46+
parser.add_argument("--no-generate", dest="no_file",
47+
help="disables the creation of a commiter.yml file",
48+
default=True, type=bool)
49+
parser.add_argument('--convention', choices=supported_conventions,
50+
dest="convention",
51+
help="selects a convention to be used for the commit")
52+
parser.parse_args()

0 commit comments

Comments
 (0)