Skip to content

Conversation

@odnashestaia
Copy link

@odnashestaia odnashestaia commented Oct 24, 2025

Summary by CodeRabbit

Release Notes

  • New Features
    • Added ability to create comments on issues and projects
    • Support for replying to existing comments within both issues and projects, enabling threaded conversations

@coderabbitai
Copy link

coderabbitai bot commented Oct 24, 2025

Walkthrough

Two manager classes now support creating comments on issues and projects via new create_comment methods. These execute CreateComment mutations, validate responses, invalidate relevant caches, and return Comment instances. Tests verify creation and replies. Refactoring and formatting changes preserve existing behavior.

Changes

Cohort / File(s) Summary
Manager comment creation
linear_api/managers/issue_manager.py, linear_api/managers/project_manager.py
Added public create_comment(...) methods to both managers. Methods build and execute CreateComment GraphQL mutations, validate responses, invalidate comment-related caches, and return Comment instances. Optional parent_id parameter enables reply functionality. Minor refactoring and formatting adjustments throughout.
Test coverage for comments
tests/test_issue_manager.py, tests/test_project_manager.py
Added test_create_comment_and_reply and test_create_comment_and_reply_project test functions to verify comment creation and replies on issues and projects respectively. Includes validation of comment IDs, bodies, and presence in parent entity comment lists. Minor formatting and assertion style normalization.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Manager
    participant GraphQL
    participant Cache
    participant Response

    Client->>Manager: create_comment(issue_id, body, parent_id)
    Manager->>Manager: Build CreateComment mutation
    Manager->>GraphQL: Execute mutation
    GraphQL-->>Response: Return comment data
    Manager->>Manager: Validate response
    Manager->>Cache: Invalidate comment cache
    Manager-->>Client: Return Comment instance
    
    Note over Manager,Cache: On reply: parent_id included<br/>in mutation payload
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

The changes introduce new GraphQL mutation logic and cache invalidation patterns across two manager classes, coupled with corresponding test coverage. While the implementations follow consistent patterns, each requires verification of correct mutation structure, response handling, and cache key invalidation. Test changes include data structure expectations that warrant careful review.

Poem

🐰 Hop, hop—comments now flow free,
On issues and projects, one, two, three,
Replies nestle beneath like carrots in soil,
The cache whispers thanks for the timely invalidation toil,
A burrow of features, complete and sublime!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "add create comment and reply to comment" directly and specifically relates to the main changes in the changeset. The PR adds a new create_comment() method to both IssueManager and ProjectManager classes that enables creating comments with optional reply functionality, along with corresponding tests. The title clearly conveys the primary objective—adding comment creation and reply capabilities—which a teammate scanning the commit history would immediately understand, and it avoids vague terms or generic language.
Docstring Coverage ✅ Passed Docstring coverage is 98.48% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link

@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: 0

🧹 Nitpick comments (1)
linear_api/managers/issue_manager.py (1)

752-798: LGTM! Comment creation logic is correct.

The create_comment method properly executes the GraphQL mutation, validates the response, invalidates the cache, and returns a Comment instance. The support for nested replies via parent_id is well-implemented.

Optional improvements:

  1. Address static analysis hints - Consider using str | None instead of implicit Optional for the parent_id parameter (line 753, PEP 484 style), and extract the error message to a constant (line 791).

  2. Reduce code duplication - The create_comment implementation in project_manager.py (lines 648-695) is nearly identical. Consider extracting common logic to a base class helper method that accepts the resource type (issue vs. project) as a parameter.

Example refactor for the base manager:

