Skip to content

Conversation

@kart-u
Copy link
Contributor

@kart-u kart-u commented Nov 30, 2025

… an organization

Proposed change

Resolves #2700

This PR updates indexing logic so that only repositories and projects associated with an Organization are indexed

Changes:

Repositories: Updated RepositoryIndex.get_entities in backend/apps/github/index/registry/repository.py to filter for organization__isnull=False

Projects: Updated ProjectIndex.get_entities in backend/apps/owasp/index/registry/project.py to filter for organizations__isnull=False Added .distinct() to the project queryset to prevent duplicate entries from arising

Checklist

  • I've read and followed the contributing guidelines.
  • I've run make check-test locally; all checks and tests passed.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 30, 2025

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

💤 Files selected but had no reviewable changes (1)
  • backend/tests/apps/owasp/index/registry/init.py

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Summary by CodeRabbit

  • Changes

    • Indexed repositories and projects are now filtered to include only those with associated organizations.
    • Duplicate project entries have been removed from results.
  • Tests

    • Added test coverage for repository and project indexing with organization-based filtering.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

The changes add organization-based filtering to repository and project indexing logic. Repositories and projects without associated organizations are now excluded from the indexed queryset. Updated tests validate the new filtering behavior.

Changes

Cohort / File(s) Summary
Repository and Project Indexing Filters
backend/apps/github/index/registry/repository.py, backend/apps/owasp/index/registry/project.py
Added ORM filters to exclude entities without organizations: repository uses organization__isnull=False and project uses organizations__isnull=False with .distinct() to ensure uniqueness and remove duplicates.
Test Updates
backend/tests/apps/github/index/registry/repository_test.py
Updated existing test to verify the new organization__isnull=False filter is applied when constructing the Repository queryset.
New Test Suite
backend/tests/apps/owasp/index/registry/project_test.py
Added comprehensive test suite for ProjectIndex covering class attributes, method delegation, and validation of the new queryset construction with .filter(organizations__isnull=False) and .distinct().

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Verify the field name consistency: organization__isnull=False for Repository vs organizations__isnull=False for Project (plural difference reflects relationship naming)
  • Confirm the .distinct() call in project filtering is necessary and correctly handles potential duplicates
  • Ensure test expectations align with actual queryset construction, particularly mock setup in new test file

Suggested labels

backend, backend-tests

Suggested reviewers

  • kasya

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: removing indexing from repositories and projects without organizations.
Linked Issues check ✅ Passed The PR fully implements the requirement from issue #2700 by filtering repositories and projects to exclude those not belonging to any organization.
Out of Scope Changes check ✅ Passed All changes are in scope: filtering logic in repository and project index files, and corresponding test updates to validate the new behavior.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description check ✅ Passed The pull request description clearly relates to the changeset. It explains the proposed changes to both RepositoryIndex and ProjectIndex to filter entities by organization association.

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
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)
backend/tests/apps/owasp/index/registry/project_test.py (1)

1-1: Consider adding __init__.py to the test directory.

The static analysis tool flags that this file is part of an implicit namespace package. While this doesn't break functionality in Python 3.3+, adding an __init__.py file to the test directory improves compatibility and makes the package structure explicit.

Create an empty __init__.py file in backend/tests/apps/owasp/index/registry/ directory:

# backend/tests/apps/owasp/index/registry/__init__.py
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 28ef47f and 89921cb.

📒 Files selected for processing (4)
  • backend/apps/github/index/registry/repository.py (1 hunks)
  • backend/apps/owasp/index/registry/project.py (1 hunks)
  • backend/tests/apps/github/index/registry/repository_test.py (1 hunks)
  • backend/tests/apps/owasp/index/registry/project_test.py (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-11-23T11:37:26.253Z
Learnt from: rudransh-shrivastava
Repo: OWASP/Nest PR: 2606
File: backend/apps/api/rest/v0/project.py:43-48
Timestamp: 2025-11-23T11:37:26.253Z
Learning: In the OWASP Nest backend, `entity_leaders` is a `property` method defined in `RepositoryBasedEntityModel` (backend/apps/owasp/models/common.py) that returns a dynamically constructed QuerySet. It cannot be prefetched using standard `prefetch_related()` because Django's prefetch mechanism only works on model fields and relations, not property methods.

Applied to files:

  • backend/apps/owasp/index/registry/project.py
🧬 Code graph analysis (1)
backend/tests/apps/owasp/index/registry/project_test.py (1)
backend/apps/owasp/index/registry/project.py (4)
  • ProjectIndex (8-115)
  • configure_replicas (82-99)
  • update_synonyms (102-104)
  • get_entities (106-115)
🪛 Ruff (0.14.6)
backend/tests/apps/owasp/index/registry/project_test.py

1-1: File backend/tests/apps/owasp/index/registry/project_test.py is part of an implicit namespace package. Add an __init__.py.

(INP001)

🔇 Additional comments (4)
backend/apps/github/index/registry/repository.py (1)

73-78: LGTM!

The addition of organization__isnull=False correctly filters repositories to include only those associated with an organization. The filter is applied before prefetch_related, which is the optimal order for query performance.

backend/tests/apps/github/index/registry/repository_test.py (1)

32-49: LGTM!

The test correctly validates the updated queryset construction with the new organization__isnull=False filter. The mock setup and assertions appropriately verify both the filter arguments and the prefetch_related call.

backend/tests/apps/owasp/index/registry/project_test.py (1)

1-58: Excellent test coverage!

The test suite comprehensively validates ProjectIndex behavior including class attributes, delegation to parent methods, and the queryset construction in get_entities. The mock setup correctly reflects the implementation's chaining of prefetch_related(), filter(), and distinct().

backend/apps/owasp/index/registry/project.py (1)

108-115: The ManyToMany filtering approach is correct.

The code already includes .distinct() which properly handles the duplication issue that occurs when filtering ManyToMany relationships with organizations__isnull=False. Django's __isnull=False on ManyToMany fields performs an INNER JOIN that produces duplicate parent rows for each matching related object, but the .distinct() call removes these duplicates as intended. The current implementation is appropriate and no changes are necessary.

@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve project/repository indexing

1 participant