Skip to content

Introduce printer module#52

Merged
leynos merged 4 commits intomainfrom
codex/introduce-printer-module-for-printing-helpers
Aug 3, 2025
Merged

Introduce printer module#52
leynos merged 4 commits intomainfrom
codex/introduce-printer-module-for-printing-helpers

Conversation

@leynos
Copy link
Copy Markdown
Owner

@leynos leynos commented Jul 31, 2025

Summary

  • move printing helpers into printer module
  • document printer functions with examples
  • restrict reviews module to fetching helpers only

Testing

  • make fmt
  • make lint
  • make test

https://chatgpt.com/codex/tasks/task_e_688be428f84c8322986c38c04790b8b4

Summary by Sourcery

Extract printing logic into a dedicated printer module, relocate all comment/thread/review printing functions there, remove them from main.rs and reviews.rs, and update imports and tests to use the new module.

Enhancements:

  • Add printer module to house functions for formatting and printing review comments, review threads, and reviews with termimad syntax highlighting.
  • Document all printer functions with usage examples and module-level documentation.

Chores:

  • Remove obsolete printing helpers from main.rs and reviews.rs to restrict the reviews module to fetching logic.
  • Update imports and tests to reference printing functions from the new printer module.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Jul 31, 2025

Reviewer's Guide

This PR refactors the printing logic by extracting all printing helpers into a new printer module (with documentation and examples), removes printing code from main.rs and reviews.rs, and updates imports to use the new module.

Class diagram for the new printer module

classDiagram
    class printer {
        +write_comment_body(out, skin, comment)
        +write_comment(out, skin, comment)
        +write_thread(out, skin, thread)
        +print_reviews(skin, reviews)
        +write_review(out, skin, review)
    }
    class ReviewComment
    class ReviewThread
    class PullRequestReview
    class MadSkin
    printer --> ReviewComment
    printer --> ReviewThread
    printer --> PullRequestReview
    printer --> MadSkin
Loading

Class diagram showing reviews module after refactor

classDiagram
    class reviews {
        +latest_reviews(reviews)
    }
    class printer {
        +write_review(out, skin, review)
        +print_reviews(skin, reviews)
    }
    reviews ..> printer : uses (for printing)
    reviews --> PullRequestReview
Loading

Class diagram showing main.rs printing usage after refactor

classDiagram
    class main {
    }
    class printer {
        +write_comment_body(out, skin, comment)
        +write_review(out, skin, review)
        +write_thread(out, skin, thread)
    }
    main ..> printer : uses printing helpers
Loading

File-Level Changes

Change Details Files
Extract printing helpers into a dedicated printer module with docs and examples
  • Define write_comment_body, write_comment, write_thread, write_review, print_reviews in new module
  • Add doc comments with usage examples for each function
  • Import termimad and collapse_details in printer functions
src/printer/mod.rs
Remove printing implementations from main.rs and reviews.rs to isolate logic
  • Delete write_comment_body, write_comment, write_thread from main.rs
  • Delete write_review and print_reviews from reviews.rs
src/main.rs
src/reviews.rs
Update imports and tests to reference the new printer module
  • Change use statements in main.rs tests to pull functions from printer module
  • Adjust references to write_review and other helpers accordingly
src/main.rs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jul 31, 2025

Warning

Rate limit exceeded

@leynos has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 2 minutes and 15 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 324a42b and e648ecd.

📒 Files selected for processing (1)
  • src/printer/mod.rs (1 hunks)

Summary by CodeRabbit

  • Refactor

    • Improved separation between data retrieval and terminal output, moving all formatting and printing of review comments and threads into a dedicated module.
    • Updated internal documentation to reflect a narrower focus on data retrieval.
    • Streamlined code for clarity and maintainability.
  • Style

    • Minor syntax improvements for code clarity without affecting behaviour.

No changes to the user interface or core features are visible.

Walkthrough

