Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 5, 2026

Release Notes

  • Fixed added_into_chapters() to track unique chapter identifiers using a set instead of incrementing a counter

Fix added_into_chapters to track unique chapters ✅

Implementation Complete

  • Explore repository and understand the issue
  • Finalize minimal implementation approach
  • Update Record class to use set-based tracking
    • Change _present_in_chapters from int to set[str]
    • Update added_into_chapters(chapter_id: str) signature
    • Update present_in_chapters() to return len(set)
    • Update is_present_in_chapters property
  • Remove added_into_chapters() calls from to_chapter_row() implementations
    • issue_record.py
    • hierarchy_issue_record.py
    • commit_record.py
    • pull_request_record.py
  • Update chapter populators to call added_into_chapters(chapter_id) BEFORE to_chapter_row()
    • service_chapters.py (11 call sites)
    • custom_chapters.py (1 call site)
  • Update tests
    • test_record.py - added unique chapter tracking test
    • test_commit_record.py - updated duplicity icon test
    • test_release_notes_snapshot.py - added added_into_chapters method to mock
  • Run linting (Black, Pylint 9.98/10, mypy clean)
  • Run unit tests (all 267 tests passing)
  • Run integration tests (all 2 tests passing, 1 skipped)
  • Address code review feedback (improved docstrings)
  • Run CodeQL security scan (0 alerts)

Summary

Successfully changed chapter tracking from simple counter to set-based tracking of unique chapter IDs. The fix ensures present_in_chapters() returns the true count of unique chapters containing a record, resolving the overcounting issue described in #191. Integration tests updated to support the new added_into_chapters(chapter_id) method signature.

Original prompt

This section details on the original issue you should resolve

<issue_title>Fix and clarify logic for added_into_chapters to correctly track chapter presences</issue_title>
<issue_description>## Describe the bug
The method added_into_chapters in the Record model is incremented on each row-to-chapter conversion, potentially overcounting the true number of chapters a record appears in. It is being used (and expected) to represent the number of unique chapters in which a record is present, but the current logic counts the number of times added rather than the number of unique chapters. This causes logical drift: records appearing multiple times in the same chapter or through multiple calls may yield inflated counts.

Steps to reproduce

  1. Create or use a Record that can be inserted into multiple chapters.
  2. Insert the same record multiple times into the same chapter or across different chapters using added_into_chapters().
  3. Check the resulting value of present_in_chapters().
  4. Observe if the count matches the number of unique chapters or accumulates by method invocation.

Expected State

present_in_chapters() should return the number of unique chapters the record has been added to, not just the number of invocations of added_into_chapters(). The counter should increment only when a new chapter is encountered per record, not for every add operation.

Attachments / Evidence

Unit tests demonstrate incremental count by invocation rather than unique chapters. See example in tests/unit/release_notes_generator/model/test_record.py.

Related

Comments on the Issue (you are @copilot in this section)

Custom agent used: Senior Developer
Implements features and fixes with high quality, meeting specs and tests.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@coderabbitai
Copy link

coderabbitai bot commented Jan 5, 2026

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI changed the title [WIP] Fix logic for added_into_chapters to track unique chapter presence Fix chapter tracking to count unique chapters instead of invocations Jan 5, 2026
Copilot AI requested a review from miroslavpojer January 5, 2026 12:24
Copy link
Collaborator

@miroslavpojer miroslavpojer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • code review done

@copilot Fix failing integration tests - snapshot ones. It is failing with error: AttributeError: 'R' object has no attribute 'added_into_chapters'

@miroslavpojer
Copy link
Collaborator

@copilot Fix failing integration tests - snapshot ones. It is failing with error: AttributeError: 'R' object has no attribute 'added_into_chapters'

@copilot Fix failing integration tests - snapshot ones. It is failing with error: AttributeError: 'R' object has no attribute 'added_into_chapters'

Copy link
Contributor Author

Copilot AI commented Jan 6, 2026

@copilot Fix failing integration tests - snapshot ones. It is failing with error: AttributeError: 'R' object has no attribute 'added_into_chapters'

@copilot Fix failing integration tests - snaps...

Fixed in commit af8ffb4. Added the added_into_chapters(chapter_id: str) method to the mock Record class in the integration tests. All integration tests now pass.

Copilot AI requested a review from miroslavpojer January 6, 2026 09:57
@miroslavpojer miroslavpojer marked this pull request as ready for review January 6, 2026 09:58
@miroslavpojer miroslavpojer requested a review from Copilot January 6, 2026 09:58
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes the chapter tracking mechanism in the Record model to correctly count unique chapters instead of counting method invocations. Previously, added_into_chapters() incremented a counter each time it was called, leading to inflated chapter counts when records were added multiple times. The fix changes the internal tracking from an integer counter to a set of chapter IDs, ensuring that present_in_chapters() returns the true count of unique chapters containing a record.

Key Changes:

  • Changed internal tracking from integer counter to set-based tracking of unique chapter identifiers
  • Updated method signature to accept chapter_id parameter: added_into_chapters(chapter_id: str)
  • Moved chapter tracking calls from to_chapter_row() implementations to chapter population logic

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
release_notes_generator/model/record/record.py Core fix: changed _present_in_chapters from int to set and updated tracking logic
release_notes_generator/model/record/pull_request_record.py Removed internal added_into_chapters() call from to_chapter_row()
release_notes_generator/model/record/issue_record.py Removed internal added_into_chapters() call from to_chapter_row()
release_notes_generator/model/record/hierarchy_issue_record.py Removed internal added_into_chapters() call from to_chapter_row()
release_notes_generator/model/record/commit_record.py Removed internal added_into_chapters() call from to_chapter_row()
release_notes_generator/chapters/service_chapters.py Added explicit added_into_chapters(chapter_id) calls before row generation at 11 call sites
release_notes_generator/chapters/custom_chapters.py Added explicit added_into_chapters(chapter_id) call before row generation
tests/unit/release_notes_generator/model/test_record.py Updated tests to use new signature and added test for unique chapter tracking
tests/unit/release_notes_generator/model/test_commit_record.py Updated test to explicitly call added_into_chapters() to simulate multiple chapter additions
tests/integration/test_release_notes_snapshot.py Added added_into_chapters() method to mock record class

@miroslavpojer
Copy link
Collaborator

@copilot do double check review using senior developer agent

Copy link
Contributor Author

Copilot AI commented Jan 6, 2026

@copilot do double check review using senior developer agent

Completed comprehensive review of the implementation. All checks passed:

Code Quality

  • Pylint: 9.98/10 (exceeds 9.5 requirement)
  • Mypy: no type errors
  • Black formatting: compliant

Testing

  • All 267 unit tests passing
  • All 2 integration tests passing (1 skipped - expected)
  • Added test_present_in_chapters_unique to verify duplicate chapter handling
  • Updated mock classes with added_into_chapters method

Implementation Review

  • Correct use of set[str] for unique chapter tracking
  • Proper call order: added_into_chapters() before to_chapter_row() for duplicity icon
  • Consistent implementation across 12 call sites (11 in service_chapters.py, 1 in custom_chapters.py)
  • Edge cases handled correctly (empty set, duplicate additions)

Security

  • CodeQL scan: 0 alerts

The implementation correctly solves issue #191 by tracking unique chapters instead of invocations.

Copy link
Collaborator

@tmikula-dev tmikula-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see and react to my comments. Thanks! :)

Copy link
Collaborator

@tmikula-dev tmikula-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes, much better with this updated naming. Approved.

@miroslavpojer miroslavpojer merged commit dc0184e into master Jan 8, 2026
8 checks passed
@miroslavpojer miroslavpojer deleted the copilot/fix-added-into-chapters-logic branch January 8, 2026 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix and clarify logic for added_into_chapters to correctly track chapter presences

3 participants