Skip to content

Avoid indexing issues with linked PR #1312

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 1 commit into
base: main
Choose a base branch
from

Conversation

yashgoyal0110
Copy link
Contributor

fixes: #528

@yashgoyal0110 yashgoyal0110 requested a review from arkid15r as a code owner April 8, 2025 20:00
Copy link
Contributor

coderabbitai bot commented Apr 8, 2025

Summary by CodeRabbit

  • New Features
    • Enhanced issue tracking now includes pull request association, ensuring the system distinguishes between standalone issues and pull requests.
    • Issue listings have been updated to display only those without an associated pull request.
    • Database updates support this improved categorization for clearer, more relevant issue management.

Walkthrough

The pull request adds a new boolean flag, has_pull_request, to the Issue model. This flag is set based on whether an issue has an associated pull request according to the GitHub API response. The change involves updating the Issue model (and its migration) and modifying the update and indexing processes to handle this new field, ensuring that issues with linked pull requests are not indexed.

Changes

Files Change Summary
backend/apps/.../common.py, backend/apps/.../models/issue.py Updated the update_data method to include the has_pull_request parameter and added a new Boolean field has_pull_request (default False) to the Issue model.
backend/apps/.../index/issue.py Modified the get_entities method to filter out issues that have a linked pull request by enforcing has_pull_request=False.
backend/apps/.../migrations/0021_issue_has_pull_request.py Introduced a migration that adds the has_pull_request Boolean field to the Issue model with a default value of False.

Assessment against linked issues

Objective Addressed Explanation
Introduce a new flag has_pull_request for the Issue model and populate it based on the GitHub API response (Issue [#528])
Exclude issues with linked pull requests from indexing (Issue [#528])
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

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

sonarqubecloud bot commented Apr 8, 2025

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 comments (1)
backend/apps/github/models/issue.py (1)

176-200: ⚠️ Potential issue

Missing parameter in update_data method signature.

The update_data method is being called with a has_pull_request parameter in common.py, but the method signature doesn't include this parameter. This will cause a runtime error.

-def update_data(gh_issue, author=None, repository=None, save=True):
+def update_data(gh_issue, author=None, repository=None, has_pull_request=False, save=True):

Additionally, you'll need to update the method to set the has_pull_request field on the issue instance:

 issue.from_github(gh_issue, author=author, repository=repository)
+issue.has_pull_request = has_pull_request
 if save:
     issue.save()
🧹 Nitpick comments (1)
backend/apps/github/common.py (1)

79-80: Consider using the has_pr variable for consistency.

You've defined has_pr to safely check for the presence of a pull request, but then directly access gh_issue.pull_request in the conditional, which could potentially raise an AttributeError.

-                if gh_issue.pull_request:  # Skip pull requests.
+                if has_pr:  # Skip pull requests.
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2262e4d and 8011e4c.

📒 Files selected for processing (4)
  • backend/apps/github/common.py (1 hunks)
  • backend/apps/github/index/issue.py (1 hunks)
  • backend/apps/github/migrations/0021_issue_has_pull_request.py (1 hunks)
  • backend/apps/github/models/issue.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
backend/apps/github/common.py (1)
backend/apps/github/models/issue.py (2)
  • update_data (177-200)
  • Issue (16-200)
🔇 Additional comments (4)
backend/apps/github/migrations/0021_issue_has_pull_request.py (1)

1-17: Migration looks good.

This migration adds a new boolean field has_pull_request to the Issue model with a default value of False. The migration is properly structured with the correct dependencies.

backend/apps/github/models/issue.py (1)

46-47: New field definition looks good.

The new boolean field has_pull_request with default False is correctly defined in the Issue model.

backend/apps/github/index/issue.py (1)

96-106: Filter for excluding issues with pull requests looks good.

The change to filter out issues that have associated pull requests (has_pull_request=False) is correctly implemented. This will prevent issues with linked PRs from being indexed, addressing the goal of this PR.

backend/apps/github/common.py (1)

78-79: Proper check for pull request attribute.

Good use of getattr with a default value to safely check if the issue has a pull request attribute.

Comment on lines 85 to +88
author = User.update_data(gh_issue.user)
issue = Issue.update_data(gh_issue, author=author, repository=repository)
issue = Issue.update_data(
gh_issue, author=author, repository=repository, has_pull_request=has_pr
)
Copy link
Contributor

@coderabbitai coderabbitai bot Apr 8, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue

Passing has_pull_request parameter to update_data.

This code is passing the has_pull_request parameter to Issue.update_data(), but the method's signature doesn't include this parameter, which will cause a runtime error. Make sure to update the method signature in issue.py as mentioned in the previous comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

🧩 Analysis chain

@yashgoyal0110 The file that needs to be updated is backend/apps/github/models/issue.py. This is where the Issue class is defined, and you need to modify the update_data method signature to include the has_pull_request parameter.


🏁 Script executed:

#!/bin/bash
# Find the Issue class and its update_data method
grep -r "def update_data" --include="*.py" backend/apps/github/models/

Length of output: 841


@yashgoyal0110 You need to update the method signature in backend/apps/github/models/issue.py. Currently, the method is defined as:

def update_data(gh_issue, author=None, repository=None, save=True):

You need to add the has_pull_request parameter to match what's being passed in common.py. The updated signature should look like:

def update_data(gh_issue, author=None, repository=None, has_pull_request=False, save=True):

This will resolve the error and make it consistent with the new field you've added to the Issue model.


🧬 Code Graph Analysis Results

Relevant Code Snippets

From backend/apps/github/models/user.py

  • Line 92-113:
def update_data(gh_user, save=True):
    """Update GitHub user data.

    Args:
        gh_user (github.NamedUser.NamedUser): The GitHub user object.
        save (bool, optional): Whether to save the instance.

    Returns:
        User: The updated or created user instance.

    """
    user_node_id = User.get_node_id(gh_user)
    try:
        user = User.objects.get(node_id=user_node_id)
    except User.DoesNotExist:
        user = User(node_id=user_node_id)

    user.from_github(gh_user)
    if save:
        user.save()

    return user

From backend/apps/github/models/organization.py

  • Line 67-88:
def update_data(gh_organization, save=True):
    """Update organization data.

    Args:
        gh_organization (github.Organization.Organization): The GitHub organization object.
        save (bool, optional): Whether to save the instance.

    Returns:
        Organization: The updated or created organization instance.

    """
    organization_node_id = Organization.get_node_id(gh_organization)
    try:
        organization = Organization.objects.get(node_id=organization_node_id)
    except Organization.DoesNotExist:
        organization = Organization(node_id=organization_node_id)

    organization.from_github(gh_organization)
    if save:
        organization.save()

    return organization

From backend/apps/github/models/repository.py

  • Line 291-332:
def update_data(
        gh_repository,
        commits=None,
        contributors=None,
        languages=None,
        organization=None,
        user=None,
        save=True,
    ):
    """Update repository data.

    Args:
        gh_repository (github.Repository.Repository): The GitHub repository object.
        commits (github.PaginatedList.PaginatedList, optional): List of commits.
        contributors (github.PaginatedList.PaginatedList, optional): List of contributors.
        languages (dict, optional): Dictionary of languages used in the repository.
        organization (Organization, optional): The organization instance.
        user (User, optional): The user instance.
        save (bool, optional): Whether to save the instance.

    Returns:
        Repository: The updated or created repository instance.

    """
    repository_node_id = Repository.get_node_id(gh_repository)
    try:
        repository = Repository.objects.get(node_id=repository_node_id)
    except Repository.DoesNotExist:
        repository = Repository(node_id=repository_node_id)

    repository.from_github(
        gh_repository,
        commits=commits,
        contributors=contributors,
        languages=languages,
        organization=organization,
        user=user,
    )
    if save:
        repository.save()

    return repository

From backend/apps/github/models/issue.py

  • Line 177-200:
def update_data(gh_issue, author=None, repository=None, save=True):
    """Update issue data.

    Args:
        gh_issue (github.Issue.Issue): The GitHub issue object.
        author (User, optional): The author of the issue.
        repository (Repository, optional): The repository instance.
        save (bool, optional): Whether to save the instance.

    Returns:
        Issue: The updated or created issue instance.

    """
    issue_node_id = Issue.get_node_id(gh_issue)
    try:
        issue = Issue.objects.get(node_id=issue_node_id)
    except Issue.DoesNotExist:
        issue = Issue(node_id=issue_node_id)

    issue.from_github(gh_issue, author=author, repository=repository)
    if save:
        issue.save()

    return issue

From backend/apps/github/models/pull_request.py

  • Line 102-125:
def update_data(gh_pull_request, author=None, repository=None, save=True):
    """Update pull request data.

    Args:
        gh_pull_request (github.PullRequest.PullRequest): The GitHub pull request object.
        author (User, optional): The author of the pull request.
        repository (Repository, optional): The repository instance.
        save (bool, optional): Whether to save the instance.

    Returns:
        PullRequest: The updated or created pull request instance.

    """
    pull_request_node_id = PullRequest.get_node_id(gh_pull_request)
    try:
        pull_request = PullRequest.objects.get(node_id=pull_request_node_id)
    except PullRequest.DoesNotExist:
        pull_request = PullRequest(node_id=pull_request_node_id)

    pull_request.from_github(gh_pull_request, author=author, repository=repository)
    if save:
        pull_request.save()

    return pull_request

From backend/apps/github/utils.py

  • Line 14-31:
def check_owasp_site_repository(key):
    """Check if the repository is an OWASP site repository.

    Args:
        key (str): The repository key.

    Returns:
        bool: True if the repository is an OWASP site repository, False otherwise.

    """
    return key.startswith(
        (
            "www-chapter-",
            "www-committee-",
            "www-event",
            "www-project-",
        )
    )

These snippets provide context on how user, organization, repository, issue, and pull request data is updated and managed within the application, which may be relevant to the user's inquiry regarding file specifics.

@yashgoyal0110 yashgoyal0110 marked this pull request as draft April 8, 2025 20:05
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.

Do not index issues that have a linked PR
1 participant