Skip to content

Add docstrings to mixin property methods#3532

Merged
arkid15r merged 7 commits intoOWASP:mainfrom
moizulfiqar:add-docstrings-mixins
Jan 26, 2026
Merged

Add docstrings to mixin property methods#3532
arkid15r merged 7 commits intoOWASP:mainfrom
moizulfiqar:add-docstrings-mixins

Conversation

@moizulfiqar
Copy link
Contributor

@moizulfiqar moizulfiqar commented Jan 25, 2026

Proposed change

Resolves #2648

Files Updated:
• backend/apps/github/models/mixins/repository.py
• backend/apps/github/models/mixins/user.py
• backend/apps/owasp/models/mixins/project.py
What was changed:
• Added docstrings to all @Property methods in the mixin classes.
• Docstrings now explain:
• Purpose of the property (why it exists / how it is used).
• Return value and its type.
• Followed the existing docstring style in the codebase (verified from files like project health metrics, repository index, etc.).
Tests / Verification:
• Ran make check-test locally.

Checklist

  • Required: I followed the contributing workflow
  • Required: I verified that my code works as intended and resolves the issue as described
  • Required: I ran make check-test locally: all warnings addressed, tests passed
  • I used AI for code, documentation, tests, or communication related to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 25, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Improved indexing eligibility criteria to exclude template repositories and items without associated projects.
    • Enhanced user indexing logic with additional validation checks.
  • Documentation

    • Added comprehensive docstrings across indexing properties with explicit return type descriptions.
  • Refactor

    • Enriched contribution data structure with detailed repository information and filtering logic.
    • Added explicit type annotations to improve code clarity and reliability.
    • Updated query construction for related data retrieval across platform entities.
  • Tests

    • Expanded test coverage for new indexing properties and repository attributes.

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

Walkthrough

Docstrings were added or expanded across GitHub repository/user mixins and the OWASP Project model; indexing eligibility logic was tightened in repository and user mixins, and idx_contributions was changed to return enriched contribution dictionaries.

Changes

Cohort / File(s) Summary
GitHub Repository Mixin
backend/apps/github/models/mixins/repository.py
is_indexable now also requires an associated project and that the repo is not a template; idx_subscribers_count sources subscribers_count; idx_topics signature changed to -> list[str]; many idx_* docstrings added/expanded.
GitHub User Mixin
backend/apps/github/models/mixins/user.py
is_indexable adds exclusion for non-indexable logins; idx_contributions now returns enriched list of dicts with repository metadata and applies filters/limits; extensive docstring expansions across idx_* properties.
OWASP Project Model
backend/apps/owasp/models/project.py
Numerous docstring expansions and some explicit return type annotations (e.g., published_releases -> models.QuerySet[Release], recent_milestones -> models.QuerySet[Milestone]); query accessors adjusted to prefetch/select related data.
Tests (GitHub Repository Mixin)
backend/tests/apps/github/models/mixins/repository_test.py
New constants added and fixture updated to populate additional attributes; tests expanded to assert new idx_* properties (commits, size, subscribers, etc.).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

backend-tests

Suggested reviewers

  • kasya
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning Several behavioral changes detected beyond docstring additions: repository.is_indexable now adds stricter constraints, idx_subscribers_count changed return source, idx_topics signature changed, and user.is_indexable logic refined. These changes exceed the stated scope of adding docstrings. Remove or clarify behavioral changes unrelated to docstring additions. If these changes are intentional, document them in the PR description and link to separate issues, or revert them to keep this PR focused on documentation.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add docstrings to mixin property methods' accurately describes the main change—adding comprehensive docstrings to property methods across multiple mixin classes.
Description check ✅ Passed The description is clearly related to the changeset, detailing which mixin files were updated, what docstrings were added, and confirming local test verification.
Linked Issues check ✅ Passed The PR successfully addresses all core requirements of issue #2648: docstrings added to property methods in the three specified files, explaining purpose and return types, following existing codebase style, and tests verified locally.
Docstring Coverage ✅ Passed Docstring coverage is 98.57% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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: 1

🤖 Fix all issues with AI agents
In `@backend/apps/github/models/mixins/repository.py`:
- Around line 184-192: The property idx_subscribers_count currently returns the
wrong attribute (self.stars_count); update the property implementation for
idx_subscribers_count to return self.subscribers_count instead so it matches the
docstring and intended semantics; locate the idx_subscribers_count property in
the repository mixin and replace the returned symbol stars_count with
subscribers_count.
🧹 Nitpick comments (1)
backend/apps/github/models/mixins/user.py (1)

181-208: Add repository__owner to select_related() to avoid N+1 queries on owner access.

The query uses .select_related("repository"), but accessing rc.repository.owner.login at line 195 causes an additional query per iteration since owner is a ForeignKey that isn't included in the select_related.

♻️ Suggested improvement
             for rc in RepositoryContributor.objects.filter(
                 user=self,
             )
             .exclude(
                 Q(repository__is_fork=True)
                 | Q(repository__organization__is_owasp_related_organization=False)
                 | Q(user__login__in=self.get_non_indexable_logins())
             )
             .order_by("-contributions_count")
-            .select_related("repository")[:TOP_REPOSITORY_CONTRIBUTORS_LIMIT]
+            .select_related("repository", "repository__owner")[:TOP_REPOSITORY_CONTRIBUTORS_LIMIT]

Note: The access to rc.repository.latest_release (lines 191-193) will also trigger queries since latest_release is a property method that cannot be optimized with prefetch or select_related mechanisms.

@sonarqubecloud
Copy link

Copy link
Collaborator

@arkid15r arkid15r left a comment

Choose a reason for hiding this comment

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

This is good, but any AI work needs to be reviewed by a PR author.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
backend/apps/github/models/mixins/user.py (1)

168-204: Potential N+1 queries in idx_contributions for owner access; latest_release requires different approach.

Line 185–189 accesses rc.repository.owner (a ForeignKey), but the queryset only select_related("repository"). This will trigger one extra query per row.

Additionally, line 187 calls rc.repository.latest_release.summary, which is a @property that executes .releases.filter(...).order_by(...).first() for each row—another N+1 concern. Since latest_release is not a database field but a computed property, it cannot be resolved with select_related. Consider using prefetch_related("repository__releases") or restructuring to fetch and filter releases more efficiently.

At minimum, add select_related("repository__owner"):

♻️ Possible partial fix (owner only)
             .select_related(
                 "repository",
+                "repository__owner",
             )[:TOP_REPOSITORY_CONTRIBUTORS_LIMIT]

For latest_release, evaluate whether prefetch_related("repository__releases") with post-processing, or a custom Prefetch object with filtered querysets, is more appropriate for your use case.

🧹 Nitpick comments (2)
backend/apps/owasp/models/project.py (2)

404-423: Property name doesn't match implementation (pre-existing).

The docstring accurately describes the implementation, but note that the property is named recent_milestones while the query has no date/time filtering—it returns all milestones for the project's repositories. This is a pre-existing naming issue, not introduced by this PR.

Consider renaming to milestones or adding date filtering in a follow-up if "recent" filtering is intended.


232-254: Consider adding type annotations for consistency.

The published_releases and recent_milestones properties now have return type annotations (models.QuerySet[Release] and models.QuerySet[Milestone]), but similar QuerySet-returning properties like issues, open_issues, and pull_requests do not.

For consistency, consider adding type annotations to these properties as well in a follow-up.

Example for `issues`
 `@property`
-def issues(self):
+def issues(self) -> models.QuerySet[Issue]:
     """Get issues across the project's repositories.

@codecov
Copy link

codecov bot commented Jan 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.48%. Comparing base (c15981a) to head (e081b68).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #3532   +/-   ##
=======================================
  Coverage   85.48%   85.48%           
=======================================
  Files         461      461           
  Lines       14240    14240           
  Branches     1896     1896           
=======================================
  Hits        12173    12173           
  Misses       1688     1688           
  Partials      379      379           
Flag Coverage Δ
backend 84.48% <100.00%> (ø)
frontend 88.26% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
backend/apps/github/models/mixins/repository.py 100.00% <100.00%> (ø)
backend/apps/github/models/mixins/user.py 93.33% <ø> (ø)
backend/apps/owasp/models/project.py 82.85% <100.00%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c15981a...e081b68. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@arkid15r arkid15r added this pull request to the merge queue Jan 26, 2026
Merged via the queue into OWASP:main with commit f3ce810 Jan 26, 2026
37 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Jan 26, 2026
4 tasks
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.

Add Docstrings to Model Mixin Methods

2 participants

Comments