Skip to content

Commit

Permalink
Add text beatification (add final dot, capitalization)
Browse files Browse the repository at this point in the history
  • Loading branch information
barseghyanartur committed Nov 22, 2019
1 parent 00d148d commit 993f49a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ are used for versioning (schema follows below):
2019-11-22 (not yet released)

- Fixes in rendering logic.
- Added simple text beatification (capitalize, add final dot).

0.3.1
-----
Expand Down
26 changes: 26 additions & 0 deletions src/matyan/auto_correct.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from typing import AnyStr

__author__ = 'Artur Barseghyan'
__copyright__ = '2019 Artur Barseghyan'
__license__ = 'GPL-2.0-only OR LGPL-2.0-or-later'
__all__ = (
'add_final_dot',
'capitalize',
'unslugify',
)


def unslugify(value: AnyStr) -> AnyStr:
return value.replace('-', ' ').title() if value else ''


def capitalize(value: AnyStr) -> AnyStr:
if len(value) == 0:
return value
return '. '.join([val.strip().capitalize() for val in value.split('.')]).strip()


def add_final_dot(value: AnyStr) -> AnyStr:
if len(value) and value[-1].isalnum():
return value + "."
return value
10 changes: 10 additions & 0 deletions src/matyan/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import git
from git.exc import GitCommandError

from .auto_correct import add_final_dot, capitalize, unslugify
from .labels import (
get_all_branch_types,
get_branch_types,
Expand Down Expand Up @@ -310,6 +311,10 @@ def prepare_changelog(
ticket_number = ''
commit_message = entry['title'][:]

commit_message = unslugify(commit_message)
commit_message = capitalize(commit_message)
commit_message = add_final_dot(commit_message)

# Ignore the following messages
if commit_message.lower() in IGNORE_COMMITS_EXACT_WORDS:
continue
Expand Down Expand Up @@ -510,6 +515,11 @@ def prepare_releases_changelog(
ticket_number = ''
commit_message = entry['title'][:]


commit_message = unslugify(commit_message)
commit_message = capitalize(commit_message)
commit_message = add_final_dot(commit_message)

# Ignore the following messages
if commit_message.lower() in IGNORE_COMMITS_EXACT_WORDS:
continue
Expand Down

0 comments on commit 993f49a

Please sign in to comment.