Skip to content

Add ReportWithOpeningFile reporter for issue #205 #210

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

nitsanavni
Copy link
Contributor

@nitsanavni nitsanavni commented May 28, 2025

Summary

• Implements ReportWithOpeningFile reporter that opens received files using system default viewer
• Provides cross-platform support for macOS (open), Windows (start), and Linux/Unix (xdg-open)

Fixes #205

Test plan

  • Unit tests cover all platform scenarios with mocking
  • Tests verify correct command generation for each OS
  • Tests confirm subprocess.call is invoked with proper arguments
  • Code formatted with black and follows existing patterns
  • All tests pass via tox

🤖 Generated with Claude Code

nitsanavni and others added 2 commits May 28, 2025 14:04
- Implements cross-platform file opening using system default viewer
- Supports macOS (open), Windows (start), and Linux/Unix (xdg-open)
- Includes comprehensive pytest-style tests with platform mocking
- Follows existing reporter patterns and naming conventions

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Copy link

sourcery-ai bot commented May 28, 2025

Reviewer's Guide

Introduces a new ReportWithOpeningFile reporter subclass that determines and invokes platform-specific commands to open a received file in the system default viewer, and adds unit tests mocking platform detection and subprocess calls to verify correct behavior on macOS, Windows, and Linux/Unix.

Sequence diagram for file reporting process

sequenceDiagram
    participant ClientCode
    participant RWOFile as ReportWithOpeningFile
    participant platform
    participant subprocess

    ClientCode->>RWOFile: report(received_path, approved_path)
    activate RWOFile
    RWOFile->>RWOFile: self.get_command(received_path)
    activate RWOFile
    RWOFile->>platform: system()
    platform-->>RWOFile: os_name
    RWOFile-->>RWOFile: command_array
    deactivate RWOFile
    RWOFile->>subprocess: call(command_array)
    subprocess-->>RWOFile: (OS dependent interaction)
    RWOFile-->>ClientCode: True
    deactivate RWOFile
Loading

Class diagram for ReportWithOpeningFile

classDiagram
    class Reporter {
        <<Interface>>
        report(received_path str, approved_path str) bool
    }
    class ReportWithOpeningFile {
        +get_command(received_path str) List~str~ $
        +report(received_path str, approved_path str) bool
    }
    Reporter <|-- ReportWithOpeningFile
Loading

File-Level Changes

Change Details Files
Add new ReportWithOpeningFile reporter
  • Define ReportWithOpeningFile subclass of Reporter
  • Implement get_command to select ‘open’, ‘start’, or ‘xdg-open’ based on platform.system()
  • Override report to build command array and invoke subprocess.call
  • Return True unconditionally from report
approvaltests/reporters/report_with_opening_file.py
Add unit tests for ReportWithOpeningFile
  • Mock platform.system for Darwin, Windows, Linux, and unknown values
  • Assert get_command returns the correct command list
  • Patch subprocess.call and verify report() invokes it with expected arguments
  • Ensure report() returns True
tests/reporters/test_report_with_opening_file.py

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

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.

Add a report by opening file
1 participant