Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process snippet only once #26

Merged
merged 1 commit into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .snippets/25.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## Process snippet only once
<!--
type: bugfix
scope: all
affected: all
-->

A snippet is now only added once to the changelog, even if it has been touched or modified again at a later point in the commit history timeline.
7 changes: 6 additions & 1 deletion snippets2changelog/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ def snippets(self) -> Iterator[Tuple[Commit, Path]]:
# self._logger.debug(f"collected_snippets: {collected_snippets}, looking for {self.snippets_folder}")
# collected_snippets: [PosixPath('.snippets/3.md')], looking for .snippets

# remember which snippets have already been visited to avoid processing
# it twice in case it has been touched or modified at a later point
processed_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():
Expand All @@ -113,7 +117,8 @@ def snippets(self) -> Iterator[Tuple[Commit, Path]]:
self._logger.warning(f"file {self.snippets_folder / file} is a match")
yield (commit, self.snippets_folder / file)
"""
if Path(file) in collected_snippets:
if Path(file) in collected_snippets and Path(file) not in processed_snippets:
# self._logger.debug(f"file {file} is a match")
# file .snippets/3.md is a match
processed_snippets.append(Path(file))
yield (commit, Path(file))
Loading