Skip to content

Commit 8bdd7c6

Browse files
committed
add(config file): added initial parser for yml
1 parent a9c3c58 commit 8bdd7c6

File tree

5 files changed

+117
-20
lines changed

5 files changed

+117
-20
lines changed

.editorconfig

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
[*.py]
2-
indent_size = 4
1+
[*]
2+
charset = utf-8
33
indent_style = space
44
end_of_line = lf
55
trim_trailing_whitespace = false
6+
7+
[*.py]
8+
indent_size = 4

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
.vscode/
2+
commiter.yml
3+
__pycache__/

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ Just follow the commands below:
2929

3030
```
3131

32+
## Usage and configuration
33+
34+
Configuration tags available:
35+
<!-- list here all tags that are used in configuration file -->
36+
-
37+
3238
## Project's maintainers
3339
| **Name** | **Username** |
3440
| :--------: | :-----: |

generator.py

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,57 @@
11
import os
22

3-
opt = int(input("""
4-
what type of commit convention are you using?
3+
from pathlib import Path
4+
from yaml import load
5+
from yaml import YAMLError
56

6-
1- Karma/Angular
7-
2- Conventional changelog
8-
3- Symfony CMF
9-
"""))
7+
from utils import run_config
8+
from utils import angular_convention
9+
from utils import changelog_convention
10+
from utils import symphony_convention
11+
from utils import possible_configurations
1012

11-
tag = str(input("type the tag: "))
12-
msg = str(input("type the commit message: ")).lower()
13+
tag = ''
14+
# msg = ''
15+
tag_is_lowercase = False
16+
tag_is_uppercase = False
17+
tag_is_capitalized = False
18+
convention = ''
1319

14-
if opt == 1:
15-
context = str(input('type the context: ')).lower()
16-
tag = tag.lower()
17-
os.system("git commit -m '%s(%s): %s'" % (tag, context, msg))
20+
file_path = Path("commiter.yml")
1821

19-
elif opt == 2:
20-
tag = tag.upper()
21-
os.system("git commit -m '%s: %s'" % (tag, msg))
22+
if file_path.is_file():
23+
with open(str(file_path), 'r') as stream:
24+
try:
25+
config = load(stream)
26+
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)
27+
if convention != '' or convention != 'custom':
28+
if convention == 'angular':
29+
print('You are using the %s convention' % convention)
30+
angular_convention()
31+
elif convention == 'changelog':
32+
print('You are using the %s convention' % convention)
33+
changelog_convention()
34+
elif convention == 'symphony':
35+
print('You are using the %s convention' % convention)
36+
symphony_convention()
37+
else:
38+
custom_convention()
39+
except YAMLError as exc:
40+
print(exc)
2241

23-
elif opt == 3:
24-
tag = tag.capitalize()
25-
os.system("git commit -m '[%s] %s'" % (tag, msg))
42+
else:
43+
print("No config files found!\nRunning default script...")
44+
opt = int(input("""
45+
what type of commit convention are you using?
46+
47+
1- Karma/Angular
48+
2- Conventional changelog
49+
3- Symfony CMF
50+
"""))
51+
52+
if opt == 1:
53+
angular_convention()
54+
elif opt == 2:
55+
changelog_convention()
56+
elif opt == 3:
57+
symphony_convention()

utils.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import os
2+
3+
possible_configurations = [
4+
'tag',
5+
'tag_is_lowercase',
6+
'tag_is_uppercase',
7+
'tag_is_capitalized',
8+
'convention',
9+
]
10+
11+
# refactor this function, surely there is a better way of writing this
12+
def run_config(array, tag, tag_is_capitalized, tag_is_lowercase, tag_is_uppercase,convention):
13+
for conf in possible_configurations:
14+
if conf in array:
15+
if conf == 'tag':
16+
tag = str(array[conf])
17+
elif conf == 'tag_is_lowercase':
18+
tag_is_lowercase = bool(array[conf])
19+
elif conf == 'tag_is_uppercase':
20+
tag_is_uppercase = bool(array[conf])
21+
elif conf == 'tag_is_capitalized':
22+
tag_is_capitalized = bool(array[conf])
23+
elif conf == 'convention':
24+
convention = str(array[conf])
25+
return tag, tag_is_capitalized, tag_is_lowercase, tag_is_uppercase, convention
26+
27+
def get_text(context=False):
28+
if context:
29+
tag = str(input("type the tag: "))
30+
msg = str(input("type the commit message: ")).lower()
31+
context = str(input('type the context: ')).lower()
32+
return tag, msg, context
33+
else:
34+
tag = str(input("type the tag: "))
35+
msg = str(input("type the commit message: ")).lower()
36+
return tag, msg
37+
38+
def angular_convention():
39+
tag, msg, context = get_text(context=True)
40+
tag = tag.lower()
41+
os.system("git commit -m '%s(%s): %s'" % (tag, context, msg))
42+
43+
def changelog_convention():
44+
tag, msg = get_text()
45+
tag = tag.upper()
46+
os.system("git commit -m '%s: %s'" % (tag, msg))
47+
48+
def symphony_convention():
49+
tag, msg = get_text()
50+
tag = tag.capitalize()
51+
os.system("git commit -m '[%s] %s'" % (tag, msg))
52+
53+
def custom_convention():
54+
pass

0 commit comments

Comments
 (0)