ref(code_review): Split transform_webhook_to_codegen_request#106398
ref(code_review): Split transform_webhook_to_codegen_request#106398
Conversation
Currently, `transform_webhook_to_codegen_request` is executed as part of the task, however, we want to execute prior to scheduling the task. Splitting this function helps with comprehension and will help each GitHub event have its own data transformation path.
def541b to
b930edb
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
|
@sentry review |
| MISSING_PULL_REQUEST = "github.webhook.pull_request.missing-pull-request" | ||
| MISSING_ACTION = "github.webhook.pull_request.missing-action" | ||
| UNSUPPORTED_ACTION = "github.webhook.pull_request.unsupported-action" | ||
| DRAFT_PR = "github.webhook.pull_request.draft-pr" |
There was a problem hiding this comment.
We really don't care to track this since we don't run on drafts.
| if pull_request.get("draft") is True: | ||
| # Skip draft check for CLOSED actions to ensure Seer receives cleanup notifications | ||
| # even if the PR was converted to draft before closing | ||
| if action != PullRequestAction.CLOSED and pull_request.get("draft") is True: |
There was a problem hiding this comment.
We recently added support for closed, however, we need to report to Seer even if it's a draft.
| } | ||
|
|
||
|
|
||
| def _get_trigger_metadata( |
| self.mock_reaction.assert_not_called() | ||
| self.mock_seer.assert_not_called() | ||
|
|
||
| def test_skips_regular_issue_comments(self) -> None: |
There was a problem hiding this comment.
The new tests are basically some of the tests of test_utils.py.
These convert them from unit tests to integration tests.
| assert payload["data"]["config"]["trigger_comment_id"] is None | ||
| assert payload["data"]["config"]["trigger_comment_type"] is None | ||
|
|
||
| def test_pull_request_closed_draft_still_sends_to_seer(self) -> None: |
There was a problem hiding this comment.
This is the test case missing from yesterday's close pull request support.
| comment_body = comment.get("body") | ||
|
|
||
| issue = event.get("issue", {}) | ||
| if not issue.get("pull_request"): |
There was a problem hiding this comment.
We have been unnecessarily scheduling tasks for GitHub comments that are not part of a pull request. This will drop the numbered of scheduled tasks.
| except OrganizationContributors.DoesNotExist: | ||
| metrics.incr( | ||
| "seer.code_review.error.contributor_not_found", | ||
| tags={"organization_id": organization_id}, |
There was a problem hiding this comment.
Our metrics module should raise errors about forbidden tags, however, it only shows up in the output. I noticed while running tests.
| @@ -171,7 +158,7 @@ def _get_target_commit_sha( | |||
| # XXX: Refactor this function to handle it at the handler level rather than during task execution | |||
| def transform_webhook_to_codegen_request( | |||
| trigger_user = event_payload.get("sender", {}).get("login") or event_payload.get( | ||
| "pull_request", {} | ||
| ).get("user", {}).get("login") | ||
| # Prioritize sender (person who triggered the action) over PR author |
|
@cursoragent resolve the conflicts |
|
Perfect! I've successfully resolved the merge conflicts and pushed the changes. Here's what I did: Conflict Resolution:
Changes Made:
The branch is now clean and up to date with master, with all conflicts resolved while preserving your PR's refactored code structure. |
- Integrated integration_id handling from master into _build_repo_definition - Maintained refactored structure with separate transform functions Co-authored-by: armenzg <armenzg@sentry.io>
|
|
||
| def _build_repo_definition(repo: Repository, target_commit_sha: str) -> dict[str, Any]: | ||
| """ | ||
| Build the repository definition for the CodecovTaskRequest. |
There was a problem hiding this comment.
Is it really called CodecovTaskRequest? We should rename that 😅
Currently, `transform_webhook_to_codegen_request` is executed for both `issue_comment` and `pull_request`. This decouples the two event types to help comprehension. I also want all data manipulations to happen in the same location rather than throughout different stages (this currently happens during pre-scheduling task & after task scheduling). This also fixes this issue: * Prevent orphaned state in Seer by allowing CLOSED events through even for draft PRs Improvements: * Non-PR comments filtered earlier in the flow, thus, we won't unnecesarily schedule them * Clean separation of concerns with dedicated transform functions for each webhook type * DRAFT_PR removed from error types since it's a filter condition, not an error --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>


Currently,
transform_webhook_to_codegen_requestis executed for bothissue_commentandpull_request. This decouples the two event types to help comprehension. I also want all data manipulations to happen in the same location rather than throughout different stages (this currently happens during pre-scheduling task & after task scheduling).This also fixes this issue:
Improvements: