Skip to content

Commit 7a2646a

Browse files
authored
merge(#61): add support to conventions helpers
Convention helper
2 parents 40bc943 + e4fcb6c commit 7a2646a

File tree

15 files changed

+325
-61
lines changed

15 files changed

+325
-61
lines changed

README.md

Lines changed: 51 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,33 @@ Sometimes we, the developers, go _full-loco_ while programming and make mistakes
3030

3131
## Screenshots
3232

33-
<div style="margin-right:auto;margin-left:auto;">
34-
<img src="assets/commit.gif"/>
35-
<img src="assets/--tudo.gif"/>
36-
<img src="assets/--co-author.gif"/>
37-
<img src="assets/--debug.gif"/>
38-
<img src="assets/--no-file.gif"/>
39-
<img src="assets/--convention.gif"/>
40-
</div>
33+
### Initial commit
4134

35+
<img src="" style="min-width:200px;margin-left:auto;margin-right:auto;"/>
36+
37+
### Normal commit
38+
39+
<img src="" style="min-width:200px;margin-left:auto;margin-right:auto;"/>
40+
41+
### Co-authored commit
42+
43+
<img src="" style="min-width:200px;margin-left:auto;margin-right:auto;"/>
44+
45+
### Fast commit
46+
47+
<img src="" style="min-width:200px;margin-left:auto;margin-right:auto;"/>
48+
49+
### Debugging and commiting
50+
51+
<img src="" style="min-width:200px;margin-left:auto;margin-right:auto;"/>
52+
53+
### All-in-one commit
54+
55+
<img src="" style="min-width:200px;margin-left:auto;margin-right:auto;"/>
56+
57+
### Getting help for writing in a convention
58+
59+
<img src="" style="min-width:200px;margin-left:auto;margin-right:auto;"/>
4260

4361

4462
## Installation
@@ -56,21 +74,27 @@ will show you the usage and options for your commit. All of them are optional
5674
for the sake of not losing your precious time.
5775

5876
```bash
59-
$ commit -h
60-
usage: generator.py [-h] [--co-author CO_AUTHOR] [--no-generate NO_FILE]
61-
[--convention {angular,changelog,symphony,message}]
62-
63-
A commit formatter tool to help you follow commit conventions.
64-
65-
optional arguments:
66-
-h, --help show this help message and exit
67-
-ca, --co-author CO_AUTHOR
68-
make your friend an co-author to the commit
69-
-nf, --no-file
70-
disables the creation of a commiter.yml file
71-
-c, --convention {angular,changelog,symphony,message}
72-
Selects a convention to be used for the commit.
73-
Required if there is no commiter.yml file.
77+
$ commit -h
78+
usage: commit [-h] [-t TAG] [-m MESSAGE] [-ct CONTEXT] [-ca CO_AUTHOR] [-nf]
79+
[-c {angular,karma,tagged,symphony,message}] [-d]
80+
81+
A commit formatter tool to help you follow commit conventions.
82+
83+
optional arguments:
84+
-h, --help show this help message and exit
85+
-t TAG, --tag TAG Pass your commit tag directly
86+
-m MESSAGE, --message MESSAGE
87+
Pass your commit message directly
88+
-ct CONTEXT, --context CONTEXT
89+
Pass your commit context directly
90+
-ca CO_AUTHOR, --co-author CO_AUTHOR
91+
Make your friend an co-author to the commit
92+
-nf, --no-file Disables the creation of a commiter.yml file
93+
-c {angular,karma,tagged,symphony,message}, --convention {angular,karma,tagged,symphony,message}
94+
Selects a convention to be used for the commit.
95+
Required if there's no commiter.yml file.
96+
-d, --debug Toggles debug option
97+
7498
```
7599
76100
So, if you want to write a co-authored commit, you should use:
@@ -82,7 +106,7 @@ $ commit --co-author "foo bar doritous <foobar@douritos.com>"
82106
Or if you are using this for the first time in your project:
83107
84108
```bash
85-
$ commit --convention changelog
109+
$ commit --convention tagged
86110
```
87111
88112
To work even more smoothly, 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:
@@ -96,7 +120,7 @@ convention: karma # tag(context): commit message
96120
97121
# or
98122
99-
convention: changelog # TAG: commit message
123+
convention: tagged # TAG: commit message
100124
101125
# or
102126
@@ -121,9 +145,9 @@ Supported conventions available:
121145
122146
- angular
123147
- karma
124-
- changelog
148+
- tagged
125149
- symphony
126-
- a custom one that you may invent ;)
150+
- a custom one that you may create :)
127151
128152
## Troubleshooting
129153
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:

VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.3.4
1+
3.4.4

commit_helper/__main__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from .utils.text_utils import debug
66
from .utils.file_handler import handle_file_based_commit
77
from .utils.flag_commit_handler import convention_flag_handler
8+
# convention imports
9+
from .conventions.convention_help_handler import convention_help_handler
810

911

1012
def main():
@@ -18,7 +20,11 @@ def main():
1820

1921
debug('file_path', file_path, debug_mode)
2022

21-
if args.convention is not '':
23+
if args.show_convention_tags is True:
24+
convention_help_handler(file_path, args, debug_mode)
25+
return
26+
27+
elif args.convention is not '':
2228
convention_flag_handler(args, debug_mode)
2329
return
2430

commit_helper/conventions/atom.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
def atom_convention(tag, msg):
2+
tag = tag.lower()
3+
msg = msg.capitalize()
4+
composed_message = ":%s: %s\n" % (tag, msg)
5+
return composed_message
6+
7+
8+
atom_convention_help = \
9+
"""
10+
The atom convention:
11+
12+
:<tag>: <Message>
13+
<BREAK>
14+
<body>
15+
<BREAK>
16+
17+
---
18+
Tags:
19+
- art: when improving the format/structure of the code
20+
- racehorse: when improving performance
21+
- non-potable_water: when plugging memory leaks
22+
- memo: when writing docs
23+
- penguin: when fixing something on Linux
24+
- apple: when fixing something on macOS
25+
- checkered_flag: when fixing something on Windows
26+
- bug: when fixing a bug
27+
- fire: when removing code or files
28+
- green_heart: when fixing the CI build
29+
- white_check_mark: when adding tests
30+
- lock: when dealing with security
31+
- arrow_up: when upgrading dependencies
32+
- arrow_down: when downgrading dependencies
33+
- shirt: when removing linter warnings
34+
35+
---
36+
Message rules:
37+
- Use the present tense ("Add feature" not "Added feature")
38+
- Use the imperative mood ("Move cursor to..." not "Moves cursor to...")
39+
"""

