Skip to content

feat(preprod): Add snapshot PR comment task and wiring#112360

Merged
runningcode merged 5 commits intomasterfrom
no/snapshot-pr-comment-task
Apr 14, 2026
Merged

feat(preprod): Add snapshot PR comment task and wiring#112360
runningcode merged 5 commits intomasterfrom
no/snapshot-pr-comment-task

Conversation

@runningcode
Copy link
Copy Markdown
Contributor

@runningcode runningcode commented Apr 7, 2026

Add Celery task that posts/updates GitHub PR comments for snapshot comparisons, and wire it into all existing trigger points.

Task (snapshot_tasks.py): Follows the build distribution PR comment pattern — locks CommitComparison rows to prevent duplicates, finds existing comments across PR commits, creates or updates via GitHub API, stores comment_id in extras["pr_comments"]["snapshots"]. Gated by feature flag organizations:preprod-snapshot-pr-comments and project option sentry:preprod_snapshot_pr_comments_enabled (both already registered).

Wiring: Triggered alongside the snapshot status check task at five entry points:

  • Comparison completion and failure (snapshots/tasks.py)
  • Upload completion (preprod_artifact_snapshot.py)
  • Approval via API (preprod_artifact_approve.py)
  • Approval via GitHub check run button (github_check_run.py)
  • Rerun status checks (preprod_artifact_rerun_status_checks.py)

I might have missed something so let me know if this should be added somewhere else!

Here's what this looks like using the test script: link
image

Depends on #112353.

Refs EME-999

@linear-code
Copy link
Copy Markdown

linear-code bot commented Apr 7, 2026

EME-999 PR comments

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 7, 2026
Base automatically changed from no/snapshot-pr-comment-templates to master April 9, 2026 06:59
Add Celery task that posts/updates GitHub PR comments for snapshot
comparisons. Follows the same pattern as build distribution PR
comments: locks CommitComparison rows, finds existing comment across
PR commits, creates or updates via GitHub API, stores comment_id in
extras["pr_comments"]["snapshots"].

Wire the task into all snapshot trigger points:
- Comparison completion/failure in snapshots/tasks.py
- Upload completion in snapshot endpoint
- Approval via API and GitHub check run webhook
- Rerun status checks endpoint
@runningcode runningcode marked this pull request as ready for review April 9, 2026 07:22
@runningcode runningcode requested a review from a team as a code owner April 9, 2026 07:22
Parameterize _find_existing_comment_id and _save_pr_comment_result by
comment_type so both build_distribution and snapshots tasks use the
same logic instead of maintaining near-identical copies.

api_error: Exception | None = None

with transaction.atomic(router.db_for_write(CommitComparison)):
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we lock here on the commit comparison. this is the same as what we do for build distirbution comments.

# update_comment instead of creating a duplicate.
if not comment_id:
existing = extras.get("pr_comments", {}).get("build_distribution", {})
existing = extras.get("pr_comments", {}).get(comment_type, {})
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we store the pr comment id in CommitComparison.extras, with keys build_distribution and snapshots for those respective features.

Adds a manual trigger script for testing snapshot PR comments
locally, mirroring the existing trigger_pr_comment and
trigger_snapshot_status_check scripts.
@@ -0,0 +1,396 @@
#!/usr/bin/env python
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is the script I used to test this. Similar to the other test scripts in this directory.

Copy link
Copy Markdown
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 89cd881. Configure here.

@runningcode runningcode requested a review from rbro112 April 9, 2026 15:02
Remove single-line wrapper functions _find_existing_comment_id and
_save_pr_comment_result, inlining the calls with the hardcoded
"build_distribution" argument directly at the call sites.

Rename _build_changes_map to build_changes_map and move it (along with
its helper _comparison_has_changes) from the status_checks snapshots
tasks module to sentry.preprod.snapshots.utils, since it is now shared
across multiple production modules.
@runningcode runningcode merged commit 5cd53c6 into master Apr 14, 2026
56 checks passed
@runningcode runningcode deleted the no/snapshot-pr-comment-task branch April 14, 2026 06:07
@vgrozdanic vgrozdanic added the Trigger: Revert Add to a merged PR to revert it (skips CI) label Apr 14, 2026
@getsentry-bot
Copy link
Copy Markdown
Contributor

PR reverted: 811e6cc

getsentry-bot added a commit that referenced this pull request Apr 14, 2026
…)"

This reverts commit 5cd53c6.

Co-authored-by: vgrozdanic <26199428+vgrozdanic@users.noreply.github.com>
@vgrozdanic
Copy link
Copy Markdown
Member

Reverted because it broke the CI, not sure why it wasn't caught during CI tests on this PR 🤔

FAILED tests/sentry/taskworker/test_config.py::test_all_instrumented_tasks_registered - AssertionError: Found 1 module(s) with @instrumented_task that are NOT registered in TASKWORKER_IMPORTS.
These tasks will not be discovered by the taskworker in production!

Missing modules:
  - sentry.preprod.vcs.pr_comments.snapshot_tasks

runningcode added a commit that referenced this pull request Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components Trigger: Revert Add to a merged PR to revert it (skips CI)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants