Skip to content

Commit b9d737e

Browse files
authored
feat(yaml config): merges implementation of yaml configuration
Adds .yml config file support
2 parents a9c3c58 + 0be5fe4 commit b9d737e

File tree

5 files changed

+143
-20
lines changed

5 files changed

+143
-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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,40 @@ Just follow the commands below:
2929

3030
```
3131

32+
## Usage and configuration
33+
34+
For this project to work smoothly, you must have in your working directory a file named **commiter.yml**. In this file you must pass the commit convention that you want to use, following the example:
35+
36+
```yaml
37+
convention: angular
38+
# or
39+
convention: changelog
40+
# or even
41+
convention: symphony
42+
```
43+
44+
45+
46+
Supported conventions available:
47+
<!-- list here all tags that are used in configuration file -->
48+
49+
- angular/karma
50+
- changelog
51+
- symphony
52+
53+
In the event of no commiter.yml file presence, you will be prompted with the following option menu:
54+
55+
```bash
56+
No config files found!
57+
Running default script...
58+
what type of commit convention are you using?
59+
1- Karma/Angular
60+
2- Conventional changelog
61+
3- Symfony CMF
62+
```
63+
64+
65+
3266
## Project's maintainers
3367
| **Name** | **Username** |
3468
| :--------: | :-----: |

generator.py

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,55 @@
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 safe_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
1011

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

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))
18+
file_path = Path("commiter.yml")
1819

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

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