commit_helper/conventions/changelog.py

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# dependencies imports
2+
from yaml import safe_load
3+
from yaml import YAMLError
4+
# convention imports
5+
from .atom import atom_convention_help
6+
from .tagged import tagged_convention_help
7+
from .karma_angular import karma_convention_help
8+
from .karma_angular import angular_convention_help
9+
from .symphony_cmf import symphony_convention_help
10+
# utils imports
11+
from commit_helper.utils.colors import HELP
12+
from commit_helper.utils.colors import RESET
13+
from commit_helper.utils.colors import MIN_ERROR
14+
from commit_helper.utils.text_utils import debug
15+
from commit_helper.utils.text_utils import print_help
16+
from commit_helper.utils.utils import dump_convention
17+
18+
19+
# TODO: test
20+
def convention_help_handler(file_path, args, debug_mode):
21+
if file_path.is_file() and args.convention is '':
22+
debug('Found file for help', str(file_path), debug_mode)
23+
with open(str(file_path)) as target:
24+
try:
25+
config = safe_load(target)
26+
convention = dump_convention(config)
27+
debug('Convention captured', convention, debug_mode)
28+
except YAMLError as err:
29+
print(err)
30+
31+
elif args.convention is not '':
32+
debug('Found convention in args', args, debug_mode)
33+
convention = args.convention
34+
35+
else:
36+
print(MIN_ERROR + 'No convention was specified!' + RESET)
37+
return
38+
39+
debug('convention captured for helper', convention, debug_mode)
40+
get_help_to_defined_convention(convention, debug_mode)
41+
42+
43+
# TODO: test
44+
def get_help_to_defined_convention(convention, debug_mode):
45+
debug('recieved convention for help catch', convention, debug_mode)
46+
if convention == 'angular':
47+
print_help(angular_convention_help)
48+
49+
elif convention == 'tagged':
50+
print_help(tagged_convention_help)
51+
52+
elif convention == 'karma':
53+
print_help(karma_convention_help)
54+
55+
elif convention == 'symphony':
56+
print_help(symphony_convention_help)
57+
58+
elif convention == 'atom':
59+
print_help(atom_convention_help)
60+
61+
else:
62+
print(MIN_ERROR + 'The chosen convention has no helper!' + RESET)
Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,60 @@
1-
def angular_convention(tag, msg, context):
1+
def karma_angular_convention(tag, msg, context):
22
tag = tag.lower()
33
if context == '':
44
composed_message = "%s: %s\n" % (tag, msg)
55
else:
66
composed_message = "%s(%s): %s\n" % (tag, context, msg)
77
return composed_message
8+
9+
10+
angular_convention_help = \
11+
"""
12+
The angular convention:
13+
14+
<tag>(<scope>): <message>
15+
<BLANK>
16+
<body>
17+
<BLANK>
18+
<footer>
19+
20+
----
21+
Tags:
22+
build: Changes that affect the build system or external dependencies
23+
ci: Changes to our CI configuration files and scripts
24+
docs: Documentation only changes
25+
feat: A new feature
26+
fix: A bug fix
27+
perf: A code change that improves performance
28+
refactor: A code change that neither fixes a bug nor adds a feature
29+
style: Changes that do not affect the meaning of the code
30+
test: Adding missing tests or correcting existing tests
31+
32+
---
33+
Optional fields:
34+
<scope> or <context>, <body> and <footer>
35+
"""
36+
37+
karma_convention_help = \
38+
"""
39+
The karma convention:
40+
41+
<tag>(<scope>): <message>
42+
<BLANK>
43+
<body>
44+
<BLANK>
45+
<footer>
46+
47+
---
48+
Tags:
49+
feat: New feature for the user, not a new feature for build script
50+
fix: Bug fix for the user, not a fix to a build script
51+
docs: Changes to the documentation
52+
style: Formatting, missing semi colons, etc; no production code change
53+
refactor: Refactoring production code, eg. renaming a variable
54+
test: Adding missing tests, refactoring tests; no product code change
55+
chore: Updating grunt tasks etc; no production code change
56+
57+
---
58+
Optional fields:
59+
<scope> or <context>, <body> and <footer>
60+
"""

commit_helper/conventions/symphony_cmf.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,26 @@ def symphony_convention(tag, msg):
22
tag = tag.capitalize()
33
composed = "[%s] %s\n" % (tag, msg)
44
return composed
5+
6+
7+
symphony_convention_help = \
8+
"""
9+
The symphony CMF convention:
10+
11+
[<Tag>] <message>
12+
<BLANK>
13+
<body>
14+
<BLANK>
15+
<changes>
16+
<BLANK>
17+
<footer>
18+
19+
---
20+
Obs.:
21+
Tag is not a tag similar to other commit conventions, it is actually a
22+
context to what was changed.
23+
24+
---
25+
Optionals:
26+
<body>, <changes>, <footer>
27+
"""
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
def tagged_convention(tag, msg):
2+
tag = tag.upper()
3+
composed_message = "%s: %s\n" % (tag, msg)
4+
return composed_message
5+
6+
7+
tagged_convention_help = \
8+
"""
9+
The tagged convention:
10+
11+
TAG: message
12+
<BLANK>
13+
<body>
14+
<BLANK>
15+
<footer>
16+
17+
---
18+
Tag usage:
19+
20+
ADD -> use for new files or methods
21+
FEAT -> for when adding a new feature
22+
DEL -> use for excluded files or methods
23+
CHR -> use for normal dev work and maintainance
24+
MERGE -> use for signal merges
25+
DOCS -> for documentation changes
26+
FIX -> use for solving bugs or failures in file
27+
REF -> use for when you rename a file
28+
STYLE -> use for fixing stylesheet errors
29+
TEST -> use for test files
30+
CI -> for that commit that aims for fix a build
31+
"""

commit_helper/utils/colors.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from colored import fg
22
from colored import attr
33

4-
INPUT_COLOR = fg(14)
5-
NOTIFY_COLOR = fg(15)
6-
DEBUG_COLOR = fg(244)
4+
# color wheel: https://pypi.org/project/colored/
5+
HELP = fg(227)
76
RESET = attr(0)
7+
MIN_ERROR = fg(160)
8+
INPUT_COLOR = fg(6)
9+
DEBUG_COLOR = fg(239)
10+
NOTIFY_COLOR = fg(14)

0 commit comments

Comments
 (0)