Skip to content

Conversation

@NarayanBavisetti
Copy link
Collaborator

@NarayanBavisetti NarayanBavisetti commented Dec 1, 2024

chore:

  • this pull request adds functionality to track and save version histories of issue descriptions.

Summary by CodeRabbit

  • New Features

    • Introduced a new asynchronous task for handling issue versioning upon partial updates.
    • Added a new IssueVersion entity to enhance issue management functionality.
  • Bug Fixes

    • Improved data handling in the log_issue_version method to ensure accurate timestamps and efficient processing of related entity IDs.
  • Chores

    • Streamlined import statements by removing redundancies for better code clarity.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 1, 2024

Walkthrough

The changes introduce a new asynchronous task, issue_version_task, which is called within the partial_update method of the IssueViewSet class to manage issue versioning upon updates. Additionally, the IssueVersion class is added to the models, and modifications are made to streamline the handling of issue versions, including adjustments to the creation process and data handling within the log_issue_version method.

Changes

File Path Change Summary
apiserver/plane/app/views/issue/base.py Added import for issue_version_task and invoked it in partial_update method with relevant parameters.
apiserver/plane/bgtasks/issue_version_task.py Introduced issue_version_task function with parameters for issue versioning and error handling.
apiserver/plane/db/models/__init__.py Added IssueVersion to imports, removed duplicate imports for clarity.
apiserver/plane/db/models/issue.py Updated log_issue_version method to streamline data handling and ensure accurate timestamps.

Possibly related PRs

Suggested labels

⚙️backend, 🌟improvement

Suggested reviewers

  • pablohashescobar
  • sriramveeraghanta

🐰 In the meadow, changes bloom,
A task for versions to resume.
With updates swift, we hop along,
Managing issues, righting the wrong.
In code we trust, our work is clear,
A better world for all to cheer! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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
Contributor

@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 and nitpick comments (6)
apiserver/plane/db/models/issue.py (4)

741-743: Consider importing models directly to improve readability and performance.

Using apps.get_model() to retrieve ModuleIssue and CycleIssue models can impact performance and reduce code readability. If there are no circular dependency issues, consider importing these models directly at the top of the file.

Apply this change to import the models directly:

# At the top of the file
from plane.db.models import ModuleIssue, CycleIssue

# Then, you can use the models directly without `apps.get_model()`
# Remove these lines inside the method
- ModuleIssue = apps.get_model("db.ModuleIssue")
- CycleIssue = apps.get_model("db.CycleIssue")

Line range hint 750-775: Incorrect retrieval of module IDs; use module_id instead of id.

When fetching module IDs associated with the issue, you should retrieve the module_id field from the ModuleIssue model. Currently, you are retrieving the ids of the ModuleIssue instances, not the Module instances.

Apply this diff to fix the issue:

 modules=list(
-    ModuleIssue.objects.filter(issue=issue).values_list("id", flat=True)
+    ModuleIssue.objects.filter(issue=issue).values_list("module_id", flat=True)
 ),

770-770: Consider using updated_at instead of last_saved_at to avoid redundancy.

Since IssueVersion inherits created_at and updated_at from ProjectBaseModel, the last_saved_at field may be redundant. Consider using updated_at to track when the version was last saved.

You can remove the last_saved_at field and update references accordingly:

  • Remove last_saved_at from the model fields.
  • Replace last_saved_at with updated_at in your code.

Line range hint 741-775: Add unit tests for the log_issue_version method.

To ensure the correctness and reliability of the version logging functionality, consider adding unit tests for the log_issue_version method. Tests should cover various scenarios, including issues with or without cycles, modules, assignees, and labels.

apiserver/plane/bgtasks/issue_version_task.py (2)

32-32: Consider tracking changes to additional fields for comprehensive versioning.

Currently, version logging is triggered only when description_html changes. To ensure a complete version history, consider checking for changes in other significant fields such as name, priority, or state.

Modify the condition to check multiple fields:

if (
    current_instance.get("description_html") != issue.description_html
    or current_instance.get("name") != issue.name
    or current_instance.get("priority") != issue.priority
    # Add other fields as necessary
):
    # Proceed with version logging

63-63: Ensure consistent parameter naming for clarity.

In IssueVersion.log_issue_version(issue, user_id), the user parameter is actually a user ID (UUID). For clarity, consider renaming the parameter from user to user_id in the method definition to reflect its actual content.

Update the method signature and references:

 @classmethod
-def log_issue_version(cls, issue, user):
+def log_issue_version(cls, issue, user_id):
     # ...
-    owned_by=user,
+    owned_by=user_id,
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d0f9a4d and 28ece29.

📒 Files selected for processing (4)
  • apiserver/plane/app/views/issue/base.py (2 hunks)
  • apiserver/plane/bgtasks/issue_version_task.py (1 hunks)
  • apiserver/plane/db/models/__init__.py (1 hunks)
  • apiserver/plane/db/models/issue.py (4 hunks)
🔇 Additional comments (3)
apiserver/plane/db/models/issue.py (1)

12-12: Importing apps from django.apps is appropriate.

The import statement change to from django.apps import apps is acceptable and allows for dynamic model retrieval using apps.get_model().

apiserver/plane/db/models/__init__.py (1)

44-44: Importing IssueVersion model is appropriate.

The addition of IssueVersion to the imports integrates the new model into the application's models module correctly.

apiserver/plane/app/views/issue/base.py (1)

656-658: Asynchronous version logging is correctly integrated.

The addition of issue_version_task.delay() in the partial_update method ensures that issue versioning is handled asynchronously after an update, which is appropriate for maintaining responsiveness.

Comment on lines +25 to +26
json.loads(existing_instance) if existing_instance is not None else {}
)
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add error handling for JSON parsing of existing_instance.

Parsing existing_instance without handling potential JSONDecodeError exceptions may lead to crashes if invalid JSON is provided. Consider adding a try-except block to handle this scenario gracefully.

Apply this diff to fix the issue:

 try:
     current_instance = (
-        json.loads(existing_instance) if existing_instance is not None else {}
+        json.loads(existing_instance) if existing_instance else {}
     )
+except json.JSONDecodeError:
+    current_instance = {}
+    # Optionally, log the error or handle it appropriately

Committable suggestion skipped: line range outside the PR's diff.

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.

2 participants