Skip to content

Commit

Permalink
Fixes in capitalizing sentences. Clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
barseghyanartur committed Dec 27, 2019
1 parent 12905c7 commit f66e882
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 148 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ are used for versioning (schema follows below):
0.3.4 to 0.4).
- All backwards incompatible changes are mentioned in this document.

0.4.4
-----
2019-12-27

- Minor fixes.
- Add regex ignore patterns.

0.4.3
-----
2019-12-26
Expand Down
7 changes: 7 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ are used for versioning (schema follows below):
0.3.4 to 0.4).
- All backwards incompatible changes are mentioned in this document.

0.4.4
-----
2019-12-27

- Minor fixes.
- Add regex ignore patterns.

0.4.3
-----
2019-12-26
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
except:
readme = ''

version = '0.4.3'
version = '0.4.4'

setup(
name='matyan',
Expand Down
1 change: 1 addition & 0 deletions src/matyan/.matyan.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ exact: more
commit
prefix: more on
continue on
regex:
2 changes: 1 addition & 1 deletion src/matyan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
)

__title__ = 'matyan'
__version__ = '0.4.3'
__version__ = '0.4.4'
__author__ = 'Artur Barseghyan'
__copyright__ = '2019 Artur Barseghyan'
__license__ = 'GPL-2.0-only OR LGPL-2.1-or-later'
Expand Down
24 changes: 23 additions & 1 deletion src/matyan/auto_correct.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,46 @@


def capitalize_first_letter(value: AnyStr) -> AnyStr:
"""Capitalize first letter of the given string.
:param value:
:return:
"""
if len(value) == 0:
return value
return value[0].upper() + value[1:]


def unslugify(value: AnyStr) -> AnyStr:
"""Un-slugify. Opposite of slugify.
:param value:
:return:
"""
return capitalize_first_letter(value.replace('-', ' ')) if value else ''


def capitalize(value: AnyStr) -> AnyStr:
"""Capitalize.
Make each first letter of each first word in the sentence uppercase.
:param value:
:return:
"""
if len(value) == 0:
return value
return '. '.join(
[capitalize_first_letter(val.strip()) for val in value.split('.')]
[capitalize_first_letter(val.strip()) for val in value.split('. ')]
).strip()


def add_final_dot(value: AnyStr) -> AnyStr:
"""Add final dot at the end of the sentence.
:param value:
:return:
"""
if len(value) and value[-1].isalnum() and not value.endswith('.'):
return value + "."
return value
16 changes: 13 additions & 3 deletions src/matyan/labels.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
from configparser import SectionProxy
from typing import Union, Dict, AnyStr, Type, List
from typing import Dict, List

from .config import CONFIG

__author__ = 'Artur Barseghyan'
__copyright__ = '2019 Artur Barseghyan'
__license__ = 'GPL-2.0-only OR LGPL-2.1-or-later'
__all__ = (
# 'get_unreleased',
# 'get_unreleased_key',
'BRANCH_TYPE_OTHER',
'BRANCH_TYPES',
'get_all_branch_types',
'get_branch_types',
'get_ignore_commits_exact_words',
'get_ignore_commits_prefixes',
'get_ignore_commits_regex_patterns',
'get_other_branch_type',
'get_other_branch_type_key',
'get_settings',
Expand Down Expand Up @@ -105,6 +104,17 @@ def get_ignore_commits_prefixes() -> List[str]:
except KeyError:
return []


def get_ignore_commits_regex_patterns() -> List[str]:
"""Get ignore commits regex patterns.
:return:
"""
try:
return CONFIG['IgnoreCommits']['regex'].split('\n')
except KeyError:
return []

# Constants


Expand Down
64 changes: 9 additions & 55 deletions src/matyan/renderers/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
from typing import Dict, Type, List

from ..config import CONFIG
from ..labels import BRANCH_TYPES, BRANCH_TYPE_OTHER, UNRELEASED_LABEL, UNRELEASED
from ..labels import (
BRANCH_TYPE_OTHER,
BRANCH_TYPES,
UNRELEASED,
UNRELEASED_LABEL,
)
from ..logger import LOGGER
from ..registry import Registry

Expand Down Expand Up @@ -73,7 +78,6 @@ def render_changelog(self,
include_other: bool,
headings_only: bool,
fetch_description: bool) -> str:
# changelog = []
self.changelog = []
for branch_type, tickets in tree.items():
# Skip adding orphaned commits if explicitly asked not to.
Expand All @@ -87,12 +91,6 @@ def render_changelog(self,
if BRANCH_TYPES.get(branch_type):
# Feature type label `append_feature_type`
self.append_feature_type(branch_type)
# changelog.append(
# "\n**{}**{}".format(
# BRANCH_TYPES.get(branch_type),
# '\n' if branch_type == BRANCH_TYPE_OTHER else ''
# )
# )

# Add tickets
for ticket_number, ticket_data in tickets.items():
Expand All @@ -105,23 +103,12 @@ def render_changelog(self,
ticket_number,
ticket_data['title']
)
# changelog.append(
# "\n*{} {}*".format(
# ticket_number,
# ticket_data['title']
# )
# )

if fetch_description and ticket_data['description']:
# Description quote `append_ticket_description`
self.append_ticket_description(
ticket_data['description']
)
# changelog.append(
# "\n```\n{}\n```".format(
# ticket_data['description'].strip()
# )
# )

if headings_only:
continue
Expand All @@ -134,24 +121,15 @@ def render_changelog(self,
branch_type=branch_type,
counter=counter
)
# changelog.append(
# "{}- {} [{}]".format(
# '\n' if counter == 0 and branch_type != BRANCH_TYPE_OTHER else '',
# commit_data['title'],
# commit_data['author']
# )
# )
counter = counter + 1

# return '\n'.join(changelog)
return '\n'.join(self.changelog)

def render_releases_changelog(self,
releases_tree: dict,
include_other: bool,
headings_only: bool,
fetch_description: bool) -> str:
# changelog = []
self.changelog = []
for release, branches in releases_tree.items():
release_label = UNRELEASED_LABEL \
Expand All @@ -160,7 +138,6 @@ def render_releases_changelog(self,

# Release label `append_release`
self.append_release(release_label)
# changelog.append("\n### {}".format(release_label))

for branch_type, tickets in branches.items():

Expand All @@ -175,12 +152,6 @@ def render_releases_changelog(self,
# Feature type label `append_feature_type`
if BRANCH_TYPES.get(branch_type):
self.append_feature_type(branch_type)
# changelog.append(
# "\n**{}**{}".format(
# BRANCH_TYPES.get(branch_type),
# '\n' if branch_type == BRANCH_TYPE_OTHER else ''
# )
# )

# Add tickets
for ticket_number, ticket_data in tickets.items():
Expand All @@ -201,43 +172,26 @@ def render_releases_changelog(self,
ticket_number,
ticket_data['title']
)
# changelog.append(
# "\n*{} {}*".format(
# ticket_number,
# ticket_data['title']
# )
# )

if fetch_description and ticket_data['description']:
# Description quote `append_ticket_description`
self.append_ticket_description(
ticket_data['description']
)
# changelog.append(
# "\n```\n{}\n```".format(
# ticket_data['description'].strip()
# )
# )

if headings_only:
continue

counter = 0
for commit_hash, commit_data in ticket_data['commits'].items(): # NOQA
for commit_hash, commit_data \
in ticket_data['commits'].items():

# Commit text `append_commit_message`
self.append_commit_message(
commit_data=commit_data,
branch_type=branch_type,
counter=counter
)
# changelog.append(
# "{}- {} [{}]".format(
# '\n' if counter == 0 and branch_type != BRANCH_TYPE_OTHER else '',
# commit_data['title'],
# commit_data['author']
# )
# )
counter = counter + 1

# return '\n'.join(changelog)
return '\n'.join(self.changelog)
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*MSFT-1235 Deprecate old api*

- Update docs. [Artur Barseghyan]
- Deprecate API v 2. 0. [Artur Barseghyan]
- Deprecate API v 2.0. [Artur Barseghyan]

**Feature**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
##### MSFT-1235 Deprecate old api

- Update docs. [Artur Barseghyan]
- Deprecate API v 2. 0. [Artur Barseghyan]
- Deprecate API v 2.0. [Artur Barseghyan]

#### Feature

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ MSFT-1235 Deprecate old api
^^^^^^^^^^^^^^^^^^^^^^^^^^^

- Update docs. [Artur Barseghyan]
- Deprecate API v 2. 0. [Artur Barseghyan]
- Deprecate API v 2.0. [Artur Barseghyan]

Feature
~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion src/matyan/tests/output/generate-changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
##### MSFT-1235 Deprecate old api

- Update docs. [Artur Barseghyan]
- Deprecate API v 2. 0. [Artur Barseghyan]
- Deprecate API v 2.0. [Artur Barseghyan]
2 changes: 1 addition & 1 deletion src/matyan/tests/output/json-changelog-show-releases.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{'0.2': {'feature': {'MSFT-1238': {'commit_hash': 'c42ff7ed2e5b1a3c42ead2b81735397cefc554b8', 'commit_abbr': 'c42ff7e', 'date': '2019-11-17 20:50:49 +0000', 'ticket_number': 'MSFT-1238', 'branch_type': 'feature', 'slug': 'Token-authentication', 'title': 'Token authentication', 'description': None, 'commits': {'Update authentication docs.': {'commit_hash': '513e790ccf0a7f3024fb226b0c530e04528ff046', 'commit_abbr': '513e790', 'author': 'Artur Barseghyan', 'date': '2019-11-17 21:50:08 +0100', 'ticket_number': 'MSFT-1238', 'title': 'Update authentication docs.'}, 'Implement token authentication.': {'commit_hash': '7fbd3035ef40d0f311469ec88088266bc7d13f5c', 'commit_abbr': '7fbd303', 'author': 'Artur Barseghyan', 'date': '2019-11-17 21:49:49 +0100', 'ticket_number': 'MSFT-1238', 'title': 'Implement token authentication.'}}, 'release': '0.2'}, 'MSFT-1237': {'commit_hash': '2d799b037160961d7ebc6e552dfd63c60b155553', 'commit_abbr': '2d799b0', 'date': '2019-11-17 20:48:51 +0000', 'ticket_number': 'MSFT-1237', 'branch_type': 'feature', 'slug': 'Improve-document-sharing', 'title': 'Improve document sharing', 'description': None, 'commits': {'Improve document sharing. Add option to share via GDrive.': {'commit_hash': 'b54d3263c3d14cc77e73e730228ac064551145cc', 'commit_abbr': 'b54d326', 'author': 'Artur Barseghyan', 'date': '2019-11-17 21:48:04 +0100', 'ticket_number': 'MSFT-1237', 'title': 'Improve document sharing. Add option to share via GDrive.'}}, 'release': '0.2'}}}, '0.1': {'bugfix': {'MSFT-1236': {'commit_hash': '5d20c1b24c0dce57b8972250d09d417e41b6faf2', 'commit_abbr': '5d20c1b', 'date': '2019-11-17 20:46:22 +0000', 'ticket_number': 'MSFT-1236', 'branch_type': 'bugfix', 'slug': 'prevent-duplicate-postal-codes', 'title': 'Prevent duplicate postal codes', 'description': None, 'commits': {'Make postal code field unique for the country.': {'commit_hash': '4ee17c4126be93bb9d0ffd7b2370f180e7fd0056', 'commit_abbr': '4ee17c4', 'author': 'Artur Barseghyan', 'date': '2019-11-17 21:44:58 +0100', 'ticket_number': 'MSFT-1236', 'title': 'Make postal code field unique for the country.'}, 'Normalise postal codes for US addresses.': {'commit_hash': '47ddb712de58c88e0c0067ba63610c18af6d3815', 'commit_abbr': '47ddb71', 'author': 'Artur Barseghyan', 'date': '2019-11-17 21:44:32 +0100', 'ticket_number': 'MSFT-1236', 'title': 'Normalise postal codes for US addresses.'}, 'Normalise postal codes for German addresses.': {'commit_hash': 'b2e08fd1b52d7837d64250a3d2bf1fd1cdef7849', 'commit_abbr': 'b2e08fd', 'author': 'Artur Barseghyan', 'date': '2019-11-17 21:44:01 +0100', 'ticket_number': 'MSFT-1236', 'title': 'Normalise postal codes for German addresses.'}}, 'release': '0.1'}}, 'deprecation': {'MSFT-1235': {'commit_hash': 'd794c5aa297d3bf34fe20cb47b3e04a298915357', 'commit_abbr': 'd794c5a', 'date': '2019-11-17 20:42:47 +0000', 'ticket_number': 'MSFT-1235', 'branch_type': 'deprecation', 'slug': 'deprecate-old-api', 'title': 'Deprecate old api', 'description': None, 'commits': {'Update docs.': {'commit_hash': '7ab619cda816e714b66865fd8395af4ad591d080', 'commit_abbr': '7ab619c', 'author': 'Artur Barseghyan', 'date': '2019-11-17 21:42:22 +0100', 'ticket_number': 'MSFT-1235', 'title': 'Update docs.'}, 'Deprecate API v 2. 0.': {'commit_hash': 'a84a77fa712d7f4e1e018de2d9b0607943544877', 'commit_abbr': 'a84a77f', 'author': 'Artur Barseghyan', 'date': '2019-11-17 21:41:44 +0100', 'ticket_number': 'MSFT-1235', 'title': 'Deprecate API v 2. 0.'}}, 'release': '0.1'}}, 'feature': {'MSFT-1234': {'commit_hash': '5babfbe19a31a8386f52d730eccd4df60fb775dd', 'commit_abbr': '5babfbe', 'date': '2019-11-17 20:40:43 +0000', 'ticket_number': 'MSFT-1234', 'branch_type': 'feature', 'slug': 'car-type-suggester', 'title': 'Car type suggester', 'description': None, 'commits': {'Add insurance amount indication based on car weight.': {'commit_hash': 'd74a816dd27052fe1ffe61997513b94df8682af3', 'commit_abbr': 'd74a816', 'author': 'Artur Barseghyan', 'date': '2019-11-17 21:39:23 +0100', 'ticket_number': 'MSFT-1234', 'title': 'Add insurance amount indication based on car weight.'}, 'Initial car type suggester implementation.': {'commit_hash': 'a68119cb3b519b35b322aeb14f64c5b41810b39c', 'commit_abbr': 'a68119c', 'author': 'Artur Barseghyan', 'date': '2019-11-17 21:37:23 +0100', 'ticket_number': 'MSFT-1234', 'title': 'Initial car type suggester implementation.'}}, 'release': '0.1'}}, 'other': {None: {'commits': {'Readme.': {'commit_hash': '22dd2c07649bd783275e8ebeb3a4b565af9215a3', 'commit_abbr': '22dd2c0', 'author': 'Artur Barseghyan', 'date': '2019-11-17 21:36:27 +0100', 'ticket_number': None, 'title': 'Readme.'}}}}}}
{'0.2': {'feature': {'MSFT-1238': {'commit_hash': 'c42ff7ed2e5b1a3c42ead2b81735397cefc554b8', 'commit_abbr': 'c42ff7e', 'date': '2019-11-17 20:50:49 +0000', 'ticket_number': 'MSFT-1238', 'branch_type': 'feature', 'slug': 'Token-authentication', 'title': 'Token authentication', 'description': None, 'commits': {'Update authentication docs.': {'commit_hash': '513e790ccf0a7f3024fb226b0c530e04528ff046', 'commit_abbr': '513e790', 'author': 'Artur Barseghyan', 'date': '2019-11-17 21:50:08 +0100', 'ticket_number': 'MSFT-1238', 'title': 'Update authentication docs.'}, 'Implement token authentication.': {'commit_hash': '7fbd3035ef40d0f311469ec88088266bc7d13f5c', 'commit_abbr': '7fbd303', 'author': 'Artur Barseghyan', 'date': '2019-11-17 21:49:49 +0100', 'ticket_number': 'MSFT-1238', 'title': 'Implement token authentication.'}}, 'release': '0.2'}, 'MSFT-1237': {'commit_hash': '2d799b037160961d7ebc6e552dfd63c60b155553', 'commit_abbr': '2d799b0', 'date': '2019-11-17 20:48:51 +0000', 'ticket_number': 'MSFT-1237', 'branch_type': 'feature', 'slug': 'Improve-document-sharing', 'title': 'Improve document sharing', 'description': None, 'commits': {'Improve document sharing. Add option to share via GDrive.': {'commit_hash': 'b54d3263c3d14cc77e73e730228ac064551145cc', 'commit_abbr': 'b54d326', 'author': 'Artur Barseghyan', 'date': '2019-11-17 21:48:04 +0100', 'ticket_number': 'MSFT-1237', 'title': 'Improve document sharing. Add option to share via GDrive.'}}, 'release': '0.2'}}}, '0.1': {'bugfix': {'MSFT-1236': {'commit_hash': '5d20c1b24c0dce57b8972250d09d417e41b6faf2', 'commit_abbr': '5d20c1b', 'date': '2019-11-17 20:46:22 +0000', 'ticket_number': 'MSFT-1236', 'branch_type': 'bugfix', 'slug': 'prevent-duplicate-postal-codes', 'title': 'Prevent duplicate postal codes', 'description': None, 'commits': {'Make postal code field unique for the country.': {'commit_hash': '4ee17c4126be93bb9d0ffd7b2370f180e7fd0056', 'commit_abbr': '4ee17c4', 'author': 'Artur Barseghyan', 'date': '2019-11-17 21:44:58 +0100', 'ticket_number': 'MSFT-1236', 'title': 'Make postal code field unique for the country.'}, 'Normalise postal codes for US addresses.': {'commit_hash': '47ddb712de58c88e0c0067ba63610c18af6d3815', 'commit_abbr': '47ddb71', 'author': 'Artur Barseghyan', 'date': '2019-11-17 21:44:32 +0100', 'ticket_number': 'MSFT-1236', 'title': 'Normalise postal codes for US addresses.'}, 'Normalise postal codes for German addresses.': {'commit_hash': 'b2e08fd1b52d7837d64250a3d2bf1fd1cdef7849', 'commit_abbr': 'b2e08fd', 'author': 'Artur Barseghyan', 'date': '2019-11-17 21:44:01 +0100', 'ticket_number': 'MSFT-1236', 'title': 'Normalise postal codes for German addresses.'}}, 'release': '0.1'}}, 'deprecation': {'MSFT-1235': {'commit_hash': 'd794c5aa297d3bf34fe20cb47b3e04a298915357', 'commit_abbr': 'd794c5a', 'date': '2019-11-17 20:42:47 +0000', 'ticket_number': 'MSFT-1235', 'branch_type': 'deprecation', 'slug': 'deprecate-old-api', 'title': 'Deprecate old api', 'description': None, 'commits': {'Update docs.': {'commit_hash': '7ab619cda816e714b66865fd8395af4ad591d080', 'commit_abbr': '7ab619c', 'author': 'Artur Barseghyan', 'date': '2019-11-17 21:42:22 +0100', 'ticket_number': 'MSFT-1235', 'title': 'Update docs.'}, 'Deprecate API v 2.0.': {'commit_hash': 'a84a77fa712d7f4e1e018de2d9b0607943544877', 'commit_abbr': 'a84a77f', 'author': 'Artur Barseghyan', 'date': '2019-11-17 21:41:44 +0100', 'ticket_number': 'MSFT-1235', 'title': 'Deprecate API v 2.0.'}}, 'release': '0.1'}}, 'feature': {'MSFT-1234': {'commit_hash': '5babfbe19a31a8386f52d730eccd4df60fb775dd', 'commit_abbr': '5babfbe', 'date': '2019-11-17 20:40:43 +0000', 'ticket_number': 'MSFT-1234', 'branch_type': 'feature', 'slug': 'car-type-suggester', 'title': 'Car type suggester', 'description': None, 'commits': {'Add insurance amount indication based on car weight.': {'commit_hash': 'd74a816dd27052fe1ffe61997513b94df8682af3', 'commit_abbr': 'd74a816', 'author': 'Artur Barseghyan', 'date': '2019-11-17 21:39:23 +0100', 'ticket_number': 'MSFT-1234', 'title': 'Add insurance amount indication based on car weight.'}, 'Initial car type suggester implementation.': {'commit_hash': 'a68119cb3b519b35b322aeb14f64c5b41810b39c', 'commit_abbr': 'a68119c', 'author': 'Artur Barseghyan', 'date': '2019-11-17 21:37:23 +0100', 'ticket_number': 'MSFT-1234', 'title': 'Initial car type suggester implementation.'}}, 'release': '0.1'}}, 'other': {None: {'commits': {'Readme.': {'commit_hash': '22dd2c07649bd783275e8ebeb3a4b565af9215a3', 'commit_abbr': '22dd2c0', 'author': 'Artur Barseghyan', 'date': '2019-11-17 21:36:27 +0100', 'ticket_number': None, 'title': 'Readme.'}}}}}}
Loading

0 comments on commit f66e882

Please sign in to comment.