Skip to content

Add management command to backfill ActivityEvent histor - #5338

Open
anurag2787 wants to merge 11 commits into
OWASP:feature/owasp-pulsefrom
anurag2787:backfill-pulse-command
Open

Add management command to backfill ActivityEvent histor#5338
anurag2787 wants to merge 11 commits into
OWASP:feature/owasp-pulsefrom
anurag2787:backfill-pulse-command

Conversation

@anurag2787

@anurag2787 anurag2787 commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Proposed change

Added management command to backfill existing GitHub activity into the ActivityEvent

Resolves #5337

Checklist

  • Required: I followed the contributing workflow
  • Required: I verified that my code works as intended and resolves the issue as described
  • Required: I ran all required checks and tests locally; all warnings addressed and failures resolved
  • I used AI for code, documentation, tests, or communication related to this PR

@github-actions

Copy link
Copy Markdown

Contribution validation failed:

@github-actions github-actions Bot closed this Jul 30, 2026
@anurag2787 anurag2787 changed the title Backfill pulse command Add management command to backfill ActivityEvent histor Jul 30, 2026
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Summary by CodeRabbit

  • New Features
    • Added activity tracking for GitHub issues, pull requests, and releases (opened/closed/merged/published).
    • Added an Activity Events admin interface with filtering and search.
    • Added a backfill workflow to generate activity history for existing records, including model selection and offset support.
  • Bug Fixes
    • Improved backfill/activity processing so errors on individual records don’t stop the rest.
  • Chores
    • Updated local Docker Compose setup with named volumes for persistent dev data.

Walkthrough

Adds 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.

Changes

Activity event lifecycle

