Skip to content

WIP Development #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
08e4564
add(documentation): added docstrings to all functions
andre-filho Jun 14, 2019
3bcad7d
Merge branch 'master' of github.com:andre-filho/commit-helper into de…
andre-filho Aug 10, 2019
a56592c
fix(codestyle): pycodestyle
andre-filho Aug 12, 2019
10f810d
ci(codeclimate): fixes the coverage reporter version
andre-filho Oct 4, 2019
2fdb679
Pin argh to latest version 0.31.3
pyup-bot Dec 1, 2024
6c550e3
Pin atomicwrites to latest version 1.4.1
pyup-bot Dec 1, 2024
d13b5ae
Pin attrs to latest version 24.2.0
pyup-bot Dec 1, 2024
9c45d30
Pin certifi to latest version 2024.8.30
pyup-bot Dec 1, 2024
419c1f2
Pin chardet to latest version 5.2.0
pyup-bot Dec 1, 2024
50c897d
Pin colored to latest version 2.2.4
pyup-bot Dec 1, 2024
487cccd
Pin coverage to latest version 7.6.8
pyup-bot Dec 1, 2024
429bc7c
Pin idna to latest version 3.10
pyup-bot Dec 1, 2024
adb6d3d
Pin more-itertools to latest version 10.5.0
pyup-bot Dec 1, 2024
4470e8b
Pin pip to latest version 24.3.1
pyup-bot Dec 1, 2024
b6e8421
Pin py to latest version 1.11.0
pyup-bot Dec 1, 2024
f87032b
Pin pycodestyle to latest version 2.12.1
pyup-bot Dec 1, 2024
76a0e3c
Pin pytest to latest version 8.3.4
pyup-bot Dec 1, 2024
56554ea
Pin pytest-cov to latest version 6.0.0
pyup-bot Dec 1, 2024
2455450
Pin requests to latest version 2.32.3
pyup-bot Dec 1, 2024
749bea5
Pin setuptools to latest version 75.6.0
pyup-bot Dec 1, 2024
4818059
Pin six to latest version 1.16.0
pyup-bot Dec 1, 2024
0da5fb9
Pin urllib3 to latest version 2.2.3
pyup-bot Dec 1, 2024
291c058
Pin watchdog to latest version 6.0.0
pyup-bot Dec 1, 2024
5d37494
Pin wheel to latest version 0.45.1
pyup-bot Dec 1, 2024
99fd5b1
Pin twine to latest version 6.0.1
pyup-bot Dec 1, 2024
a37a25c
deps: updates dependencies to resume dev
andre-filho Jul 17, 2025
75ef135
Merge branch 'pyup-scheduled-update-2024-12-01' of github.com:andre-f…
andre-filho Jul 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions commit_helper/__main__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
# dependencies imports
from pathlib import Path
# utils imports

from .utils.utils import parser_cli
from .utils.text_utils import debug
from .utils.file_handler import handle_file_based_commit
from .utils.file_handler import get_file_path
from .utils.flag_commit_handler import convention_flag_handler
# convention imports

from .conventions.convention_help_handler import convention_help_handler


def main():
"""
Main function. Called by CLI.
"""
parser = parser_cli()
args = parser.parse_args()
debug_mode = args.debug
Expand All @@ -21,11 +23,11 @@ def main():

debug('file_path', file_path, debug_mode)

if args.show_convention_tags is True:
if args.show_convention_tags == True:
convention_help_handler(file_path, args, debug_mode)
return

elif args.convention is not '':
elif args.convention != '':
convention_flag_handler(args, debug_mode)
return

Expand Down
6 changes: 6 additions & 0 deletions commit_helper/conventions/atom.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
def atom_convention(tag, msg):
"""
Formats the commit following the atom convention format:
The atom convention:

:<tag as emoticon>: <Message>
"""
tag = tag.lower()
msg = msg.capitalize()
composed_message = ":%s: %s\n" % (tag, msg)
Expand Down
12 changes: 8 additions & 4 deletions commit_helper/conventions/convention_help_handler.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# dependencies imports
from yaml import safe_load
from yaml import YAMLError
# convention imports

from .atom import atom_convention_help
from .tagged import tagged_convention_help
from .karma_angular import karma_convention_help
from .karma_angular import angular_convention_help
from .symphony_cmf import symphony_convention_help
# utils imports
from commit_helper.utils.colors import HELP

from commit_helper.utils.colors import RESET
from commit_helper.utils.colors import MIN_ERROR
from commit_helper.utils.text_utils import debug
Expand All @@ -18,6 +16,9 @@

# TODO: test
def convention_help_handler(file_path, args, debug_mode):
"""
Handles the user's help request.
"""
if file_path.is_file() and args.convention is '':
debug('Found file for help', str(file_path), debug_mode)
with open(str(file_path)) as target:
Expand All @@ -42,6 +43,9 @@ def convention_help_handler(file_path, args, debug_mode):

