From fd842fd6fd1c90450e76b9ef54f402b10e85a145 Mon Sep 17 00:00:00 2001 From: Joe Becher Date: Wed, 13 May 2026 12:25:54 -0400 Subject: [PATCH 1/2] feat: handle ready_for_review webhook action to trigger PullsSync Co-Authored-By: Claude Sonnet 4.6 --- .../codecov-api/webhook_handlers/constants.py | 19 +++++++++++++++++++ .../webhook_handlers/tests/test_github.py | 15 +++++++++++++++ .../webhook_handlers/views/github.py | 13 ++++++++----- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/apps/codecov-api/webhook_handlers/constants.py b/apps/codecov-api/webhook_handlers/constants.py index 0f8a5a6014..c2ea95bf25 100644 --- a/apps/codecov-api/webhook_handlers/constants.py +++ b/apps/codecov-api/webhook_handlers/constants.py @@ -23,6 +23,25 @@ class GitHubWebhookEvents: repository_events = [PULL_REQUEST, DELETE, PUSH, PUBLIC, STATUS, REPOSITORY, MEMBER] +class GitHubPullRequestActions: + OPENED = "opened" + CLOSED = "closed" + REOPENED = "reopened" + SYNCHRONIZE = "synchronize" + LABELED = "labeled" + EDITED = "edited" + READY_FOR_REVIEW = "ready_for_review" + + PULLS_SYNC_ACTIONS = [ + OPENED, + CLOSED, + REOPENED, + SYNCHRONIZE, + LABELED, + READY_FOR_REVIEW, + ] + + class BitbucketHTTPHeaders: EVENT = "HTTP_X_EVENT_KEY" UUID = "HTTP_X_HOOK_UUID" diff --git a/apps/codecov-api/webhook_handlers/tests/test_github.py b/apps/codecov-api/webhook_handlers/tests/test_github.py index 563cf63e33..890853861a 100644 --- a/apps/codecov-api/webhook_handlers/tests/test_github.py +++ b/apps/codecov-api/webhook_handlers/tests/test_github.py @@ -509,6 +509,21 @@ def test_pull_request_triggers_pulls_sync_task_for_valid_actions( [call(repoid=self.repo.repoid, pullid=pull.pullid)] * len(valid_actions) ) + @patch("services.task.TaskService.pulls_sync") + def test_pull_request_ready_for_review_triggers_pulls_sync(self, pulls_sync_mock): + pull = PullFactory(repository=self.repo) + self._post_event_data( + event=GitHubWebhookEvents.PULL_REQUEST, + data={ + "repository": {"id": self.repo.service_id}, + "action": "ready_for_review", + "number": pull.pullid, + }, + ) + pulls_sync_mock.assert_called_once_with( + repoid=self.repo.repoid, pullid=pull.pullid + ) + def test_pull_request_updates_title_if_edited(self): pull = PullFactory(repository=self.repo) new_title = "brand new dang title" diff --git a/apps/codecov-api/webhook_handlers/views/github.py b/apps/codecov-api/webhook_handlers/views/github.py index e986fce2c8..a6cad2e46e 100644 --- a/apps/codecov-api/webhook_handlers/views/github.py +++ b/apps/codecov-api/webhook_handlers/views/github.py @@ -28,6 +28,7 @@ from utils.config import get_config from webhook_handlers.constants import ( GitHubHTTPHeaders, + GitHubPullRequestActions, GitHubWebhookEvents, WebhookHandlerErrorMessages, ) @@ -316,15 +317,17 @@ def pull_request(self, request, *args, **kwargs): if not repo.active: return Response(data=WebhookHandlerErrorMessages.SKIP_NOT_ACTIVE) - action, pullid = request.data.get("action"), request.data.get("number") - - if action in ["opened", "closed", "reopened", "synchronize", "labeled"]: - TaskService().pulls_sync(repoid=repo.repoid, pullid=pullid) + action = request.data.get("action") + pullid = request.data.get("number") - elif action == "edited": + if action == GitHubPullRequestActions.EDITED: Pull.objects.filter(repository=repo, pullid=pullid).update( title=request.data.get("pull_request", {}).get("title") ) + return Response() + + if action in GitHubPullRequestActions.PULLS_SYNC_ACTIONS: + TaskService().pulls_sync(repoid=repo.repoid, pullid=pullid) return Response() From 8ae9a8282f43d2a84ceaaf95e2e251c287d2a9b6 Mon Sep 17 00:00:00 2001 From: Joe Becher Date: Thu, 14 May 2026 11:11:28 -0400 Subject: [PATCH 2/2] Alphabetize GitHubPullRequestActions, separate EDITED Co-Authored-By: Claude Sonnet 4.6 --- apps/codecov-api/webhook_handlers/constants.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/codecov-api/webhook_handlers/constants.py b/apps/codecov-api/webhook_handlers/constants.py index c2ea95bf25..054a4a86d1 100644 --- a/apps/codecov-api/webhook_handlers/constants.py +++ b/apps/codecov-api/webhook_handlers/constants.py @@ -24,21 +24,22 @@ class GitHubWebhookEvents: class GitHubPullRequestActions: - OPENED = "opened" CLOSED = "closed" + LABELED = "labeled" + OPENED = "opened" + READY_FOR_REVIEW = "ready_for_review" REOPENED = "reopened" SYNCHRONIZE = "synchronize" - LABELED = "labeled" + EDITED = "edited" - READY_FOR_REVIEW = "ready_for_review" PULLS_SYNC_ACTIONS = [ - OPENED, CLOSED, - REOPENED, - SYNCHRONIZE, LABELED, + OPENED, READY_FOR_REVIEW, + REOPENED, + SYNCHRONIZE, ]