Skip to content

Conversation

@sidd190
Copy link
Contributor

@sidd190 sidd190 commented Nov 17, 2025

Proposed change

Resolves #2645

Changes made -

Enhanced docstrings across 8 files in the sitemap views:
chapter.py
committee.py
member.py
organization.py
project.py
repository.py
snapshot.py
static.py

All the docstrings now include detailed Args and Returns sections where appropriate, following the style guide from base.py and repository.py .

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 17, 2025

Summary by CodeRabbit

  • Enhancements
    • Sitemap items now consistently ordered by recent updates and creation dates
    • Updated filtering logic for chapters, committees, members, organizations, projects, and repositories
    • Repository sitemap filtering refined for organization-based content prioritization
    • Snapshot sitemap ordering enhanced with explicit date-based sorting

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

Walkthrough

Adds return type annotations and expanded docstrings across sitemap view classes; several methods also change how items are produced (ordering, source queryset vs. comprehension) affecting Member, Organization, Repository, and Snapshot sitemaps. Tests updated to match new query/order behaviors.

Changes

Cohort / File(s) Summary
Chapter & Committee & Project
backend/apps/sitemap/views/chapter.py, backend/apps/sitemap/views/committee.py, backend/apps/sitemap/views/project.py
Added return type annotations to items() and expanded docstrings describing returned list and ordering. No change to runtime filtering or control flow.
Member sitemap & test
backend/apps/sitemap/views/member.py, backend/tests/apps/sitemap/views/member_test.py
Added items() -> list[User], expanded docstring, and changed item retrieval to apply ordering before is_indexable filtering. Test adjusted to mock .order_by() chain.
Organization sitemap & test
backend/apps/sitemap/views/organization.py, backend/tests/apps/sitemap/views/organization_test.py
items() now uses Organization.related_organizations.order_by(...) and returns only o.is_indexable entries; signature annotated -> list[Organization] and docstring expanded. Test mocking updated to related_organizations.order_by.
Repository sitemap & test
backend/apps/sitemap/views/repository.py, backend/tests/apps/sitemap/views/repository_test.py
Changed items() return annotation from QuerySet to list[Repository]; moved filtering from queryset filters into a Python-level iteration over Repository.objects.order_by(...) with if r.organization and r.is_indexable. Test updated to mock .order_by().
Snapshot sitemap
backend/apps/sitemap/views/snapshot.py
Added QuerySet import and annotated items() -> QuerySet[Snapshot]; items() now orders by -updated_at, -created_at in addition to filtering by COMPLETED. Expanded docstrings for items() and location().
Static sitemap
backend/apps/sitemap/views/static.py
Added explicit return type annotations and expanded docstrings for changefreq(), location(), items(), lastmod(), and priority(). No behavioral changes beyond typing and doc updates.
Tests alignment
backend/tests/apps/sitemap/views/*_test.py
Adjusted mocks to reflect .order_by() or .related_organizations.order_by() usage where source logic was changed.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

  • Review ordering/location changes in Member, Organization, Repository, and Snapshot sitemaps for correctness and potential performance implications.
  • Verify tests accurately represent queryset behavior (chained .order_by() mocks).
  • Check Repository Python-level filtering preserves previous exclusion rules (archived/empty/template) if those are still required elsewhere.

Possibly related PRs

Suggested labels

backend-tests

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: enhancing and adding docstrings to sitemap views following existing style guides.
Description check ✅ Passed The description is directly related to the changeset, detailing which files were enhanced, what was added (Args and Returns docstring sections), and confirming local testing.
Linked Issues check ✅ Passed The PR comprehensively addresses issue #2645 by adding docstrings with Args/Returns sections to all targeted sitemap view methods across the eight required files, meeting all stated acceptance criteria.
Out of Scope Changes check ✅ Passed All changes are tightly scoped to the issue requirements: docstrings, type annotations, and necessary implementation adjustments to support proper documentation.
Docstring Coverage ✅ Passed Docstring coverage is 82.35% which is sufficient. The required threshold is 80.00%.
✨ 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: 0

🧹 Nitpick comments (1)
backend/apps/sitemap/views/organization.py (1)

14-19: Consider minor wording adjustment for consistency.

The one-line summary on line 14 says "queryset" but the method returns a list (list comprehension), not a QuerySet. The Returns section correctly documents it as "list". Consider updating line 14 to:

-        """Return a queryset of indexable Organization objects.
+        """Return a list of indexable Organization objects for sitemap generation.

This would align the summary with the actual return type and match the pattern used in other similar files (chapter.py, committee.py, project.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 28ba425 and 62f30f0.

📒 Files selected for processing (8)
  • backend/apps/sitemap/views/chapter.py (1 hunks)
  • backend/apps/sitemap/views/committee.py (1 hunks)
  • backend/apps/sitemap/views/member.py (1 hunks)
  • backend/apps/sitemap/views/organization.py (1 hunks)
  • backend/apps/sitemap/views/project.py (1 hunks)
  • backend/apps/sitemap/views/repository.py (1 hunks)
  • backend/apps/sitemap/views/snapshot.py (2 hunks)
  • backend/apps/sitemap/views/static.py (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
backend/apps/sitemap/views/static.py (1)
backend/apps/sitemap/views/base.py (4)
  • location (46-48)
  • items (38-40)
  • BaseSitemap (7-52)
  • lastmod (42-44)
🔇 Additional comments (13)
backend/apps/sitemap/views/project.py (1)

14-19: LGTM! Clear and accurate docstring.

The docstring accurately describes the return value and ordering behavior. The documentation clearly states that it returns a list of indexable Project objects, which matches the list comprehension implementation.

backend/apps/sitemap/views/committee.py (1)

14-19: LGTM! Documentation is clear and accurate.

The enhanced docstring properly documents the return type and ordering, matching the implementation.

backend/apps/sitemap/views/chapter.py (1)

14-19: LGTM! Well-documented method.

The docstring enhancement accurately describes the method's behavior and return value.

backend/apps/sitemap/views/repository.py (2)

16-21: LGTM! Comprehensive and accurate docstring.

The docstring accurately documents the QuerySet return type and clearly describes the filtering criteria (non-archived, non-empty, non-template repositories with organizations).


33-43: LGTM! Clear parameter and return documentation.

The Args and Returns sections provide clear documentation for the location method.

backend/apps/sitemap/views/member.py (1)

14-18: LGTM! Clear and accurate documentation.

The docstring accurately describes the return value, including the important detail about excluding bots.

backend/apps/sitemap/views/static.py (5)

19-29: LGTM! Clear documentation for changefreq method.

The docstring properly documents the parameter and return value.


31-41: LGTM! Clear documentation for location method.

The Args and Returns sections are clear and accurate.


43-50: LGTM! Accurate documentation for items method.

The docstring correctly describes the return value as a tuple of static route configurations from BaseSitemap.STATIC_ROUTES.


52-77: LGTM! Comprehensive documentation for lastmod method.

The docstring accurately describes the complex logic of mapping paths to models and returning the latest update timestamp or current time as fallback. The detailed Returns section clearly explains this behavior.


79-89: LGTM! Clear documentation for priority method.

The docstring properly documents the parameter and return type with appropriate range information (0.0 to 1.0).

backend/apps/sitemap/views/snapshot.py (2)

14-19: LGTM! Accurate and clear docstring.

The docstring correctly documents the QuerySet return type and clearly describes the filtering criteria (completed snapshots ordered by update/creation date).


27-36: LGTM! Well-documented location method.

The Args and Returns sections provide clear documentation for the method's parameter and return value.

@ahmedxgouda ahmedxgouda self-requested a review November 17, 2025 13:39
@ahmedxgouda ahmedxgouda self-assigned this Nov 17, 2025
Copy link
Collaborator

@ahmedxgouda ahmedxgouda 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 not right. Please create a feature branch and make your changes in this branch not the main. Please see contributing guidelines
Image

@arkid15r
Copy link
Collaborator

This is not right. Please create a feature branch and make your changes in this branch not the main. Please see contributing guidelines Image

@ahmedxgouda it should be fine, yes it's a good idea to have a separate branch, but this PR can be reviewed as is. It's their fork and it doesn't really affect our code base, right?

@sidd190
Copy link
Contributor Author

sidd190 commented Nov 17, 2025

This is not right. Please create a feature branch and make your changes in this branch not the main. Please see contributing guidelines Image

@ahmedxgouda it should be fine, yes it's a good idea to have a separate branch, but this PR can be reviewed as is. It's their fork and it doesn't really affect our code base, right?

Yes, I'll take care to make changes through a seperate branch from next time.

Copy link
Collaborator

@ahmedxgouda ahmedxgouda left a comment

Choose a reason for hiding this comment

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

Looks good to me except for this minor suggestion.

"""Return list of projects for sitemap generation.
Returns:
list: List of indexable Project objects ordered by update/creation date.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
list: List of indexable Project objects ordered by update/creation date.
list: List of indexable active Project objects ordered by update/creation date.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, updated as suggested. Thanks!

ahmedxgouda
ahmedxgouda previously approved these changes Nov 18, 2025
Copy link
Collaborator

@ahmedxgouda ahmedxgouda left a comment

Choose a reason for hiding this comment

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

LGTM


def items(self) -> QuerySet[Repository]:
"""Return list of repositories for sitemap generation."""
"""Return list of repositories for sitemap generation.
Copy link
Collaborator

Choose a reason for hiding this comment

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

It doesn't look like a list.

@sonarqubecloud
Copy link

@arkid15r arkid15r enabled auto-merge November 22, 2025 20:21
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

🧹 Nitpick comments (4)
backend/apps/sitemap/views/repository.py (1)

13-28: Docstring and return type look good; minor consistency nit

items() now clearly returns a list[Repository] and the docstring accurately describes the ordering and indexability filter. To keep the docstrings consistent with other sitemap views (e.g., Chapter/Project using list: in the Returns: section), you might consider using list: here as well or updating the others to the list[Repository]-style for uniformity.

backend/tests/apps/sitemap/views/repository_test.py (1)

20-29: Mock wiring matches new items() implementation

The test now correctly mocks Repository.objects.order_by to return an iterable that yields mock_obj, which aligns with the updated items() implementation. Wrapping sitemap.items() in list() is redundant now that items() already returns a list, but it’s harmless and doesn’t affect correctness.

backend/apps/sitemap/views/member.py (1)

13-29: Member sitemap items() matches its docstring; tiny style tweak possible

The implementation correctly returns indexable, non-bot users ordered by update/creation date, and the type hint/docstring describe that accurately. For consistency with the other sitemap docstrings, you could add a trailing period to the “Returns:” description line (... update/creation date.), but that’s purely cosmetic.

backend/apps/sitemap/views/static.py (1)

19-28: Docstring and type‑hint updates are consistent with static route structure

The new docstrings and return annotations for changefreq, location, items, and priority correctly describe the actual behavior and the shape of BaseSitemap.STATIC_ROUTES. One small optional improvement would be to type the item parameter consistently across these methods (e.g., item: dict or item: Mapping[str, Any]) to match the docstrings that already describe it as a dictionary.

Also applies to: 31-40, 43-49, 79-88

📜 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 62f30f0 and 08771a0.

📒 Files selected for processing (11)
  • backend/apps/sitemap/views/chapter.py (1 hunks)
  • backend/apps/sitemap/views/committee.py (1 hunks)
  • backend/apps/sitemap/views/member.py (1 hunks)
  • backend/apps/sitemap/views/organization.py (1 hunks)
  • backend/apps/sitemap/views/project.py (1 hunks)
  • backend/apps/sitemap/views/repository.py (1 hunks)
  • backend/apps/sitemap/views/snapshot.py (3 hunks)
  • backend/apps/sitemap/views/static.py (2 hunks)
  • backend/tests/apps/sitemap/views/member_test.py (1 hunks)
  • backend/tests/apps/sitemap/views/organization_test.py (1 hunks)
  • backend/tests/apps/sitemap/views/repository_test.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • backend/apps/sitemap/views/snapshot.py
  • backend/apps/sitemap/views/committee.py
🧰 Additional context used
🧬 Code graph analysis (7)
backend/apps/sitemap/views/organization.py (7)
backend/apps/sitemap/views/chapter.py (1)
  • items (13-27)
backend/apps/sitemap/views/committee.py (1)
  • items (13-27)
backend/apps/sitemap/views/member.py (1)
  • items (13-29)
backend/apps/sitemap/views/project.py (1)
  • items (13-27)
backend/apps/sitemap/views/repository.py (1)
  • items (13-28)
backend/apps/sitemap/views/snapshot.py (1)
  • items (15-27)
backend/apps/sitemap/views/base.py (1)
  • items (38-40)
backend/tests/apps/sitemap/views/organization_test.py (1)
backend/tests/apps/github/api/internal/queries/organization_test.py (1)
  • mock_organization (15-20)
backend/apps/sitemap/views/chapter.py (3)
backend/apps/sitemap/views/committee.py (1)
  • items (13-27)
backend/apps/sitemap/views/base.py (1)
  • items (38-40)
backend/apps/owasp/models/chapter.py (1)
  • Chapter (21-217)
backend/apps/sitemap/views/static.py (1)
backend/apps/sitemap/views/base.py (6)
  • changefreq (34-36)
  • location (46-48)
  • items (38-40)
  • BaseSitemap (7-52)
  • lastmod (42-44)
  • priority (50-52)
backend/apps/sitemap/views/repository.py (6)
backend/apps/sitemap/views/chapter.py (1)
  • items (13-27)
backend/apps/sitemap/views/committee.py (1)
  • items (13-27)
backend/apps/sitemap/views/member.py (1)
  • items (13-29)
backend/apps/sitemap/views/organization.py (1)
  • items (13-28)
backend/apps/sitemap/views/project.py (1)
  • items (13-27)
backend/apps/sitemap/views/base.py (1)
  • items (38-40)
backend/apps/sitemap/views/member.py (9)
backend/apps/sitemap/views/chapter.py (1)
  • items (13-27)
backend/apps/sitemap/views/committee.py (1)
  • items (13-27)
backend/apps/sitemap/views/organization.py (1)
  • items (13-28)
backend/apps/sitemap/views/project.py (1)
  • items (13-27)
backend/apps/sitemap/views/repository.py (1)
  • items (13-28)
backend/apps/sitemap/views/snapshot.py (1)
  • items (15-27)
backend/apps/sitemap/views/static.py (1)
  • items (43-50)
backend/apps/sitemap/views/base.py (1)
  • items (38-40)
backend/apps/github/models/user.py (1)
  • User (28-216)
backend/apps/sitemap/views/project.py (9)
backend/apps/sitemap/views/chapter.py (1)
  • items (13-27)
backend/apps/sitemap/views/committee.py (1)
  • items (13-27)
backend/apps/sitemap/views/member.py (1)
  • items (13-29)
backend/apps/sitemap/views/organization.py (1)
  • items (13-28)
backend/apps/sitemap/views/repository.py (1)
  • items (13-28)
backend/apps/sitemap/views/snapshot.py (1)
  • items (15-27)
backend/apps/sitemap/views/static.py (1)
  • items (43-50)
backend/apps/sitemap/views/base.py (1)
  • items (38-40)
backend/apps/owasp/models/project.py (1)
  • Project (37-384)
🔇 Additional comments (5)
backend/tests/apps/sitemap/views/member_test.py (1)

16-23: Chained queryset mock correctly mirrors items() query

Configuring mock_user.objects.filter.return_value.order_by.return_value = [mock_obj] matches the production chain and makes items() iterate over the expected user. The assertion on list(sitemap.items()) is straightforward and aligns with the new implementation.

backend/tests/apps/sitemap/views/organization_test.py (1)

16-24: Updated mock reflects related_organizations.order_by usage

The test’s use of mock_organization.related_organizations.order_by.return_value = mock_queryset plus a custom __iter__ on mock_queryset correctly simulates the new items() implementation. This keeps the test aligned with how organizations are sourced and ordered for the sitemap.

backend/apps/sitemap/views/chapter.py (1)

13-27: Chapter items() typing and docstring are consistent

The items() method’s type annotation, implementation (list comprehension over active_chapters.order_by with is_indexable filter), and docstring all line up and mirror the style used in other sitemap views.

backend/apps/sitemap/views/project.py (1)

13-27: Project items() implementation and docstring align

items() correctly advertises and returns a list of indexable projects ordered by updated_at/created_at, consistent with the active_projects manager and with the docstring/annotation.

backend/apps/sitemap/views/organization.py (1)

13-28: Organization sitemap items() is well-documented and consistent

The method sources organizations via related_organizations.order_by(...) and filters on is_indexable, which matches the “OWASP-related” wording in the docstring. The return type annotation and Returns: section are in sync with the actual list comprehension.

@arkid15r arkid15r added this pull request to the merge queue Nov 22, 2025
Merged via the queue into OWASP:main with commit 1e936b5 Nov 22, 2025
26 checks passed
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 Sitemap View Methods

3 participants