Repository navigation
Conversation
…view Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
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. |
There was a problem hiding this comment.
Code Health Improved
(1 files improve in Code Health)
Gates Failed
New code is healthy
(2 new files with code health below 10.00)
Our agent can fix these. Install it.
Gates Passed
2 Quality Gates Passed
Reason for failure
| New code is healthy | Violations | Code Health Impact | |
|---|---|---|---|
| visit_approval.py | 1 rule | 9.69 | Suppress |
| approve_over_limit_visits.py | 1 rule | 9.69 | Suppress |
View Improvements
| File | Code Health Impact | Categories Improved |
|---|---|---|
| init.py | 4.56 → 4.73 | Lines of Code in a Single File, Complex Method, Bumpy Road Ahead |
Quality Gate Profile: The Bare Minimum
Install CodeScene MCP: safeguard and uplift AI-generated code. Catch issues early with our IDE extension and CLI tool.
| def approve_user_visits( | ||
| opportunity: Opportunity, visits, justification: str | None = None, agree: bool = False | ||
| ) -> int: | ||
| """Approve the visits, then recalculate the workers' accrual and the visits' work areas. | ||
|
|
||
| The visits go to PM review, and one the PM disagreed with goes back to pending review. With agree, | ||
| they are marked agreed instead, as form processing does for an auto-approved visit. Flagged visits | ||
| get the justification, and MissingJustificationError is raised before anything is written if one of | ||
| them needs it and none is given. Returns the number of visits updated. | ||
| """ | ||
| visits = list(visits) | ||
| if not justification and any(visit.flagged for visit in visits): | ||
| raise MissingJustificationError("Justification is mandatory for flagged visits.") | ||
|
|
||
| approved_on = now() | ||
| for visit in visits: | ||
| _approve(visit, approved_on, justification) | ||
| if agree: | ||
| visit.review_status = VisitReviewStatus.agree | ||
| visit.review_status_modified_date = approved_on | ||
|
|
||
| approved_count = UserVisit.objects.bulk_update( | ||
| visits, | ||
| [ | ||
| "status", | ||
| "status_modified_date", | ||
| "review_created_on", | ||
| "review_status", | ||
| "review_status_modified_date", | ||
| "justification", | ||
| ], | ||
| batch_size=100, | ||
| ) | ||
| user_ids = list({visit.user_id for visit in visits}) | ||
| if user_ids: | ||
| update_payment_accrued(opportunity=opportunity, users=user_ids, incremental=True) | ||
| for work_area in {visit.work_area for visit in visits if visit.work_area}: | ||
| work_area.update_status() | ||
| return approved_count |
There was a problem hiding this comment.
❌ New issue: Complex Method
approve_user_visits has a cyclomatic complexity of 11, threshold = 9
| def handle(self, *args, opportunity, visit_ids, agree, commit, **options): | ||
| _check_justification() | ||
| opportunity = _get_opportunity(opportunity) | ||
| _check_agree(opportunity, agree) | ||
|
|
||
| candidates = list(approvable_visits(opportunity, visit_ids)) | ||
| over_limit = [visit for visit in candidates if visit.status == VisitValidationStatus.over_limit] | ||
| flagged_skipped = [visit for visit in over_limit if visit.flagged] if agree else [] | ||
| to_approve = [visit for visit in over_limit if visit not in flagged_skipped] | ||
|
|
||
| self._report(opportunity, visit_ids, candidates, over_limit, flagged_skipped, to_approve) | ||
| self._warn_about_payment(opportunity, agree) | ||
| if not commit: | ||
| self.stdout.write(self.style.WARNING("Dry run: nothing was saved. Rerun with --commit to approve.")) | ||
| return | ||
|
|
||
| with transaction.atomic(): | ||
| approved_count = approve_user_visits(opportunity, to_approve, JUSTIFICATION, agree=agree) | ||
| self.stdout.write(self.style.SUCCESS(f"Approved {approved_count} visits.")) |
There was a problem hiding this comment.
❌ New issue: Excess Number of Function Arguments
Command.handle has 6 arguments, max arguments = 4
| def _report(self, opportunity, visit_ids, candidates, over_limit, flagged_skipped, to_approve): | ||
| not_over_limit = [visit for visit in candidates if visit not in over_limit] | ||
| candidate_ids = {visit.id for visit in candidates} | ||
| not_approvable_ids = [visit_id for visit_id in visit_ids if visit_id not in candidate_ids] | ||
|
|
||
| self.stdout.write(f"Opportunity {opportunity.pk} ({opportunity.name})") | ||
| self._write_ids("Will approve", to_approve) | ||
| self._write_ids(" of which flagged, saved with the justification", [v for v in to_approve if v.flagged]) | ||
| self.stdout.write(f"Justification: {JUSTIFICATION}") | ||
| self._write_ids("Skipped, flagged (--agree leaves them for review)", flagged_skipped) | ||
| self._write_ids("Skipped, not over limit", not_over_limit) | ||
| self.stdout.write( | ||
| f"Skipped, not in this opportunity or already approved: {len(not_approvable_ids)} {not_approvable_ids}" | ||
| ) |
There was a problem hiding this comment.
❌ New issue: Excess Number of Function Arguments
Command._report has 6 arguments, max arguments = 4
| try: | ||
| approved_count = approve_user_visits(request.opportunity, visits, request.POST.get("justification")) | ||
| except MissingJustificationError as error: | ||
| return HttpResponse(str(error), status=400, headers={"HX-Trigger": "form_error"}) |
Product Description
Technical Summary
Documentation
Safety Assurance
Safety story
Automated test coverage
QA Plan
Deployment
Labels & Review