Delegate all review comment and thread printing logic from src/main.rs and src/reviews.rs into a new printer module. Remove related formatting and output functions from the main and reviews modules, updating imports and usage. Consolidate all terminal output responsibilities for review comments, threads, and reviews within src/printer/mod.rs.

Changes

Cohort / File(s) Change Summary
Printer Module Introduction
src/printer/mod.rs
Add new module encapsulating all formatting and printing logic for review comments, threads, and reviews.
Main Module Refactor
src/main.rs
Remove inline comment/thread printing functions and related imports; import and use new printer module.
Reviews Module Cleanup
src/reviews.rs
Remove all terminal output and formatting logic; update documentation and imports to reflect new focus.
HTML Module Minor Refactor
src/html.rs
Simplify conditional in find_summary_text using matches! macro without altering functionality.

Sequence Diagram(s)

sequenceDiagram
    participant Main
    participant Printer
    participant Reviews

    Main->>Reviews: Fetch review data
    Main->>Printer: write_thread(thread) / print_reviews(reviews)
    Printer-->>Main: Formatted output to terminal
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Poem

Out from main, the printers leap,
Where threads and comments used to sleep.
Reviews now shine in modules new,
Formatting logic, clear in view.
The code is tidier, output bright—
Refactor done, the future’s light!
🖨️✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/introduce-printer-module-for-printing-helpers

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey @leynos - I've reviewed your changes and found some issues that need to be addressed.

  • Propagate errors from skin.write_text_on instead of ignoring them so render failures aren’t silently dropped.
  • Consider extracting the repeated author‐banner formatting into a shared helper to DRY up write_comment_body and write_review.
  • You might make print_reviews accept a Write impl instead of locking stdout directly to increase flexibility and testability.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Propagate errors from `skin.write_text_on` instead of ignoring them so render failures aren’t silently dropped.
- Consider extracting the repeated author‐banner formatting into a shared helper to DRY up `write_comment_body` and `write_review`.
- You might make `print_reviews` accept a `Write` impl instead of locking stdout directly to increase flexibility and testability.

## Individual Comments

