Skip to content

Commit

Permalink
process snippet only once, fixes #25
Browse files Browse the repository at this point in the history
  • Loading branch information
brainelectronics committed Oct 12, 2024
1 parent 3a6e13d commit f1b2c52
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
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))

0 comments on commit f1b2c52

Please sign in to comment.