Skip to content

Commit

Permalink
Change: Change ChangelogBuilder to allow passing Version instances
Browse files Browse the repository at this point in the history
Make typing of ChangelogBuilder flexible by allowing to pass all kind of
classes that implement `__str__` als version arguments. This allows for
passing a Version instance to these methods too.
  • Loading branch information
bjoernricks authored and y0urself committed Mar 14, 2023
1 parent afd5a36 commit cd095ef
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions pontos/changelog/conventional_commits.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@


import re
from abc import abstractmethod
from datetime import date
from pathlib import Path
from typing import Dict, List, Optional, Union
from typing import Dict, List, Optional, Protocol, Union, runtime_checkable

import tomlkit

Expand All @@ -37,6 +38,13 @@
"""


@runtime_checkable
class SupportsStr(Protocol):
@abstractmethod
def __str__(self) -> str:
pass


class ChangelogBuilder:
"""
Creates Changelog from conventional commits using the git log
Expand Down Expand Up @@ -92,8 +100,8 @@ def __init__(
def create_changelog(
self,
*,
last_version: Optional[str] = None,
next_version: Optional[str] = None,
last_version: Optional[SupportsStr] = None,
next_version: Optional[SupportsStr] = None,
) -> str:
"""
Create a changelog
Expand All @@ -116,8 +124,8 @@ def create_changelog_file(
self,
output: Union[str, Path],
*,
last_version: Optional[str] = None,
next_version: Optional[str] = None,
last_version: Optional[SupportsStr] = None,
next_version: Optional[SupportsStr] = None,
) -> None:
"""
Create a changelog and write the changelog to a file
Expand All @@ -142,7 +150,7 @@ def _get_first_commit(self) -> str:
git = Git()
return git.rev_list("HEAD", max_parents=0, abbrev_commit=True)[0]

def _get_git_log(self, last_version: Optional[str]) -> List[str]:
def _get_git_log(self, last_version: Optional[SupportsStr]) -> List[str]:
"""Getting the git log for the next version.
Requires the fitting branch to be checked out
Expand Down Expand Up @@ -209,8 +217,8 @@ def _sort_commits(self, commits: List[str]) -> Dict[str, List[str]]:

def _build_changelog(
self,
last_version: Optional[str],
next_version: Optional[str],
last_version: Optional[SupportsStr],
next_version: Optional[SupportsStr],
commit_dict: Dict[str, List[str]],
) -> str:
"""
Expand Down

0 comments on commit cd095ef

Please sign in to comment.