Skip to content

Conversation

@Aryaneefds
Copy link

Proposed change

Resolves #3095

Summary

This PR simplifies the regex in the get_leaders method to reduce its complexity score and satisfy SonarQube rule python:S5843.

Details

  • Replaced the complex single regex pattern with two simpler re.findall patterns:
    • bracket_pattern: Handles bracket-style leaders like - [Name] or * [Name (Role)]
    • plain_pattern: Handles plain asterisk-style leaders like * Name
  • Removed the unused itertools import that was only needed for the previous complex approach
  • All existing test cases pass with identical output to the original implementation

This change is limited to regex refactoring and does not affect application behavior.

Checklist

  • Required: I read and followed the contributing guidelines
  • Required: I ran make check-test locally and all tests passed
  • I used AI for guidance during investigation and verification, all changes were reviewed and applied manually

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 5, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Improved leader information extraction to more reliably recognize names across common formatting patterns in documentation.
    • Enhanced name recognition to handle both bracket-style and standard list formats for better accuracy.
    • Simplified extraction behavior to reduce edge cases and ensure more consistent leader data across the system.

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

Walkthrough

Replaces complex nested regex in get_leaders with two simpler sequential patterns (bracket-style then asterisk-style) for extracting leader names from Markdown and removes the now-unused itertools import.

Changes

Cohort / File(s) Summary
Leader Extraction Logic Refactoring
backend/apps/owasp/models/common.py
Rewrote get_leaders to use two simpler regexes: first to match bracket-style bullets (e.g., - [Name] or * [Name (Role)]), then fallback to plain asterisk bullets (* Name). Removed prior itertools-based processing and deleted unused itertools import.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • kasya
  • arkid15r

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed Title clearly summarizes the main change: simplifying the leader name parsing regex in the get_leaders method, which directly matches the changeset.
Description check ✅ Passed Description is comprehensive and directly related to the changeset, explaining the regex simplification, pattern changes, removed imports, and test verification.
Linked Issues check ✅ Passed The PR addresses issue #3095 by replacing the complex regex with two simpler patterns to reduce SonarQube complexity score, achieving the stated objective of flattening the regex structure.
Out of Scope Changes check ✅ Passed All changes are narrowly scoped to regex refactoring in get_leaders: replacing complex pattern with simpler alternatives and removing unused itertools import, with no behavioral changes.
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 549a834 and 4428c5d.

📒 Files selected for processing (1)
  • backend/apps/owasp/models/common.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • backend/apps/owasp/models/common.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.

@Aryaneefds Aryaneefds changed the title refactor: simplify leader name parsing #3095 refactor: simplify leader name parsing Jan 5, 2026
coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 5, 2026
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 5, 2026

@Aryaneefds
Copy link
Author

@arkid15r @kasya can you review this PR.

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.

Simplify this regular expression to reduce its complexity

1 participant