Skip to content

Conversation

@Ontiomacer
Copy link
Contributor

@Ontiomacer Ontiomacer commented Dec 29, 2025

Proposed change

Resolves #3039

This PR fixes a SonarCloud code smell (rule python:S1192) in
backend/apps/api/rest/v0/snapshot.py by removing duplicated string literals
and extracting them into a shared constant.

Summary of changes

  • Introduced a shared constant for the ordering field description
  • Removed duplicated string literals
  • Improved readability and maintainability
  • Preserved existing behavior

Motivation

The duplicated literal was flagged by SonarCloud as a maintainability issue.
This refactor aligns the code with OWASP Nest quality standards and makes future
changes easier and safer.

Testing

  • Verified module compiles successfully using python -m compileall
  • Verified backend checks via make check-test
  • Frontend formatting step failed due to missing pnpm in local environment

Checklist

  • Required: I read and followed the contributing guidelines
  • Required: I ran make check-test locally and all tests passed
  • I used AI for code, documentation, or tests in this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 29, 2025

Summary by CodeRabbit

  • Refactor
    • Improved internal code organization for API descriptions across multiple endpoints.

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

Walkthrough

Extracted the repeated string "Ordering field" into a new public constant ORDERING_FIELD_DESCRIPTION and replaced literal occurrences with that constant across Snapshot API query parameter definitions; no logic or behavior changes.

Changes

Cohort / File(s) Summary
Snapshot API — constant extraction
backend/apps/api/rest/v0/snapshot.py
Added ORDERING_FIELD_DESCRIPTION = "Ordering field" and replaced repeated literal "Ordering field" usages in query parameter description arguments for endpoints: list_snapshots, list_snapshot_chapters, list_snapshot_issues, list_snapshot_members, list_snapshot_projects, list_snapshot_releases.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested reviewers

  • kasya

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: fixing SonarCloud rule S1192 by deduplicating string literals in the snapshot endpoint, which directly matches the changeset.
Description check ✅ Passed The description is well-related to the changeset, explaining the removal of duplicated string literals and extraction into a shared constant, with motivation from SonarCloud compliance.
Linked Issues check ✅ Passed The PR directly addresses issue #3039 by extracting the duplicated 'Ordering field' string literal into a shared constant (ORDERING_FIELD_DESCRIPTION) and replacing all occurrences, fully meeting the refactor-only objective.
Out of Scope Changes check ✅ Passed All changes are in-scope: only the introduction of ORDERING_FIELD_DESCRIPTION constant and replacement of duplicated literals in snapshot.py, with no modifications to unrelated files or functionality.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% 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

📜 Recent 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 5b2004c and 7521e8a.

📒 Files selected for processing (1)
  • backend/apps/api/rest/v0/snapshot.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • backend/apps/api/rest/v0/snapshot.py

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.

coderabbitai[bot]
coderabbitai bot previously approved these changes Dec 29, 2025
@Ontiomacer
Copy link
Contributor Author

Hi @arkid15r @kasya

This PR addresses SonarCloud issue python:S1192 by extracting the duplicated ordering field description into a shared constant in snapshot.py.
Please let me know if you’d like me to split anything further or adjust the approach. Thanks for the review.

@arkid15r
Copy link
Collaborator

Why disabling this?

Screenshot 2025-12-29 at 10 05 33 AM

@arkid15r arkid15r marked this pull request as draft December 29, 2025 18:41
@Ontiomacer Ontiomacer marked this pull request as ready for review December 30, 2025 05:00
@Ontiomacer
Copy link
Contributor Author

Ontiomacer commented Dec 30, 2025

Thanks @arkid15r for pointing this out. It wasn’t intentional
I likely left the default unchecked when opening the PR.
I have enabled it now.

@Ontiomacer
Copy link
Contributor Author

Ontiomacer commented Dec 30, 2025

Branch is now up to date with main, and maintainer edits are enabled.
Let me know if you’d like me to adjust anything, or if I should wait for workflow approval.
@arkid15r @kasya

@arkid15r arkid15r enabled auto-merge January 2, 2026 00:27
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 2, 2026

@arkid15r arkid15r added this pull request to the merge queue Jan 2, 2026
Merged via the queue into OWASP:main with commit 6ccd528 Jan 2, 2026
25 checks passed
arkid15r added a commit that referenced this pull request Jan 2, 2026
* Refactor snapshot API to remove duplicated ordering description

Signed-off-by: Tejas Tiwari <[email protected]>

* Update code

---------

Signed-off-by: Tejas Tiwari <[email protected]>
Co-authored-by: Arkadii Yakovets <[email protected]>
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.

Sonar S1192: Deduplicate "Ordering field" literal in Snapshot API

2 participants