Skip to content
Closed
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
14 changes: 13 additions & 1 deletion apps/worker/tasks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
)
from shared.metrics import Counter, Histogram
from shared.torngit.base import TorngitBaseAdapter
from shared.torngit.exceptions import TorngitClientError, TorngitRepoNotFoundError
from shared.torngit.exceptions import TorngitClientError, TorngitRefreshTokenFailedError, TorngitRepoNotFoundError
from shared.typings.torngit import AdditionalData
from shared.utils.sentry import current_sentry_trace_id

Expand Down Expand Up @@ -637,6 +637,18 @@ def get_repo_provider_service(
"Unable to reach git provider because this specific bot/integration can't see that repository",
extra={"repoid": repository.repoid},
)
except TorngitRefreshTokenFailedError:
if commit:
self._call_upload_breadcrumb_task(
commit_sha=commit.commitid,
repo_id=repository.repoid,
error=Errors.GIT_CLIENT_ERROR,
)
log.warning(
"Unable to refresh git provider token",
extra={"repoid": repository.repoid},
exc_info=True,
)
except TorngitClientError:
if commit:
self._call_upload_breadcrumb_task(
Expand Down
31 changes: 30 additions & 1 deletion apps/worker/tasks/tests/unit/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
)
from shared.django_apps.upload_breadcrumbs.models import BreadcrumbData, Errors
from shared.plan.constants import PlanName
from shared.torngit.exceptions import TorngitClientError
from shared.torngit.exceptions import TorngitClientError, TorngitRefreshTokenFailedError
from tasks.base import BaseCodecovRequest, BaseCodecovTask
from tasks.base import celery_app as base_celery_app
from tests.helpers import mock_all_plans_and_tiers
Expand Down Expand Up @@ -420,6 +420,35 @@ def test_get_repo_provider_service_torngit_client_error(
}
)

def test_get_repo_provider_service_refresh_token_failed(
self, mocker, mock_self_app
):
mocker.patch(
"tasks.base.get_repo_provider_service",
side_effect=TorngitRefreshTokenFailedError("400 Bad Request"),
)

task = BaseCodecovTask()
mock_repo = mocker.MagicMock()
mock_repo.repoid = 8
mock_commit = mocker.MagicMock()
mock_commit.commitid = "abc123"
result = task.get_repo_provider_service(mock_repo, commit=mock_commit)
assert result is None
mock_self_app.tasks[
upload_breadcrumb_task_name
].apply_async.assert_called_once_with(
kwargs={
"commit_sha": mock_commit.commitid,
"repo_id": mock_repo.repoid,
"breadcrumb_data": BreadcrumbData(
error=Errors.GIT_CLIENT_ERROR,
),
"upload_ids": [],
"sentry_trace_id": None,
}
)

def test_call_upload_breadcrumb_task_exception(self, mocker, mock_self_app):
exception = Exception("Test exception")
mocker.patch("tasks.base.get_repo_provider_service", side_effect=exception)
Expand Down
Loading