Layer / File(s) Summary
ActivityEvent model and event construction
backend/src/apps/owasp/migrations/0073_activityevent.py, backend/src/apps/owasp/models/*
Defines ActivityEvent storage, event types, source-object dispatch, event builders, uniqueness constraints, and idempotent persistence.
Synchronization and admin integration
backend/src/apps/github/common.py, backend/src/apps/owasp/admin/*
Creates activity events for synced issues, pull requests, and releases, and registers ActivityEvent in Django admin.

Historical activity backfill

Layer / File(s) Summary
Backfill command execution
backend/src/apps/owasp/management/commands/owasp_backfill_activity_events.py, backend/make/apps/owasp.mk
Adds selectable issue, pull request, release, and all-model backfills with offset support, repository checks, error continuation, and a Make target.
Backfill validation
backend/tests/unit/apps/owasp/management/commands/*, backend/tests/unit/apps/github/common_test.py
Tests command arguments, dispatch, offset handling, skipped records, error continuation, and synchronization dependency mocking.

Local compose volumes

Layer / File(s) Summary
Local volume declarations
docker-compose/local/compose.override.yaml
Declares six named Docker volumes for local persistence and caching.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

  • OWASP/Nest#5233 — Direct code-level overlap in ActivityEvent model, synchronization, and admin changes.
  • OWASP/Nest#5237 — Shares the OWASP Makefile and backend-exec-command wiring pattern.

Suggested labels: makefile, docker

Suggested reviewers: kasya

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The docker-compose volume additions are unrelated to backfilling ActivityEvent historical data. Move the docker-compose changes to a separate PR unless they are required for the linked issue.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR implements the requested Django management command to backfill historical GitHub activity into ActivityEvent.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title matches the main change by describing a management command to backfill ActivityEvent history.
Description check ✅ Passed The description clearly matches the changeset by describing the backfill command for existing GitHub activity.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Fix failing CI checks
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@github-actions

Copy link
Copy Markdown

Contribution validation failed:

@anurag2787 anurag2787 reopened this Jul 30, 2026
@github-actions

Copy link
Copy Markdown

Contribution validation failed:

3 similar comments
@github-actions

Copy link
Copy Markdown

Contribution validation failed:

@github-actions

Copy link
Copy Markdown

Contribution validation failed:

@github-actions

Copy link
Copy Markdown

Contribution validation failed:

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1b2c02f and 101805c.

📒 Files selected for processing (11)
  • backend/make/apps/owasp.mk
  • backend/src/apps/github/common.py
  • backend/src/apps/owasp/admin/__init__.py
  • backend/src/apps/owasp/admin/activity_event.py
  • backend/src/apps/owasp/management/commands/owasp_backfill_activity_events.py
  • backend/src/apps/owasp/migrations/0073_activityevent.py
  • backend/src/apps/owasp/models/__init__.py
  • backend/src/apps/owasp/models/activity_event.py
  • backend/tests/unit/apps/github/common_test.py
  • backend/tests/unit/apps/owasp/management/commands/owasp_backfill_activity_events_test.py
  • docker-compose/local/compose.override.yaml

Comment thread backend/src/apps/github/common.py
Comment thread backend/src/apps/owasp/admin/activity_event.py
Comment thread backend/src/apps/owasp/management/commands/owasp_backfill_activity_events.py Outdated
Comment thread backend/src/apps/owasp/management/commands/owasp_backfill_activity_events.py Outdated
Comment thread backend/src/apps/owasp/management/commands/owasp_backfill_activity_events.py Outdated
Comment thread backend/src/apps/owasp/management/commands/owasp_backfill_activity_events.py Outdated
Comment thread backend/src/apps/owasp/management/commands/owasp_backfill_activity_events.py Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 11 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread docker-compose/local/compose.override.yaml
Comment thread backend/src/apps/owasp/models/activity_event.py
Comment thread backend/make/apps/owasp.mk
Comment thread backend/src/apps/owasp/management/commands/owasp_backfill_activity_events.py Outdated
Comment thread backend/src/apps/owasp/management/commands/owasp_backfill_activity_events.py Outdated
@github-actions

Copy link
Copy Markdown

Contribution validation failed:

@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.03226% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.69%. Comparing base (c305ad6) to head (e716bd0).
⚠️ Report is 1 commits behind head on feature/owasp-pulse.

Files with missing lines Patch % Lines
backend/src/apps/owasp/models/activity_event.py 59.37% 26 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                   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              
Flag Coverage Δ
backend 99.17% <79.03%> (-0.20%) ⬇️
frontend 97.31% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
backend/src/apps/github/common.py 100.00% <100.00%> (ø)
backend/src/apps/owasp/admin/activity_event.py 100.00% <100.00%> (ø)
...agement/commands/owasp_backfill_activity_events.py 100.00% <100.00%> (ø)
backend/src/apps/owasp/models/activity_event.py 59.37% <59.37%> (ø)

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1b2c02f...e716bd0. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

Reject negative offsets before slicing.

--offset=-1 reaches queryset[-1:] at line 64; Django QuerySets do not support negative slicing and raise a non-command error. Validate offset >= 0 and raise CommandError instead.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 101805c and 279d99a.

📒 Files selected for processing (3)
  • backend/make/apps/owasp.mk
  • backend/src/apps/owasp/management/commands/owasp_backfill_activity_events.py
  • backend/tests/unit/apps/owasp/management/commands/owasp_backfill_activity_events_test.py

cubic-dev-ai[bot]
cubic-dev-ai Bot previously approved these changes Jul 30, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 3 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@github-actions

Copy link
Copy Markdown

Contribution validation failed:

@sonarqubecloud

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 1 file (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@github-actions

Copy link
Copy Markdown

Contribution validation failed:

@anurag2787

Copy link
Copy Markdown
Collaborator Author

Hi @arkid15r this is stack pr so only file need to be review for this pr is

  • backend/make/apps/owasp.mk
  • backend/src/apps/owasp/management/commands/owasp_backfill_activity_events.py
  • backend/tests/unit/apps/owasp/management/commands/owasp_backfill_activity_events_test.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend backend-tests gsoc2026:anurag2787 anurag2787's GSoC 2026 related work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant