Skip to content

Commit e5be426

Browse files
feat: handle ready_for_review webhook action (#920)
* feat: handle ready_for_review webhook action to trigger PullsSync Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Alphabetize GitHubPullRequestActions, separate EDITED Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent d507da5 commit e5be426

3 files changed

Lines changed: 43 additions & 5 deletions

File tree

apps/codecov-api/webhook_handlers/constants.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,26 @@ class GitHubWebhookEvents:
2323
repository_events = [PULL_REQUEST, DELETE, PUSH, PUBLIC, STATUS, REPOSITORY, MEMBER]
2424

2525

26+
class GitHubPullRequestActions:
27+
CLOSED = "closed"
28+
LABELED = "labeled"
29+
OPENED = "opened"
30+
READY_FOR_REVIEW = "ready_for_review"
31+
REOPENED = "reopened"
32+
SYNCHRONIZE = "synchronize"
33+
34+
EDITED = "edited"
35+
36+
PULLS_SYNC_ACTIONS = [
37+
CLOSED,
38+
LABELED,
39+
OPENED,
40+
READY_FOR_REVIEW,
41+
REOPENED,
42+
SYNCHRONIZE,
43+
]
44+
45+
2646
class BitbucketHTTPHeaders:
2747
EVENT = "HTTP_X_EVENT_KEY"
2848
UUID = "HTTP_X_HOOK_UUID"

apps/codecov-api/webhook_handlers/tests/test_github.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,21 @@ def test_pull_request_triggers_pulls_sync_task_for_valid_actions(
509509
[call(repoid=self.repo.repoid, pullid=pull.pullid)] * len(valid_actions)
510510
)
511511

512+
@patch("services.task.TaskService.pulls_sync")
513+
def test_pull_request_ready_for_review_triggers_pulls_sync(self, pulls_sync_mock):
514+
pull = PullFactory(repository=self.repo)
515+
self._post_event_data(
516+
event=GitHubWebhookEvents.PULL_REQUEST,
517+
data={
518+
"repository": {"id": self.repo.service_id},
519+
"action": "ready_for_review",
520+
"number": pull.pullid,
521+
},
522+
)
523+
pulls_sync_mock.assert_called_once_with(
524+
repoid=self.repo.repoid, pullid=pull.pullid
525+
)
526+
512527
def test_pull_request_updates_title_if_edited(self):
513528
pull = PullFactory(repository=self.repo)
514529
new_title = "brand new dang title"

apps/codecov-api/webhook_handlers/views/github.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from utils.config import get_config
2929
from webhook_handlers.constants import (
3030
GitHubHTTPHeaders,
31+
GitHubPullRequestActions,
3132
GitHubWebhookEvents,
3233
WebhookHandlerErrorMessages,
3334
)
@@ -316,15 +317,17 @@ def pull_request(self, request, *args, **kwargs):
316317
if not repo.active:
317318
return Response(data=WebhookHandlerErrorMessages.SKIP_NOT_ACTIVE)
318319

319-
action, pullid = request.data.get("action"), request.data.get("number")
320-
321-
if action in ["opened", "closed", "reopened", "synchronize", "labeled"]:
322-
TaskService().pulls_sync(repoid=repo.repoid, pullid=pullid)
320+
action = request.data.get("action")
321+
pullid = request.data.get("number")
323322

324-
elif action == "edited":
323+
if action == GitHubPullRequestActions.EDITED:
325324
Pull.objects.filter(repository=repo, pullid=pullid).update(
326325
title=request.data.get("pull_request", {}).get("title")
327326
)
327+
return Response()
328+
329+
if action in GitHubPullRequestActions.PULLS_SYNC_ACTIONS:
330+
TaskService().pulls_sync(repoid=repo.repoid, pullid=pullid)
328331

329332
return Response()
330333

0 commit comments

Comments
 (0)