-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db4f2df
commit c3535bd
Showing
14 changed files
with
327 additions
and
55 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
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
## Introduce snippets | ||
<!-- | ||
type: breaking | ||
scope: all | ||
affected: all | ||
--> | ||
|
||
### Added | ||
- `ChangelogCreator` class to render new changelog from snippets and existing base changelog | ||
- New `changelog-generator changelog` CLI interface available and documented | ||
- `SnippetCollector` to provide iterable of snippets found in specified folder, sorted by the appearance in the Git history (oldest first) | ||
- Template for single changelog entry | ||
- Template for complete rendered and updated changelog | ||
|
||
### Changed | ||
#### Breaking | ||
- `SnippetCreator` class has no `file_name` init parameter anymore | ||
- `content` property renamed to `parsed_content` | ||
- `parse` function takes `file_name` parameter | ||
- `parsed_content` gets resetted with every new `parse(file_name)` call | ||
- `_required_keys` renamed to `_required_parser_keys` | ||
- `SnippetCreator` class has no `file_name` and `content` init parameter anymore | ||
- `snippets_file` property removed | ||
- `content` property renamed to `rendered_content` | ||
- `render` function takes `content` parameter and returns `None` | ||
- `create` function takes `file_name` parameter | ||
|
||
#### Other | ||
- `changelog2version` moved from dev dependency to package dependency | ||
- Create changelog from snippets in GitHub workflow before creating the python package | ||
|
||
### Fixed | ||
- Sorted package dependencies in `pyproject.toml` | ||
- Ignore all `.venv*` directories |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#!/usr/bin/env python3 | ||
|
||
"""Snippets collector""" | ||
|
||
from collections.abc import Iterator | ||
from pathlib import Path | ||
|
||
from git import Commit, GitCmdObjectDB, Repo, Submodule, TagReference | ||
from git.refs.head import Head | ||
|
||
|
||
class CollectorError(Exception): | ||
"""Base class for exceptions in this module.""" | ||
|
||
pass | ||
|
||
|
||
class HistoryWalker(object): | ||
"""docstring for HistoryWalker""" | ||
|
||
def __init__( | ||
self, repo: Path, search_parent_directories: bool = True, branch_only: bool = True | ||
) -> None: | ||
if repo.exists(): | ||
try: | ||
self._repo = Repo(repo, search_parent_directories=search_parent_directories) | ||
except Exception as e: | ||
raise CollectorError(e) | ||
else: | ||
raise CollectorError(f"Given repo folder '{repo}' does not exist") | ||
|
||
# limit amount of commits to crawl to a positive number | ||
self._max_count = None | ||
self._branch_only = branch_only | ||
|
||
@property | ||
def repo_root(self) -> Path: | ||
return Path(self._repo.working_dir) | ||
|
||
@property | ||
def branch_name(self) -> Head: | ||
return self._repo.active_branch | ||
|
||
@property | ||
def tags(self) -> list[TagReference]: | ||
return sorted(self._repo.tags, key=lambda t: t.commit.committed_datetime) | ||
|
||
def commits(self) -> Iterator[Commit]: | ||
kwargs = dict() | ||
|
||
if self._branch_only: | ||
# Collect the commits on this branch only | ||
# aka ignore commits on other branches | ||
kwargs["first-parent"] = True | ||
|
||
# latest commit is first element | ||
for ele in self._repo.iter_commits( | ||
rev=self.branch_name, | ||
max_count=self._max_count, | ||
**kwargs, | ||
): | ||
yield ele | ||
|
||
|
||
class SnippetCollector(HistoryWalker): | ||
"""docstring for SnippetCollector""" | ||
|
||
def __init__(self, snippets_folder: Path, file_extension: str = "md", **kwargs) -> None: | ||
if snippets_folder.exists(): | ||
self._snippets_folder = snippets_folder | ||
else: | ||
raise CollectorError(f"Given snippets folder '{snippets_folder}' does not exist") | ||
|
||
HistoryWalker.__init__(self, repo=self._snippets_folder, **kwargs) | ||
self._file_extension = file_extension | ||
|
||
@property | ||
def snippets_folder(self) -> Path: | ||
return self._snippets_folder | ||
|
||
def all_snippet_files(self) -> Iterator[Path]: | ||
"""Get all potential snippet files from the snippets folder""" | ||
for file in self._snippets_folder.iterdir(): | ||
if file.is_file() and (file.suffix == ".{}".format(self._file_extension)): | ||
yield file | ||
|
||
def snippets(self) -> Iterator[tuple[Commit, Path]]: | ||
collected_snippets = list(self.all_snippet_files()) | ||
|
||
# nice chaos :) | ||
# close to midnight, stop now or the problem of tomorrow will catch you | ||
|
||
# self._logger.debug(f"Repo root: {self.repo_root}") | ||
# changelog-generator/ | ||
|
||
# self._logger.debug(f"collected_snippets: {collected_snippets}, looking for {self.snippets_folder}") | ||
# collected_snippets: [PosixPath('.snippets/3.md')], looking for .snippets | ||
|
||
# use reversed to have oldest commit as first element | ||
for idx, commit in reversed(list(enumerate(self.commits()))): | ||
for file in commit.stats.files.keys(): | ||
# self._logger.debug(f"{idx}: {commit}, looking for file: {file} in {collected_snippets}") | ||
# 0: b768d6983432b730d81b34d125a4bbefb0a66525, looking for file: .snippets/3.md in [PosixPath('.snippets/3.md')] | ||
# self._logger.debug(Path(file) in collected_snippets) | ||
# True | ||
""" | ||
if self.snippets_folder / file in collected_snippets: | ||
self._logger.warning(f"file {self.snippets_folder / file} is a match") | ||
yield (commit, self.snippets_folder / file) | ||
""" | ||
if Path(file) in collected_snippets: | ||
# self._logger.debug(f"file {file} is a match") | ||
# file .snippets/3.md is a match | ||
yield (commit, Path(file)) |
Oops, something went wrong.