def _create_comment_for_resource(
    self, 
    resource_id: str, 
    body: str, 
    resource_type: str,  # "issueId" or "projectId"
    cache_name: str,     # "comments_by_issue" or "comments_by_project"
    parent_id: str | None = None
) -> Comment:
    mutation = """
    mutation CreateComment($input: CommentCreateInput!) {
      commentCreate(input: $input) {
        success
        comment {
          id
          body
          createdAt
          updatedAt
        }
      }
    }
    """
    
    input_vars = {"input": {"body": body, resource_type: resource_id}}
    if parent_id is not None:
        input_vars["input"]["parentId"] = parent_id
    
    response = self._execute_query(mutation, input_vars)
    
    if (
        not response
        or "commentCreate" not in response
        or not response["commentCreate"].get("comment")
    ):
        raise ValueError(f"Failed to create comment for {resource_type} {resource_id}")
    
    comment_data = response["commentCreate"]["comment"]
    self._cache_invalidate(cache_name, resource_id)
    
    return Comment(**comment_data)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7573c7e and efe901a.

📒 Files selected for processing (4)
  • linear_api/managers/issue_manager.py (25 hunks)
  • linear_api/managers/project_manager.py (23 hunks)
  • tests/test_issue_manager.py (7 hunks)
  • tests/test_project_manager.py (14 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
tests/test_issue_manager.py (2)
linear_api/domain/issue_models.py (1)
  • comments (189-201)
linear_api/managers/issue_manager.py (2)
  • create_comment (752-798)
  • get_comments (694-750)
tests/test_project_manager.py (4)
linear_api/domain/common_models.py (1)
  • Comment (23-30)
linear_api/domain/project_models.py (3)
  • LinearProject (146-409)
  • ProjectMilestone (34-41)
  • comments (247-259)
tests/test_integration.py (1)
  • client (22-31)
linear_api/managers/project_manager.py (3)
  • create (164-217)
  • create_comment (648-695)
  • get_comments (596-646)
linear_api/managers/project_manager.py (3)
linear_api/domain/common_models.py (1)
  • Comment (23-30)
linear_api/managers/base_manager.py (3)
  • _cache_invalidate (348-357)
  • _execute_query (48-64)
  • _handle_pagination (74-194)
linear_api/managers/issue_manager.py (4)
  • create (153-219)
  • update (222-311)
  • create_comment (752-798)
  • get (38-150)
linear_api/managers/issue_manager.py (4)
linear_api/domain/common_models.py (1)
  • Comment (23-30)
linear_api/domain/issue_models.py (5)
  • CustomerNeedResponse (406-418)
  • IssueRelation (396-403)
  • LinearAttachmentInput (72-83)
  • LinearIssue (86-310)
  • comments (189-201)
linear_api/managers/base_manager.py (3)
  • _handle_pagination (74-194)
  • _cache_set (318-330)
  • _cache_invalidate (348-357)
linear_api/managers/project_manager.py (2)
  • create_comment (648-695)
  • get (42-161)
🪛 Ruff (0.14.1)
linear_api/managers/project_manager.py

649-649: PEP 484 prohibits implicit Optional

Convert to T | None

(RUF013)


688-688: Avoid specifying long messages outside the exception class

(TRY003)

linear_api/managers/issue_manager.py

753-753: PEP 484 prohibits implicit Optional

Convert to T | None

(RUF013)


791-791: Avoid specifying long messages outside the exception class

(TRY003)

🔇 Additional comments (3)
linear_api/managers/project_manager.py (1)

648-695: LGTM! Project comment creation is correctly implemented.

The create_comment method for projects follows the same pattern as the issue version, properly handling GraphQL mutation execution, response validation, cache invalidation, and comment/reply creation.

As noted in the issue_manager.py review, there's an opportunity to refactor the common logic between this method and issue_manager.create_comment into a shared base class helper. The static analysis hints (RUF013 on line 649, TRY003 on line 688) also apply here.

tests/test_issue_manager.py (1)

335-361: Excellent test coverage for comment creation.

The test properly validates both top-level comment creation and nested replies, including verification that both comments appear in the retrieved list. This confirms the cache invalidation and comment retrieval work correctly.

tests/test_project_manager.py (1)

285-310: Great test coverage for project comment creation.

This test mirrors the issue comment test and properly validates the project comment creation and reply functionality, including verification of cache invalidation.

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.

1 participant