Skip to content
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

[PE-93] regression: issue mentions and subscribers logic #6265

Merged
merged 1 commit into from
Dec 23, 2024

Conversation

aaryan610
Copy link
Collaborator

@aaryan610 aaryan610 commented Dec 23, 2024

Description

This PR fixes the logic to update issue mentions and subscribers.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Summary by CodeRabbit

  • New Features

    • Improved mention extraction in issue descriptions and comments.
    • Enhanced filtering logic for notifications to include only valid project members.
  • Bug Fixes

    • Streamlined the process of identifying user mentions, improving accuracy.

@aaryan610 aaryan610 added 🐛bug Something isn't working ⚙️backend labels Dec 23, 2024
@aaryan610 aaryan610 added this to the v0.24.0 milestone Dec 23, 2024
Copy link
Contributor

coderabbitai bot commented Dec 23, 2024

Walkthrough

The pull request introduces modifications to the mention extraction and filtering logic in the notification_task.py file. The changes primarily focus on updating the method for identifying user mentions by switching the attribute from target: "users" to entity_name: "user_mention". The mention filtering process has been refined using a set intersection approach, which enhances the clarity and potentially the performance of identifying valid mentions within project members.

Changes

File Change Summary
apiserver/plane/bgtasks/notification_task.py - Updated extract_mentions and extract_comment_mentions to use entity_name: "user_mention" instead of target: "users"
- Modified mention filtering logic in notifications function using set intersection

Possibly related PRs

Suggested reviewers

  • SatishGandham
  • NarayanBavisetti
  • pablohashescobar

Poem

🐰 Mentions dance, a digital delight,
Set intersections make filtering bright,
From "users" to "user_mention" we leap,
Code refactored, no secrets to keep!
Rabbit's code hops with elegant might 🌟

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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: 0

🧹 Nitpick comments (1)
apiserver/plane/bgtasks/notification_task.py (1)

143-145: Consolidate repetitive mention extraction logic
The logic mirrors the one in lines 127-129. To adhere to the DRY principle, consider consolidating repeated mention-extraction code (in “extract_mentions” and “extract_comment_mentions”) into a single helper function, potentially parameterized for different HTML sources.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 34d114a and be7470f.

📒 Files selected for processing (1)
  • apiserver/plane/bgtasks/notification_task.py (3 hunks)
🔇 Additional comments (2)
apiserver/plane/bgtasks/notification_task.py (2)

127-129: Use of "entity_name" for user mention extraction
This correctly aligns the parsing logic with the updated attribute (“entity_name”: “user_mention”). Confirm that the front-end consistently uses the same “entity_name” to avoid missed or malformed mentions.

Consider the following script to locate any remaining “mention-component” references that might still rely on the old "target" attribute:

✅ Verification successful

Attribute "entity_name" with "user_mention" is consistently used across the codebase

The verification shows consistent usage of the "entity_name" attribute with "user_mention" value across both frontend and backend:

  • Frontend editor components set this attribute in web/core/hooks/use-editor-mention.tsx
  • Frontend parsing logic in web/core/hooks/use-parse-editor-content.ts expects this attribute
  • Backend notification tasks in apiserver/plane/bgtasks/notification_task.py use the same attribute pattern
  • Editor package components in packages/editor maintain the same convention
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Searching for mention-component usage with target attribute
rg -A 2 $'<mention-component[^>]*target="users"'

Length of output: 49


Script:

#!/bin/bash
# Search for mention-component usage in the codebase
rg -i "mention-component" -A 3

Length of output: 5264


Script:

#!/bin/bash
# Search for files containing mention-related code
fd -e js -e jsx -e ts -e tsx -e py . | xargs rg -l "mention"

Length of output: 4274


Script:

#!/bin/bash
# Search for entity_name attribute usage
rg "entity_name.*user_mention" -A 2

Length of output: 1384


261-263: Efficient membership filtering approach
Using a set intersection here is concise and clear. Verify that “new_mentions” and “project_members” are consistently typed (e.g., both are strings or both are UUIDs). Mixing string-based identifiers with UUID objects could lead to empty intersections.

✅ Verification successful

Let me gather more information about the types and usage of new_mentions and project_members to verify the consistency.


From the results, I can see that:

  1. project_members is obtained from Django's ORM using values_list("member_id", flat=True), which returns a list of member IDs
  2. new_mentions is constructed from extract_mentions() function and contains string values
  3. Before the intersection, project_members values are explicitly converted to strings: {str(member) for member in project_members}

Let me check the extract_mentions function to confirm the type of mentions it returns.


From the results, I can see the extract_mentions function that parses HTML content to extract user mentions, and it appears to work with user IDs. Let me check one more thing to verify how these mentions are processed.


Types are properly handled in the mention intersection operation

The code is correctly handling type consistency in the set intersection operation:

  1. extract_mentions() returns a list of entity identifiers extracted from HTML mentions
  2. project_members contains member IDs from the database
  3. Before the intersection, there's an explicit conversion of project members to strings: {str(member) for member in project_members}
  4. The intersection operation set(new_mentions) & {str(member) for member in project_members} ensures both sets contain string values

The type conversion is properly handled, preventing any potential empty intersections due to type mismatches.

🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# Let's first look at how new_mentions is constructed and used
rg -B 5 -A 2 "new_mentions\s*=" apiserver/plane/bgtasks/notification_task.py

# Also check how project_members is defined and used
rg -B 5 -A 2 "project_members\s*=" apiserver/plane/bgtasks/notification_task.py

# Look for any type hints or docstrings that might indicate types
ast-grep --pattern 'def $FUNC($PARAMS): 
    $$$
    new_mentions = $$$
    $$$'

Length of output: 2067


Script:

#!/bin/bash
# Look for extract_mentions function definition and implementation
rg -B 2 -A 10 "def extract_mentions" apiserver/plane/bgtasks/notification_task.py

# Also check if there are any type hints in the file
rg "from typing" apiserver/plane/bgtasks/notification_task.py

Length of output: 1229


Script:

#!/bin/bash
# Look for the complete extract_mentions function implementation to see what it returns
rg -B 2 -A 20 "def extract_mentions" apiserver/plane/bgtasks/notification_task.py

# Also check for any mention-related type conversions
rg -A 2 "mention" apiserver/plane/bgtasks/notification_task.py | grep -E "str|uuid"

Length of output: 2541

@pushya22 pushya22 merged commit 88737b1 into preview Dec 23, 2024
12 of 14 checks passed
@pushya22 pushya22 deleted the fix/issue-mentions branch December 23, 2024 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚙️backend 🐛bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants