-
-
Notifications
You must be signed in to change notification settings - Fork 95
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
base: main
Are you sure you want to change the base?
Conversation
Summary by CodeRabbit
WalkthroughThe pull request adds a new boolean flag, Changes
Assessment against linked issues
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
|
There was a problem hiding this 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 issueMissing parameter in update_data method signature.
The
update_data
method is being called with ahas_pull_request
parameter incommon.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 accessgh_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
📒 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 theIssue
model with a default value ofFalse
. 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 defaultFalse
is correctly defined in theIssue
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.
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 | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
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.
fixes: #528