Skip to content

Commit 5f3d768

Browse files
committed
chore(refactoring): split functions into individual files, reviewed imports and cleans code
1 parent efafe5c commit 5f3d768

File tree

10 files changed

+39
-64
lines changed

10 files changed

+39
-64
lines changed

conventions/__init__.py

Whitespace-only changes.

conventions/changelog.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from os import system
2+
from utils import get_text
3+
4+
def changelog_convention():
5+
tag, msg = get_text()
6+
tag = tag.upper()
7+
system("git commit -m '%s: %s'" % (tag, msg))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# FUTURE: implement
2+
def custom_convention():
3+
pass

conventions/karma_angular.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from os import system
2+
from utils import get_text
3+
4+
def angular_convention():
5+
tag, msg, context = get_text(context=True)
6+
tag = tag.lower()
7+
system("git commit -m '%s(%s): %s'" % (tag, context, msg))

conventions/no_convention.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from os import system
2+
from utils import get_text
3+
4+
def just_message():
5+
msg = str(input("commit message: "))
6+
system("git commit -m '%s'" % msg.capitalize())

conventions/symphony_cmf.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from os import system
2+
from utils import get_text
3+
4+
def symphony_convention():
5+
tag, msg = get_text()
6+
tag = tag.capitalize()
7+
system("git commit -m '[%s] %s'" % (tag, msg))

generator.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,24 @@
22
from yaml import safe_load
33
from yaml import YAMLError
44

5-
from utils import run_config
6-
from utils import angular_convention
7-
from utils import changelog_convention
8-
from utils import symphony_convention
9-
from utils import just_message
10-
from utils import create_file
5+
# conventions imports
6+
from conventions.karma_angular import angular_convention
7+
from conventions.changelog import changelog_convention
8+
from conventions.symphony_cmf import symphony_convention
9+
from conventions.no_convention import just_message
1110

12-
tag = ''
13-
tag_is_lowercase = False
14-
tag_is_uppercase = False
15-
tag_is_capitalized = False
16-
convention = ''
11+
from utils import create_file
1712

1813
file_path = Path('commiter.yml')
19-
2014
if file_path.is_file():
2115
with open(str(file_path), 'r') as stream:
2216
try:
2317
config = safe_load(stream)
24-
tag, tag_is_capitalized, tag_is_lowercase, tag_is_uppercase, convention = run_config(config, tag, tag_is_capitalized, tag_is_lowercase, tag_is_uppercase, convention)
25-
if convention == 'angular':
18+
convention = str(config['convention']).lower() if config['convention'] != None else ''
19+
if convention == 'angular' or convention == 'karma':
2620
print('You are using the %s convention' % convention)
2721
angular_convention()
28-
elif convention == 'changelog':
22+
elif convention == 'changelog':
2923
print('You are using the %s convention' % convention)
3024
changelog_convention()
3125
elif convention == 'symphony':
@@ -37,7 +31,6 @@
3731
custom_convention()
3832
except YAMLError as exc:
3933
print(exc)
40-
4134
else:
4235
print("No config files found!\nRunning default script...")
4336
opt = int(input("""

test/__init__.py

Whitespace-only changes.

test/test.py

Whitespace-only changes.

utils.py

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,5 @@
1-
import os
21
from yaml import dump
32

4-
possible_configurations = [
5-
'tag',
6-
'tag_is_lowercase',
7-
'tag_is_uppercase',
8-
'tag_is_capitalized',
9-
'convention',
10-
]
11-
12-
# refactor this function, surely there is a better way of writing this
13-
def run_config(array, tag, tag_is_capitalized, tag_is_lowercase, tag_is_uppercase,convention):
14-
for conf in possible_configurations:
15-
if conf in array:
16-
if conf == 'tag':
17-
tag = str(array[conf])
18-
elif conf == 'tag_is_lowercase':
19-
tag_is_lowercase = bool(array[conf])
20-
elif conf == 'tag_is_uppercase':
21-
tag_is_uppercase = bool(array[conf])
22-
elif conf == 'tag_is_capitalized':
23-
tag_is_capitalized = bool(array[conf])
24-
elif conf == 'convention':
25-
convention = str(array[conf])
26-
return tag, tag_is_capitalized, tag_is_lowercase, tag_is_uppercase, convention
27-
283
def get_text(context=False):
294
if context:
305
tag = str(input("type the tag: "))
@@ -36,29 +11,6 @@ def get_text(context=False):
3611
msg = str(input("type the commit message: ")).lower()
3712
return tag, msg
3813

39-
def angular_convention():
40-
tag, msg, context = get_text(context=True)
41-
tag = tag.lower()
42-
os.system("git commit -m '%s(%s): %s'" % (tag, context, msg))
43-
44-
def changelog_convention():
45-
tag, msg = get_text()
46-
tag = tag.upper()
47-
os.system("git commit -m '%s: %s'" % (tag, msg))
48-
49-
def symphony_convention():
50-
tag, msg = get_text()
51-
tag = tag.capitalize()
52-
os.system("git commit -m '[%s] %s'" % (tag, msg))
53-
54-
def just_message():
55-
msg = str(input("commit message: "))
56-
os.system("git commit -m '%s'" % msg.capitalize())
57-
58-
# FUTURE: implement
59-
def custom_convention():
60-
pass
61-
6214
def create_file(convention_name):
6315
data = dict(
6416
convention = convention_name

0 commit comments

Comments
 (0)