# TODO: test
def get_help_to_defined_convention(convention, debug_mode):
"""
Prints the help menu to the base conventions.
"""
debug('recieved convention for help catch', convention, debug_mode)
if convention == 'angular':
print_help(angular_convention_help)
Expand Down
5 changes: 4 additions & 1 deletion commit_helper/conventions/custom_convention.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# custom commits are only acceptable when you have a config file
from commit_helper.utils.text_utils import debug
from commit_helper.utils.text_utils import get_context


# custom commits are only acceptable when you have a config file
def custom_convention(tag, message, config_file, debug_mode):
"""
Formats the given arguments to make a custom commit message.
"""
debug('tag', tag, debug_mode)
debug('message', message, debug_mode)
debug('pattern from file', config_file['commit_pattern'], debug_mode)
Expand Down
6 changes: 6 additions & 0 deletions commit_helper/conventions/karma_angular.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
def karma_angular_convention(tag, msg, context):
"""
Handles the formatting for both karma and angular conventions.

Convention structure:
<tag>(<scope>): <message>
"""
tag = tag.lower()
if context == '':
composed_message = "%s: %s\n" % (tag, msg)
Expand Down
3 changes: 3 additions & 0 deletions commit_helper/conventions/no_convention.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@


def just_message(msg=''):
"""
Formats the message to capitalize.
"""
if msg == '':
message = str(input(INPUT_COLOR + "commit message: " + RESET))
else:
Expand Down
6 changes: 6 additions & 0 deletions commit_helper/conventions/symphony_cmf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
def symphony_convention(tag, msg):
"""
Formats the commit following the symphony convention.

The symphony CMF convention:
[<Tag>] <message>
"""
tag = tag.capitalize()
composed = "[%s] %s\n" % (tag, msg)
return composed
Expand Down
6 changes: 6 additions & 0 deletions commit_helper/conventions/tagged.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
def tagged_convention(tag, msg):
"""
Formats the convention following the tag convention.

The tagged convention:
<TAG>: <message>
"""
tag = tag.upper()
composed_message = "%s: %s\n" % (tag, msg)
return composed_message
Expand Down
12 changes: 10 additions & 2 deletions commit_helper/utils/file_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@
from pathlib import Path
from yaml import safe_load
from yaml import YAMLError
# utils imports

from .text_utils import debug
from .text_utils import notify
from .text_utils import get_text
from .utils import gen_co_author
from .utils import dump_convention
from .utils import validate_commiter_file
from .utils import handle_conventioned_commit
# conventions imports

from commit_helper.conventions.no_convention import just_message
from commit_helper.conventions.custom_convention import custom_convention


def handle_file_based_commit(file_path, debug_mode, args):
"""
Function that handles all the logic involved in commits with previous
configuration file.
"""
with open(str(file_path), 'r') as stream:
try:
config = safe_load(stream)
Expand Down Expand Up @@ -48,6 +52,10 @@ def handle_file_based_commit(file_path, debug_mode, args):


def get_file_path(): # pragma: no cover
"""
Searchs on the folder the program was called if there is a commiter.yml
or a commit-helper.yml file and returns it's path if exists.
"""
commiter = Path('commiter.yml')
commit_h = Path('commit-helper.yml')

Expand Down
8 changes: 5 additions & 3 deletions commit_helper/utils/flag_commit_handler.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# dependencies imports
from os import system
# utils imports

from .text_utils import debug
from .utils import create_file
from .utils import gen_co_author
from .utils import handle_conventioned_commit
# conventions imports

from commit_helper.conventions.no_convention import just_message


def convention_flag_handler(args, debug_mode):
"""
Handles the commit configuration and creation through flags.
"""
convention = str(args.convention)
debug('convention flag', convention, debug_mode)
commit_message = ''
Expand Down
25 changes: 25 additions & 0 deletions commit_helper/utils/text_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,69 @@


def get_text():
"""
Gets the input for both tag and message.
"""
tag = str(input(INPUT_COLOR + 'type the tag: ' + RESET))
msg = str(input(INPUT_COLOR + 'type the commit message: ' + RESET)).lower()
return tag, msg


def get_context():
"""
Gets the input for the commit context and formats it to lowercase.
"""
context = str(input(INPUT_COLOR + 'type the context: ' + RESET) or '')
context.lower()
return context


def sanitize_as_empty_string(string):
"""
Checks if arg is None and returns it as an empty string.
"""
if string is None:
return ''
return string


def notify(message):
"""
Colored formatted print for notifications.
"""
print(NOTIFY_COLOR + str(message) + RESET)


def debug(message, value, show=False):
"""
Colored formatted print for debugging.
"""
if show:
mid = 'DEBUG: ' + str(message) + ' ~> ' + str(value)
print(DEBUG_COLOR + mid + RESET)


def print_help(message):
"""
Colored formatted print for help menus.
"""
print(HELP + str(message) + RESET)


def handle_tag_message_args(tag='', message=''):
"""
Checks if args are empty strings, if so it calls the get_text function.
"""
if tag + message is not '':
return tag, message
return get_text()


def handle_context_arg(context=''):
"""
Checks if context is empty and if it is calls a input function to get the
context.
"""
if context is not '':
return context
return get_context()
Loading