### Comment 1
<location> `src/printer/mod.rs:118` </location>
<code_context>
+/// print_reviews(&MadSkin::default(), &[review]);
+/// ```
+pub fn print_reviews(skin: &MadSkin, reviews: &[PullRequestReview]) {
+    for r in reviews {
+        if let Err(e) = write_review(std::io::stdout().lock(), skin, r) {
+            eprintln!("error printing review: {e}");
+        }
</code_context>

<issue_to_address>
Locking stdout for each review may impact performance.

Locking stdout once before the loop and reusing the handle would improve efficiency and prevent output interleaving in multithreaded scenarios.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
pub fn print_reviews(skin: &MadSkin, reviews: &[PullRequestReview]) {
    for r in reviews {
        if let Err(e) = write_review(std::io::stdout().lock(), skin, r) {
            eprintln!("error printing review: {e}");
        }
=======
pub fn print_reviews(skin: &MadSkin, reviews: &[PullRequestReview]) {
    let stdout = std::io::stdout();
    let mut handle = stdout.lock();
    for r in reviews {
        if let Err(e) = write_review(&mut handle, skin, r) {
            eprintln!("error printing review: {e}");
        }
>>>>>>> REPLACE

</suggested_fix>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/printer/mod.rs Outdated
@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Aug 3, 2025

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Aug 3, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🔭 Outside diff range comments (1)
src/main.rs (1)

1-1224: Decompose this file - it exceeds the 400-line limit.

This file contains 1224 lines, violating the coding guideline that "Files must not exceed 400 lines in length". Extract meaningful components into separate modules to reduce complexity and improve maintainability.

Consider decomposing by:

  • Moving diff formatting functions to a separate module
  • Extracting reference parsing logic
  • Moving data structures to a types module
  • Separating GraphQL query logic
♻️ Duplicate comments (1)
src/printer/mod.rs (1)

132-141: Performance concern resolved.

This function now accepts a writer parameter, allowing the caller to handle stdout locking once rather than locking for each review. This addresses the performance concern from previous reviews.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c3c5a4f and c688d80.

📒 Files selected for processing (3)
  • src/html.rs (1 hunks)
  • src/main.rs (3 hunks)
  • src/printer/mod.rs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit Inference Engine (AGENTS.md)

**/*.rs: Every module must begin with a module level (//!) comment explaining the module's purpose and utility.
Document public APIs using Rustdoc comments (///) so documentation can be generated with cargo doc.
Place function attributes after doc comments.
Do not use return in single-line functions.
Use predicate functions for conditional criteria with more than two branches.
Prefer immutable data and avoid unnecessary mut bindings.
Handle errors with the Result type instead of panicking where feasible.
Prefer semantic error enums: Derive std::error::Error (via the thiserror crate) for any condition the caller might inspect, retry, or map to an HTTP status.
Use an opaque error only at the app boundary: Use eyre::Report for human-readable logs; these should not be exposed in public APIs.
Never export the opaque type from a library: Convert to domain enums at API boundaries, and to eyre only in the main main() entrypoint or top-level async task.
Clippy warnings MUST be disallowed.
Fix any warnings emitted during tests in the code itself rather than silencing them.
Where a function is too long, extract meaningfully named helper functions adhering to separation of concerns and CQRS.
Where a function has too many parameters, group related parameters in meaningfully named structs.
Where a function is returning a large error consider using Arc to reduce the amount of data returned.
Write unit and behavioural tests for new functionality. Run both before and after making any change.
Avoid unsafe code unless absolutely necessary and document any usage clearly.
Lints must not be silenced except as a last resort.
Lint rule suppressions must be tightly scoped and include a clear reason.
Prefer expect over allow.
Prefer .expect() over .unwrap().
Use concat!() to combine long string literals rather than escaping newlines with a backslash.

Files:

  • src/html.rs
  • src/main.rs
  • src/printer/mod.rs

⚙️ CodeRabbit Configuration File

**/*.rs: * Seek to keep the cyclomatic complexity of functions no more than 12.

  • Adhere to single responsibility and CQRS

  • Place function attributes after doc comments.

  • Do not use return in single-line functions.

  • Move conditionals with >2 branches into a predicate function.

  • Avoid unsafe unless absolutely necessary.

  • Every module must begin with a //! doc comment that explains the module's purpose and utility.

  • Comments and docs must follow en-GB-oxendict (-ize / -our) spelling and grammar

  • Lints must not be silenced except as a last resort.

    • #[allow] is forbidden.
    • Only narrowly scoped #[expect(lint, reason = "...")] is allowed.
    • No lint groups, no blanket or file-wide suppression.
    • Include FIXME: with link if a fix is expected.
  • Use rstest fixtures for shared setup and to avoid repetition between tests.

  • Replace duplicated tests with #[rstest(...)] parameterised cases.

  • Prefer mockall for mocks/stubs.

  • Prefer .expect() over .unwrap()

  • Ensure that any API or behavioural changes are reflected in the documentation in docs/

  • Ensure that any completed roadmap steps are recorded in the appropriate roadmap in docs/

  • Files must not exceed 400 lines in length

    • Large modules must be decomposed
    • Long match statements or dispatch tables should be decomposed by domain and collocated with targets
    • Large blocks of inline data (e.g., test fixtures, constants or templates) must be moved to external files and inlined at compile-time or loaded at run-time.

Files:

  • src/html.rs
  • src/main.rs
  • src/printer/mod.rs
🔇 Additional comments (11)
src/html.rs (1)

68-72: LGTM! Improved pattern matching syntax.

The matches! macro provides better readability for this pattern match with guard condition.

src/main.rs (4)

11-11: LGTM! Good modularisation.

Adding the printer module improves separation of concerns by extracting all printing logic.


15-16: LGTM! Imports updated correctly.

The import changes properly reflect the module restructuring, delegating printing responsibilities to the printer module.


566-570: Excellent performance improvement with stdout locking.

Locking stdout once and reusing the handle prevents output interleaving and improves efficiency compared to locking for each review.


767-768: LGTM! Test imports updated appropriately.

The test imports correctly reference the new printer module functions.

src/printer/mod.rs (6)

1-5: Excellent module documentation.

The module-level documentation clearly explains the purpose and benefits of separating printing logic for testability.


12-20: LGTM! Clean helper function.

The write_author_line function provides good abstraction for consistent author formatting across different contexts.


38-53: Well-documented and structured function.

Good use of collapse_details for HTML preprocessing and appropriate error handling with anyhow::Result.


70-79: LGTM! Clear separation of concerns.

The function properly delegates diff formatting to the existing format_comment_diff function and handles the comment body separately.


99-114: Excellent logic for diff deduplication.

The implementation correctly shows the diff only once for the first comment whilst ensuring all subsequent comments and URLs are displayed.


156-172: LGTM! Consistent formatting approach.

The review formatting follows the same pattern as comment formatting with proper HTML detail collapsing and markdown rendering.

Comment thread src/printer/mod.rs
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (2)
src/printer/mod.rs (2)

116-141: Address the performance concern raised in previous reviews.

The current implementation locks stdout for each review, which impacts performance and may cause output interleaving in multithreaded scenarios.

The performance issue identified in the past review comment remains valid. Lock stdout once before the loop and reuse the handle.


174-268: Test coverage addresses most scenarios but could be expanded.

The existing tests cover basic formatting, author handling, HTML detail collapsing, and error propagation. However, the previous review comment suggesting more comprehensive coverage for different review states and scenarios remains relevant.

Expand test coverage to include different review states, reviews with and without authors, HTML detail collapsing behaviour, and error handling scenarios as suggested in the previous review.

Additionally, add tests for the write_comment and write_thread functions to ensure complete coverage of the module's public API:

#[test]
fn write_comment_includes_diff_and_body() {
    let comment = ReviewComment {
        diff_hunk: "@@ -1 +1 @@\n-old\n+new".into(),
        body: "Good change".into(),
        author: Some(User { login: "reviewer".into() }),
        url: "https://example.com/comment".into(),
        ..Default::default()
    };
    let skin = MadSkin::default();
    let mut buf = Vec::new();
    write_comment(&mut buf, &skin, &comment).expect("write comment");
    let out = String::from_utf8(buf).expect("utf8");
    assert!(out.contains("@@"));
    assert!(out.contains("reviewer"));
    assert!(out.contains("Good change"));
}

#[test]
fn write_thread_shows_diff_only_once() {
    let comments = vec![
        ReviewComment {
            diff_hunk: "@@ -1 +1 @@\n-old\n+new".into(),
            body: "First comment".into(),
            url: "https://example.com/1".into(),
            ..Default::default()
        },
        ReviewComment {
            diff_hunk: "@@ -1 +1 @@\n-old\n+new".into(),
            body: "Second comment".into(),
            url: "https://example.com/2".into(),
            ..Default::default()
        }
    ];
    let thread = ReviewThread {
        comments: CommentConnection { nodes: comments, ..Default::default() },
        ..Default::default()
    };
    let skin = MadSkin::default();
    let mut buf = Vec::new();
    write_thread(&mut buf, &skin, &thread).expect("write thread");
    let out = String::from_utf8(buf).expect("utf8");
    // Diff should appear only once
    assert_eq!(out.matches("@@").count(), 1);
    assert!(out.contains("First comment"));
    assert!(out.contains("Second comment"));
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c688d80 and 324a42b.

📒 Files selected for processing (1)
  • src/printer/mod.rs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit Inference Engine (AGENTS.md)

**/*.rs: Every module must begin with a module level (//!) comment explaining the module's purpose and utility.
Document public APIs using Rustdoc comments (///) so documentation can be generated with cargo doc.
Place function attributes after doc comments.
Do not use return in single-line functions.
Use predicate functions for conditional criteria with more than two branches.
Prefer immutable data and avoid unnecessary mut bindings.
Handle errors with the Result type instead of panicking where feasible.
Prefer semantic error enums: Derive std::error::Error (via the thiserror crate) for any condition the caller might inspect, retry, or map to an HTTP status.
Use an opaque error only at the app boundary: Use eyre::Report for human-readable logs; these should not be exposed in public APIs.
Never export the opaque type from a library: Convert to domain enums at API boundaries, and to eyre only in the main main() entrypoint or top-level async task.
Clippy warnings MUST be disallowed.
Fix any warnings emitted during tests in the code itself rather than silencing them.
Where a function is too long, extract meaningfully named helper functions adhering to separation of concerns and CQRS.
Where a function has too many parameters, group related parameters in meaningfully named structs.
Where a function is returning a large error consider using Arc to reduce the amount of data returned.
Write unit and behavioural tests for new functionality. Run both before and after making any change.
Avoid unsafe code unless absolutely necessary and document any usage clearly.
Lints must not be silenced except as a last resort.
Lint rule suppressions must be tightly scoped and include a clear reason.
Prefer expect over allow.
Prefer .expect() over .unwrap().
Use concat!() to combine long string literals rather than escaping newlines with a backslash.

Files:

  • src/printer/mod.rs

⚙️ CodeRabbit Configuration File

**/*.rs: * Seek to keep the cyclomatic complexity of functions no more than 12.

  • Adhere to single responsibility and CQRS

  • Place function attributes after doc comments.

  • Do not use return in single-line functions.

  • Move conditionals with >2 branches into a predicate function.

  • Avoid unsafe unless absolutely necessary.

  • Every module must begin with a //! doc comment that explains the module's purpose and utility.

  • Comments and docs must follow en-GB-oxendict (-ize / -our) spelling and grammar

  • Lints must not be silenced except as a last resort.

    • #[allow] is forbidden.
    • Only narrowly scoped #[expect(lint, reason = "...")] is allowed.
    • No lint groups, no blanket or file-wide suppression.
    • Include FIXME: with link if a fix is expected.
  • Use rstest fixtures for shared setup and to avoid repetition between tests.

  • Replace duplicated tests with #[rstest(...)] parameterised cases.

  • Prefer mockall for mocks/stubs.

  • Prefer .expect() over .unwrap()

  • Ensure that any API or behavioural changes are reflected in the documentation in docs/

  • Ensure that any completed roadmap steps are recorded in the appropriate roadmap in docs/

  • Files must not exceed 400 lines in length

    • Large modules must be decomposed
    • Long match statements or dispatch tables should be decomposed by domain and collocated with targets
    • Large blocks of inline data (e.g., test fixtures, constants or templates) must be moved to external files and inlined at compile-time or loaded at run-time.

Files:

  • src/printer/mod.rs
🔇 Additional comments (5)
src/printer/mod.rs (5)

1-10: Module documentation and imports look excellent.

The module-level documentation clearly explains the purpose and separation of concerns. Import organisation follows standard Rust conventions with good use of the crate prefix for internal modules.


22-53: Function implementation follows best practices.

The documentation is comprehensive with a practical example, parameter handling is correct, and error propagation using anyhow::Result is appropriate. The use of collapse_details for preprocessing comment bodies is well-integrated.


55-79: Function correctly combines diff formatting with comment body output.

The implementation properly delegates to format_comment_diff and write_comment_body, maintaining separation of concerns. Error handling is consistent throughout.


81-114: Thread printing logic correctly handles the diff-once requirement.

The implementation elegantly uses an iterator to print the first comment with its diff, then subsequent comments without the diff. URL printing after each comment provides good traceability.


143-172: Review formatting function is well-structured.

The function correctly formats the review state as a suffix, handles optional authors appropriately, and applies HTML detail collapsing consistently with other functions.

Comment thread src/printer/mod.rs
@leynos leynos merged commit 3ed7a3a into main Aug 3, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant