Skip to content

Round 3: Sonar S3776 complexity splits in reviewers/ - #558

Merged
mzeier merged 2 commits into
stage-eksfrom
450/py-r3-reviewers-s3776
Oct 10, 2026
Merged

mzeier merged 2 commits into
stage-eksfrom
450/py-r3-reviewers-s3776

Conversation

@mzeier

@mzeier mzeier commented Oct 10, 2026

Copy link
Copy Markdown

Part of #450 (round 3).

  • reviewers/utils.py: ReviewHelper.get_actions() (S3776, reviewers/utils.py:301, complexity 21) split into _compute_action_conditions() (all the boolean condition definitions) and _build_actions() (the 7 action dict definitions, keyed off the conditions dict); get_actions() now just computes conditions, builds actions, applies the content-review-only label tweak, and filters by availability.
  • reviewers/models.py: ReviewerScore.get_event() (S3776, reviewers/models.py:420, complexity 33) split into _get_event_name_for_post_review() and _get_event_name_for_regular_review() classmethods, one per branch; get_event() now just dispatches to content_review/post_review/regular and resolves the final constant.
  • reviewers/templatetags/jinja_helpers.py: get_position() (S3776, reviewers/templatetags/jinja_helpers.py:178, complexity 18) split into _persona_position() and _regular_position() module functions, bodies moved verbatim.
  • reviewers/views.py:
    • _queue() (S3776, reviewers/views.py:460, complexity 19 - this one was introduced by my own prior-round edit to this function, per the re-pull before starting) split into _setup_queue_search_form(), _apply_queue_raw_sql_restrictions(), _normalize_queue_per_page().
    • dashboard() (S3776, reviewers/views.py:149, complexity 29) split into one function per section (_dashboard_legacy_addons_section, _dashboard_auto_approved_section, _dashboard_content_review_section, _dashboard_ratings_moderation_section, _dashboard_unlisted_addons_section, _dashboard_announcement_section, _dashboard_admin_tools_section), each returning (header, section); dashboard() now just calls the relevant one per permission check and assigns into sections[header].
    • perform_review_permission_checks() (S3776, reviewers/views.py:695, complexity 17) split out _check_regular_review_permission() for the non-content/non-theme branch.
    • review() (S3776, reviewers/views.py:759, complexity 43, the single largest function in this round) split into _check_review_permissions_unless_read_only(), _gather_channel_review_info(), _kick_off_validation_tasks(), _find_show_diff_version(), _build_auto_approval_info(). review() itself keeps the same straight-line sequence of steps, now mostly one function call per former inline block.

No behavior change anywhere in this PR: every extraction is a verbatim body move preserving the same truth table, evaluation order, and side-effect order (DB queries, cache writes, early returns/redirects, and exception handling all happen in the same relative order as before).

Verified no duplicate function names and every new helper is called exactly once (grep -c sanity check across the file).

Local Greptile review: org free-tier quota exhausted, skipped per coordinator guidance; the Greptile GitHub check on this PR still runs independently.

- reviewers/utils.py: ReviewHelper.get_actions() (complexity 21) split
  into _compute_action_conditions() (all the boolean condition
  definitions) and _build_actions() (the 7 action dict definitions,
  keyed off the conditions dict); get_actions() now just computes
  conditions, builds actions, applies the content-review-only label
  tweak, and filters by availability.
- reviewers/models.py: ReviewerScore.get_event() (complexity 33) split
  into _get_event_name_for_post_review() and
  _get_event_name_for_regular_review() classmethods, one per branch;
  get_event() now just dispatches to content_review/post_review/regular
  and resolves the final constant.
- reviewers/templatetags/jinja_helpers.py: get_position() (complexity
  18) split into _persona_position() and _regular_position() module
  functions, bodies moved verbatim.
- reviewers/views.py:
  - _queue() (complexity 19, introduced by my own prior-round edit to
    this function) split into _setup_queue_search_form(),
    _apply_queue_raw_sql_restrictions(), _normalize_queue_per_page().
  - dashboard() (complexity 29) split into one function per section
    (_dashboard_legacy_addons_section, _dashboard_auto_approved_section,
    _dashboard_content_review_section,
    _dashboard_ratings_moderation_section,
    _dashboard_unlisted_addons_section, _dashboard_announcement_section,
    _dashboard_admin_tools_section), each returning (header, section);
    dashboard() now just calls the relevant one per permission check and
    assigns into sections[header].
  - perform_review_permission_checks() (complexity 17) split out
    _check_regular_review_permission() for the non-content/non-theme
    branch.
  - review() (complexity 43, the single largest function in this round)
    split into _check_review_permissions_unless_read_only(),
    _gather_channel_review_info(), _kick_off_validation_tasks(),
    _find_show_diff_version(), _build_auto_approval_info(). review()
    itself keeps the same straight-line sequence of steps, now mostly
    one function call per former inline block.

No behavior change anywhere in this PR: every extraction is a verbatim
body move preserving the same truth table, evaluation order, and
side-effect order (DB queries, cache writes, early returns/redirects,
and exception handling all happen in the same relative order as
before).
- _dashboard_legacy_addons_section() never used its request parameter;
  removed it from the signature and the call site (S1172).
- Moved the "Permission checks for this view are done inside..." comment
  back to directly above review() (it describes that view's behavior,
  not _check_review_permissions_unless_read_only(), which ended up
  sitting where review() used to be after the earlier S3776 split).
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

Python Test Results

5 763 tests  +5 763   5 709 ✅ +5 709   11m 33s ⏱️ + 11m 33s
    1 suites +    1      54 💤 +   54 
    1 files   +    1       0 ❌ ±    0 

Results for commit 2f24ecb. ± Comparison against base commit 6d0c585.

@mzeier
mzeier merged commit 791d759 into stage-eks Oct 10, 2026
3 checks passed
@mzeier
mzeier deleted the 450/py-r3-reviewers-s3776 branch October 10, 2026 02:02
mzeier added a commit that referenced this pull request Oct 10, 2026
My earlier split in #558 (merged) reduced review() from complexity 43
to 16, still 1 over the allowed 15, per re-pull against stage-eks after
merge (python:S3776, reviewers/views.py:920).

Extracted two more self-contained chunks, both verbatim:
- _filter_review_actions(): the actions_full/actions_comments list
  comprehensions.
- _build_whiteboard_form(): the Whiteboard get-or-construct try/except
  plus the PublicWhiteboardForm/WhiteboardForm class selection.

review() keeps its @login_required/@addon_view_factory decorators
directly above it, and the "Permission checks for this view..." comment
stays directly above those decorators.

No behavior change: both extractions are straight body moves with no
change to evaluation order or side effects.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant