Add management command to backfill ActivityEvent histor - #5338
Add management command to backfill ActivityEvent histor#5338anurag2787 wants to merge 11 commits into
Conversation
…t into pulse-activityevent-model
|
Contribution validation failed: |
Summary by CodeRabbit
WalkthroughAdds ActivityEvent storage and event construction, records events during GitHub synchronization, exposes them in Django admin, and provides historical backfill tooling. Local Docker volume declarations are also added. ChangesActivity event lifecycle
Historical activity backfill
Local compose volumes
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
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. Comment |
|
Contribution validation failed: |
3 similar comments
There was a problem hiding this comment.
Actionable comments posted: 7
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@backend/src/apps/github/common.py`:
- Around line 222-224: Update the release persistence flow around
Release.bulk_save and ActivityEvent.update_data to obtain the database-generated
primary keys for newly created releases before creating activity events. Ensure
each ActivityEvent.update_data call receives a guaranteed non-null release
identifier, while preserving the existing processing for releases that already
have primary keys.
In `@backend/src/apps/owasp/admin/activity_event.py`:
- Around line 15-20: Add list_select_related to the ActivityEvent admin
configuration so the ForeignKey fields github_repository and github_user are
eagerly loaded for changelist rows, while preserving the existing list_display
configuration.
In
`@backend/src/apps/owasp/management/commands/owasp_backfill_activity_events.py`:
- Around line 56-58: Remove the unnecessary blank line immediately after each
for-loop header in backfill_issues, backfill_pull_requests, and
backfill_releases, so the first guard statement follows the header directly and
the file satisfies ruff-format.
- Around line 51-56: Update the issue, pull request, and release backfill loops
to call Django’s .iterator() on each offset queryset before iteration, including
the flows around the issue loop and their equivalent methods. Preserve the
existing ordering, offset behavior, and activity-event creation logic while
preventing queryset result caching.
- Around line 56-119: Run ruff format or pre-commit on both affected files and
commit the formatter output. In
backend/src/apps/owasp/management/commands/owasp_backfill_activity_events.py
lines 56-119, remove blank lines immediately after the issue, pull_request, and
release iteration statements and collapse the backfill_pull_requests
logger.warning call. In
backend/tests/unit/apps/owasp/management/commands/owasp_backfill_activity_events_test.py
lines 108-253, collapse the specified test method signatures and remove
formatter-flagged stray blank lines.
- Around line 49-121: Extract the duplicated processing logic from
backfill_issues, backfill_pull_requests, and backfill_releases into a private
shared helper that accepts the queryset, a callable for the item identifier, and
the log noun/message label. Preserve each method’s model-specific queryset,
identifier access (.number or .tag_name), repository skip behavior, exception
logging, offset slicing, and processed-count output while delegating the loops
to the helper.
- Around line 84-86: Reformat the logger.warning call in the pull-request
handling flow to a single line, preserving the existing message and
pull_request.number argument so it conforms to ruff-format.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 03e4dc90-3ede-4607-bc3a-c551edab309f
📒 Files selected for processing (11)
backend/make/apps/owasp.mkbackend/src/apps/github/common.pybackend/src/apps/owasp/admin/__init__.pybackend/src/apps/owasp/admin/activity_event.pybackend/src/apps/owasp/management/commands/owasp_backfill_activity_events.pybackend/src/apps/owasp/migrations/0073_activityevent.pybackend/src/apps/owasp/models/__init__.pybackend/src/apps/owasp/models/activity_event.pybackend/tests/unit/apps/github/common_test.pybackend/tests/unit/apps/owasp/management/commands/owasp_backfill_activity_events_test.pydocker-compose/local/compose.override.yaml
There was a problem hiding this comment.
All reported issues were addressed across 11 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## feature/owasp-pulse #5338 +/- ##
=======================================================
- Coverage 98.83% 98.69% -0.15%
=======================================================
Files 538 541 +3
Lines 17123 17247 +124
Branches 2460 2472 +12
=======================================================
+ Hits 16924 17022 +98
- Misses 99 125 +26
Partials 100 100
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
backend/src/apps/owasp/management/commands/owasp_backfill_activity_events.py (1)
38-41: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winReject negative offsets before slicing.
--offset=-1reachesqueryset[-1:]at line 64; Django QuerySets do not support negative slicing and raise a non-command error. Validateoffset >= 0and raiseCommandErrorinstead.Proposed fix
-from django.core.management.base import BaseCommand +from django.core.management.base import BaseCommand, CommandError def handle(self, *args, **options) -> None: """Handle the command execution.""" offset = options["offset"] + if offset < 0: + raise CommandError("--offset must be non-negative") model = options["model"]Add a regression test for
handle(offset=-1, ...).🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@backend/src/apps/owasp/management/commands/owasp_backfill_activity_events.py` around lines 38 - 41, Update the handle method to validate that options["offset"] is non-negative before constructing or slicing the queryset, raising CommandError for negative values. Preserve existing behavior for zero and positive offsets, and add a regression test covering handle with offset=-1.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@backend/tests/unit/apps/owasp/management/commands/owasp_backfill_activity_events_test.py`:
- Around line 134-145: Remove the unused ActivityEvent patch decorator and the
corresponding mock_activity_event_class parameter from
test_backfill_objects_respects_offset, leaving the test’s queryset offset
assertions unchanged.
---
Outside diff comments:
In
`@backend/src/apps/owasp/management/commands/owasp_backfill_activity_events.py`:
- Around line 38-41: Update the handle method to validate that options["offset"]
is non-negative before constructing or slicing the queryset, raising
CommandError for negative values. Preserve existing behavior for zero and
positive offsets, and add a regression test covering handle with offset=-1.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 480cd1f7-ecdb-41d5-96c2-a0e9ecf1c7ce
📒 Files selected for processing (3)
backend/make/apps/owasp.mkbackend/src/apps/owasp/management/commands/owasp_backfill_activity_events.pybackend/tests/unit/apps/owasp/management/commands/owasp_backfill_activity_events_test.py
|
|
Hi @arkid15r this is stack pr so only file need to be review for this pr is
|



Proposed change
Added management command to backfill existing GitHub activity into the ActivityEvent
Resolves #5337
Checklist