diff options
author | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-06-29 09:58:51 +0200 |
---|---|---|
committer | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-06-29 18:17:19 +0200 |
commit | 0b024ba6333041d5ffa21d67577ec85e53fc06fe (patch) | |
tree | 76cd983e9ad2c943af7069667355bc54ec34b446 /script | |
parent | 90612181b24025841ac8eb60c007adb6d041de29 (diff) | |
download | astroid-git-0b024ba6333041d5ffa21d67577ec85e53fc06fe.tar.gz |
Add patch version and minor version text automatically
Add tests for bump changelog for minor and major version
Diffstat (limited to 'script')
-rw-r--r-- | script/bump_changelog.py | 28 | ||||
-rw-r--r-- | script/test_bump_changelog.py | 82 |
2 files changed, 96 insertions, 14 deletions
diff --git a/script/bump_changelog.py b/script/bump_changelog.py index 30f46bc8..38f9ccb2 100644 --- a/script/bump_changelog.py +++ b/script/bump_changelog.py @@ -55,20 +55,19 @@ def get_next_version(version: str, version_type: VersionType) -> str: def get_next_versions(version: str, version_type: VersionType) -> List[str]: + if version_type == VersionType.PATCH: # "2.6.1" => ["2.6.2"] return [get_next_version(version, VersionType.PATCH)] if version_type == VersionType.MINOR: - assert version.endswith(".0"), f"{version} does not look like a minor version" # "2.6.0" => ["2.7.0", "2.6.1"] - next_minor_version = get_next_version(version, VersionType.MINOR) - next_patch_version = get_next_version(version, VersionType.PATCH) - return [next_minor_version, next_patch_version] - assert version.endswith(".0.0"), f"{version} does not look like a major version" - next_major_version = get_next_version(version, VersionType.MAJOR) - next_minor_version = get_next_version(next_major_version, VersionType.MINOR) - next_patch_version = get_next_version(next_major_version, VersionType.PATCH) - # "3.0.0" => ["3.1.0", "3.0.1"] + assert version.endswith(".0"), f"{version} does not look like a minor version" + else: + # "3.0.0" => ["3.1.0", "3.0.1"] + assert version.endswith(".0.0"), f"{version} does not look like a major version" + next_minor_version = get_next_version(version, VersionType.MINOR) + next_patch_version = get_next_version(version, VersionType.PATCH) + logging.debug(f"Getting the new version for {version} - {version_type.name}") return [next_minor_version, next_patch_version] @@ -99,12 +98,19 @@ def get_whats_new( return "\n".join(result) +def get_all_whats_new(version: str, version_type: VersionType) -> str: + result = "" + for version_ in get_next_versions(version, version_type=version_type): + result += get_whats_new(version_, add_date=True) + "\n" * 4 + return result + + def transform_content(content: str, version: str) -> str: version_type = get_version_type(version) next_version = get_next_version(version, version_type) old_date = get_whats_new(version, add_date=True) new_date = get_whats_new(version, add_date=True, change_date=True) - next_version_with_date = get_whats_new(next_version, add_date=True) + next_version_with_date = get_all_whats_new(version, version_type) do_checks(content, next_version, old_date, version, version_type) index = content.find(old_date) logging.debug(f"Replacing\n'{old_date}'\nby\n'{new_date}'\n") @@ -112,7 +118,7 @@ def transform_content(content: str, version: str) -> str: end_content = content[index:] content = content[:index] logging.debug(f"Adding:\n'{next_version_with_date}'\n") - content += next_version_with_date + "\n" * 4 + end_content + content += next_version_with_date + end_content return content diff --git a/script/test_bump_changelog.py b/script/test_bump_changelog.py index 5dfe7f60..ea587335 100644 --- a/script/test_bump_changelog.py +++ b/script/test_bump_changelog.py @@ -158,6 +158,82 @@ What's New in astroid 2.6.1? Release Date: 20""" new_content = transform_content(old_content, "2.6.1") - assert new_content.startswith( - expected_beginning - ), f"Wrong start for:'{new_content[:len(expected_beginning)]}'" + assert new_content[: len(expected_beginning)] == expected_beginning + + +def test_update_content_minor(): + old_content = """ +=================== +astroid's ChangeLog +=================== + +What's New in astroid 2.7.0? +============================ +Release Date: TBA +""" + expected_beginning = """ +=================== +astroid's ChangeLog +=================== + +What's New in astroid 2.8.0? +============================ +Release Date: TBA + + + +What's New in astroid 2.7.1? +============================ +Release Date: TBA + + + +What's New in astroid 2.7.0? +============================ +Release Date: 20""" + + new_content = transform_content(old_content, "2.7.0") + assert new_content[: len(expected_beginning)] == expected_beginning + + +def test_update_content_major(caplog): + caplog.set_level(logging.DEBUG) + old_content = """ +=================== +astroid's ChangeLog +=================== + +What's New in astroid 3.0.0? +============================ +Release Date: TBA + +What's New in astroid 2.7.1? +============================ +Release Date: 2020-04-03 + +What's New in astroid 2.7.0? +============================ +Release Date: 2020-04-01 +""" + expected_beginning = """ +=================== +astroid's ChangeLog +=================== + +What's New in astroid 3.1.0? +============================ +Release Date: TBA + + + +What's New in astroid 3.0.1? +============================ +Release Date: TBA + + + +What's New in astroid 3.0.0? +============================ +Release Date: 20""" + new_content = transform_content(old_content, "3.0.0") + assert new_content[: len(expected_beginning)] == expected_beginning |