-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from Colin-b/develop
Release 0.5.0
- Loading branch information
Showing
14 changed files
with
1,212 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
repos: | ||
- repo: https://github.com/psf/black | ||
rev: master | ||
rev: 20.8b1 | ||
hooks: | ||
- id: black | ||
- id: black |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
from keepachangelog.version import __version__ | ||
from keepachangelog._changelog import to_dict | ||
from keepachangelog._changelog import to_dict, to_raw_dict, release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import re | ||
from typing import Tuple, Optional | ||
|
||
|
||
def contains_breaking_changes(unreleased: dict) -> bool: | ||
return "removed" in unreleased or "changed" in unreleased | ||
|
||
|
||
def only_contains_bug_fixes(unreleased: dict) -> bool: | ||
# unreleased contains at least 2 entries: version and release_date | ||
return "fixed" in unreleased and len(unreleased) == 3 | ||
|
||
|
||
def bump_major(version: str) -> str: | ||
major, *_ = to_semantic(version) | ||
return from_semantic(major + 1, 0, 0) | ||
|
||
|
||
def bump_minor(version: str) -> str: | ||
major, minor, _ = to_semantic(version) | ||
return from_semantic(major, minor + 1, 0) | ||
|
||
|
||
def bump_patch(version: str) -> str: | ||
major, minor, patch = to_semantic(version) | ||
return from_semantic(major, minor, patch + 1) | ||
|
||
|
||
def bump(unreleased: dict, version: str) -> str: | ||
if contains_breaking_changes(unreleased): | ||
return bump_major(version) | ||
if only_contains_bug_fixes(unreleased): | ||
return bump_patch(version) | ||
return bump_minor(version) | ||
|
||
|
||
def actual_version(changelog: dict) -> Optional[str]: | ||
versions = sorted(changelog.keys()) | ||
current_version = versions.pop() if versions else None | ||
while "unreleased" == current_version: | ||
current_version = versions.pop() if versions else None | ||
return current_version | ||
|
||
|
||
def guess_unreleased_version(changelog: dict) -> Tuple[Optional[str], str]: | ||
unreleased = changelog.get("unreleased", {}) | ||
if not unreleased or len(unreleased) < 3: | ||
raise Exception( | ||
"Release content must be provided within changelog Unreleased section." | ||
) | ||
|
||
version = actual_version(changelog) | ||
return version, bump(unreleased, version) | ||
|
||
|
||
# Semantic versioning pattern should match version like 1.2.3" | ||
version_pattern = re.compile(r"^(\d+)\.(\d+)\.(\d+)$") | ||
|
||
|
||
def to_semantic(version: Optional[str]) -> Tuple[int, int, int]: | ||
if not version: | ||
return 0, 0, 0 | ||
|
||
match = version_pattern.fullmatch(version) | ||
if match: | ||
return int(match.group(1)), int(match.group(2)), int(match.group(3)) | ||
|
||
raise Exception(f"{version} is not following semantic versioning.") | ||
|
||
|
||
def from_semantic(major: int, minor: int, patch: int) -> str: | ||
return f"{major}.{minor}.{patch}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
maintainer="Colin Bounouar", | ||
maintainer_email="[email protected]", | ||
url="https://colin-b.github.io/keepachangelog/", | ||
description="Convert changelog into dict.", | ||
description="Manipulate keep a changelog files.", | ||
long_description=long_description, | ||
long_description_content_type="text/markdown", | ||
download_url="https://pypi.org/project/keepachangelog/", | ||
|
@@ -30,6 +30,7 @@ | |
"Programming Language :: Python :: 3.6", | ||
"Programming Language :: Python :: 3.7", | ||
"Programming Language :: Python :: 3.8", | ||
"Programming Language :: Python :: 3.9", | ||
"Topic :: Software Development :: Build Tools", | ||
], | ||
keywords=["changelog", "CHANGELOG.md", "markdown"], | ||
|
Oops, something went wrong.