Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions apps/codecov-api/webhook_handlers/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,26 @@ class GitHubWebhookEvents:
repository_events = [PULL_REQUEST, DELETE, PUSH, PUBLIC, STATUS, REPOSITORY, MEMBER]


class GitHubPullRequestActions:
CLOSED = "closed"
LABELED = "labeled"
OPENED = "opened"
READY_FOR_REVIEW = "ready_for_review"
REOPENED = "reopened"
SYNCHRONIZE = "synchronize"

EDITED = "edited"
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.

nit: alphabetize this list, and separate EDITED after (could even add whitespace before). I got confused and thought EDITED was part of PULLS_SYNC_ACTIONS


PULLS_SYNC_ACTIONS = [
CLOSED,
LABELED,
OPENED,
READY_FOR_REVIEW,
REOPENED,
SYNCHRONIZE,
]


class BitbucketHTTPHeaders:
EVENT = "HTTP_X_EVENT_KEY"
UUID = "HTTP_X_HOOK_UUID"
Expand Down
15 changes: 15 additions & 0 deletions apps/codecov-api/webhook_handlers/tests/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 8 additions & 5 deletions apps/codecov-api/webhook_handlers/views/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from utils.config import get_config
from webhook_handlers.constants import (
GitHubHTTPHeaders,
GitHubPullRequestActions,
GitHubWebhookEvents,
WebhookHandlerErrorMessages,
)
Expand Down Expand Up @@ -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()

Expand Down
Loading