Skip to content

Commit

Permalink
Update docs, add command for creating config file, minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
barseghyanartur committed Nov 17, 2019
1 parent 93638c5 commit 2570883
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 71 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,19 @@ are used for versioning (schema follows below):
0.3.4 to 0.4).
- All backwards incompatible changes are mentioned in this document.

0.3
---
2019-11-17

- Minor fixes.
- Add `matyan-create-config` command.

0.2
---
2019-11-17

0.1
---
2019-11-18
2019-11-17

- Initial release.
30 changes: 10 additions & 20 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ Prerequisites

Use cases and basic concepts
============================
`Matyan` does a good job generating changelog from Git commits. Think of DTAP
development, GitFlow-like concepts, JIRA (or similar tool for handling tickets
and reviewing pull requests).

How would you know it could be useful?
--------------------------------------
If the following applies to you, ``matyan`` could help:

- Project releases (tags) are numbered according to the
Expand All @@ -45,6 +39,7 @@ If the following applies to you, ``matyan`` could help:
branches) are protected.
- Direct commits to TAP branches are forbidden.
- All commits to TAP branches are made by pull requests.
- JIRA (or a similar tool) is used for handing project tickets.
- Pull requests are merged using GitHub or BitBucket web interface.

Sample use-case
Expand Down Expand Up @@ -204,6 +199,13 @@ Write to file
generate-changelog --show-releases 2>&1 | tee changelog.md
Create initial config file
--------------------------

.. code-block:: sh
matyan-create-config
Documentation
=============
Documentation is available on `Read the Docs
Expand All @@ -217,20 +219,8 @@ Latest stable version on PyPI:
pip install matyan
Or latest stable version from GitHub:

.. code-block:: sh
pip install https://github.com/barseghyanartur/matyan/archive/stable.tar.gz
Or latest stable version from BitBucket:

.. code-block:: sh
pip install https://bitbucket.org/barseghyanartur/matyan/get/stable.tar.gz
Usage examples
==============
Usage
=====
**Generate changelog:**

.. code-block:: sh
Expand Down
1 change: 1 addition & 0 deletions TODOS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ TODOS
+ Add output to file. Documented how to write to file instead.
- Add tests.
- Make it possible to provide a template for generated changelog file.
- Create initial config file.
13 changes: 12 additions & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,19 @@ are used for versioning (schema follows below):
0.3.4 to 0.4).
- All backwards incompatible changes are mentioned in this document.

0.3
---
2019-11-17

- Minor fixes.
- Add `matyan-create-config` command.

0.2
---
2019-11-17

0.1
---
2019-11-18
2019-11-17

- Initial release.
44 changes: 24 additions & 20 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ Prerequisites

Use cases and basic concepts
============================
`Matyan` does a good job generating changelog from Git commits. Think of DTAP
development, GitFlow-like concepts, JIRA (or similar tool for handling tickets
and reviewing pull requests).

How would you know it could be useful?
--------------------------------------
If the following applies to you, ``matyan`` could help:

- Project releases (tags) are numbered according to the
Expand All @@ -45,6 +39,7 @@ If the following applies to you, ``matyan`` could help:
branches) are protected.
- Direct commits to TAP branches are forbidden.
- All commits to TAP branches are made by pull requests.
- JIRA (or a similar tool) is used for handing project tickets.
- Pull requests are merged using GitHub or BitBucket web interface.

Sample use-case
Expand All @@ -67,6 +62,16 @@ Sample commits
~~~~~~~~~~~~~~
Consider the following commits into the dev branch:

*branch: bugfix/MSFT-1240-LinkedIn-authentication-failing*

- MSFT-1240 Fix package configuration.
- MSFT-1240 Update authentication pipeline.

*branch: deprecation/MSFT-1239-Deprecate-Python2*

- MSFT-1239 Deprecate Python2.
- MSFT-1238 Add initial MyPY setup.

*branch: feature/MSFT-1238-Token-authentication*

- MSFT-1238 Implement token authentication.
Expand Down Expand Up @@ -106,6 +111,10 @@ Releases have been made in the following way:

- Merged issues MSFT-1237 and MSFT-1238

*Yet unreleased features/branches*

- MSFT-1239 and

Sample changelog output
-----------------------
The generated change log would look as follows:
Expand Down Expand Up @@ -190,6 +199,13 @@ Write to file
generate-changelog --show-releases 2>&1 | tee changelog.md
Create initial config file
--------------------------

.. code-block:: sh
matyan-create-config
Documentation
=============
Documentation is available on `Read the Docs
Expand All @@ -203,20 +219,8 @@ Latest stable version on PyPI:
pip install matyan
Or latest stable version from GitHub:

.. code-block:: sh
pip install https://github.com/barseghyanartur/matyan/archive/stable.tar.gz
Or latest stable version from BitBucket:

.. code-block:: sh
pip install https://bitbucket.org/barseghyanartur/matyan/get/stable.tar.gz
Usage examples
==============
Usage
=====
**Generate changelog:**

.. code-block:: sh
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"Environment :: Web Environment",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Development Status :: 5 - Production/Stable",
"Development Status :: 3 - Alpha",
"Topic :: Internet",
"License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
"License :: OSI Approved :: GNU Lesser General Public License v2 or "
Expand All @@ -42,6 +42,7 @@
# Backups
'matyan-json-changelog = matyan.utils:json_changelog_cli',
'matyan-generate-changelog = matyan.utils:generate_changelog_cli',
'matyan-create-config = matyan.utils:create_config_file_cli',
]
},
include_package_data=True,
Expand Down
11 changes: 2 additions & 9 deletions src/matyan/config.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
import configparser
import os

from .helpers import project_dir

__author__ = 'Artur Barseghyan'
__copyright__ = '2019 Artur Barseghyan'
__license__ = 'GPL-2.0-only OR LGPL-2.0-or-later'
__all__ = (
'CONFIG',
'CONFIG_INI_PATH',
'project_dir',
)


CONFIG = configparser.ConfigParser()


def project_dir(base):
"""Absolute path to a file from current directory."""
return os.path.abspath(
os.path.join(os.path.dirname(__file__), base).replace('\\', '/')
)


CONFIG_INI_PATH = os.path.join(os.getcwd(), '.matyan.ini')

if not os.path.exists(CONFIG_INI_PATH):
Expand Down
15 changes: 15 additions & 0 deletions src/matyan/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os

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


def project_dir(base):
"""Absolute path to a file from current directory."""
return os.path.abspath(
os.path.join(os.path.dirname(__file__), base).replace('\\', '/')
)
43 changes: 24 additions & 19 deletions src/matyan/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@
import os
import re
import sys
from shutil import copyfile
from pprint import pprint
from typing import Union, Dict, AnyStr, Type, Any
import git
from git.exc import GitCommandError

from .patterns import (
REGEX_PATTERN_BRANCH_NAME,
REGEX_PATTERN_MERGED_BRANCH_NAME,
REGEX_PATTERN_COMMIT,
REGEX_PATTERN_COMMIT_LINE,
REGEX_PATTERN_TAG,
)
from .labels import (
get_all_branch_types,
get_other_branch_type,
Expand All @@ -26,6 +20,14 @@
get_unreleased_key_label,
get_ignore_commits_exact_words,
)
from .helpers import project_dir
from .patterns import (
REGEX_PATTERN_BRANCH_NAME,
REGEX_PATTERN_MERGED_BRANCH_NAME,
REGEX_PATTERN_COMMIT,
REGEX_PATTERN_COMMIT_LINE,
REGEX_PATTERN_TAG,
)

__author__ = 'Artur Barseghyan'
__copyright__ = '2019 Artur Barseghyan'
Expand Down Expand Up @@ -86,7 +88,6 @@ def get_logs(between: str = None) -> Dict[str, Any]:
upper = rev_list[0]
lower = rev_list[-1]
except GitCommandError as err:
import ipdb; ipdb.set_trace()
pass

# Merges log
Expand Down Expand Up @@ -242,7 +243,7 @@ def prepare_changelog(
try:
entry = json.loads(json_entry)
except json.decoder.JSONDecodeError:
continue # TODO: fix this
continue # TODO: fix this (when commit message contains " symbols)
merge_commit = True if ' ' in entry['merge'] else False
if merge_commit:
match = re.match(REGEX_PATTERN_MERGED_BRANCH_NAME, entry['title'])
Expand Down Expand Up @@ -308,7 +309,6 @@ def prepare_changelog(
'title': commit_message,
}
except:
# import ipdb; ipdb.set_trace()
# TODO: Anything here?
pass
else:
Expand Down Expand Up @@ -340,7 +340,6 @@ def prepare_releases_changelog(
releases = [UNRELEASED] + [tag for tag in logs['COMMIT_TAGS'].values()]
releases_tree = {tag: generate_empty_tree() for tag in releases}

# import ipdb; ipdb.set_trace()
cur_branch = None
cur_branch_type = None
branch_types = {}
Expand Down Expand Up @@ -388,14 +387,12 @@ def prepare_releases_changelog(
}
branch_types.update({ticket_number: branch_type})

# import ipdb; ipdb.set_trace()

# Now go through commits
for json_entry in filter(None, logs['LOG']):
try:
entry = json.loads(json_entry)
except json.decoder.JSONDecodeError:
continue # TODO: fix this
continue # TODO: fix this (when commit message contains " symbols)

merge_commit = True if ' ' in entry['merge'] else False
if merge_commit:
Expand Down Expand Up @@ -464,7 +461,6 @@ def prepare_releases_changelog(
'title': commit_message,
}
except:
# import ipdb; ipdb.set_trace()
# TODO: Anything here?
pass
else:
Expand Down Expand Up @@ -628,7 +624,6 @@ def generate_changelog_cli() -> Type[None]:
# Add tickets
for ticket_number, ticket_data in tickets.items():
if branch_type != BRANCH_TYPE_OTHER:
# import ipdb; ipdb.set_trace()
changelog.append(
"\n*{} {}*\n".format(ticket_number,
ticket_data['title'])
Expand All @@ -647,9 +642,19 @@ def generate_changelog_cli() -> Type[None]:
return '\n'.join(changelog)


def create_default_config_file():
"""Create default config file.
def create_config_file() -> bool:
"""Create config file.
:return:
"""
pass
source_filename = project_dir('.matyan.ini')
dest_filename = os.path.join(os.getcwd(), '.matyan.ini')
try:
copyfile(source_filename, dest_filename)
return True
except Exception as err:
return False


def create_config_file_cli():
return not create_config_file()

0 comments on commit 2570883

Please sign in to comment.