Skip to content

Commit

Permalink
2876 no copilot for ba comment (#953)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian-codecov authored Dec 16, 2024
1 parent 2470ecc commit 0f8147b
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 5 deletions.
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
https://github.com/codecov/test-results-parser/archive/c840502d1b4dd7d05b2efc2c1328affaf2acd27c.tar.gz#egg=test-results-parser
https://github.com/codecov/shared/archive/8c5de3fadd3c987304043c6cfd64864f372d674f.tar.gz#egg=shared
https://github.com/codecov/shared/archive/e41a4a1d4dd4efe44a917b47032f1a0d73775426.tar.gz#egg=shared
https://github.com/codecov/timestring/archive/d37ceacc5954dff3b5bd2f887936a98a668dda42.tar.gz#egg=timestring
asgiref>=3.7.2
analytics-python==1.3.0b1
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ sentry-sdk==2.13.0
# shared
setuptools==75.6.0
# via nodeenv
shared @ https://github.com/codecov/shared/archive/8c5de3fadd3c987304043c6cfd64864f372d674f.tar.gz#egg=shared
shared @ https://github.com/codecov/shared/archive/e41a4a1d4dd4efe44a917b47032f1a0d73775426.tar.gz#egg=shared
# via -r requirements.in
six==1.16.0
# via
Expand Down
3 changes: 3 additions & 0 deletions services/bundle_analysis/notify/contexts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import shared.storage
from shared.bundle_analysis import BundleAnalysisReport, BundleAnalysisReportLoader
from shared.torngit.base import TorngitBaseAdapter
from shared.typings.torngit import AdditionalData, UploadType
from shared.validation.types import BundleThreshold
from shared.yaml import UserYaml

Expand Down Expand Up @@ -79,9 +80,11 @@ def repository(self) -> Repository:

@cached_property
def repository_service(self) -> TorngitBaseAdapter:
additional_data: AdditionalData = {"upload_type": UploadType.BUNDLE_ANALYSIS}
return get_repo_provider_service(
self.repository,
installation_name_to_use=self.gh_app_installation_name,
additional_data=additional_data,
)

commit_report = NotificationContextField[CommitReport]()
Expand Down
7 changes: 6 additions & 1 deletion services/owner.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
log = logging.getLogger(__name__)


def get_owner_provider_service(owner, *, ignore_installation=False):
def get_owner_provider_service(
owner, *, ignore_installation=False, additional_data=None
):
_timeouts = [
get_config("setup", "http", "timeouts", "connect", default=15),
get_config("setup", "http", "timeouts", "receive", default=30),
Expand All @@ -23,12 +25,15 @@ def get_owner_provider_service(owner, *, ignore_installation=False):
adapter_auth_info = get_adapter_auth_information(
owner, ignore_installations=ignore_installation
)
if additional_data is None:
additional_data = {}
data = TorngitInstanceData(
owner=OwnerInfo(
service_id=owner.service_id, ownerid=owner.ownerid, username=owner.username
),
installation=adapter_auth_info["selected_installation_info"],
fallback_installations=adapter_auth_info["fallback_installations"],
additional_data=additional_data,
)

adapter_params = dict(
Expand Down
11 changes: 10 additions & 1 deletion services/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
TorngitError,
TorngitObjectNotFoundError,
)
from shared.typings.torngit import OwnerInfo, RepoInfo, TorngitInstanceData
from shared.typings.torngit import (
AdditionalData,
OwnerInfo,
RepoInfo,
TorngitInstanceData,
)
from shared.validation.exceptions import InvalidYamlException
from shared.yaml import UserYaml
from shared.yaml.user_yaml import OwnerContext
Expand All @@ -39,12 +44,15 @@
def get_repo_provider_service(
repository: Repository,
installation_name_to_use: str = GITHUB_APP_INSTALLATION_DEFAULT_NAME,
additional_data: AdditionalData = None,
) -> TorngitBaseAdapter:
adapter_auth_info = get_adapter_auth_information(
repository.owner,
repository=repository,
installation_name_to_use=installation_name_to_use,
)
if additional_data is None:
additional_data = {}
data = TorngitInstanceData(
repo=RepoInfo(
name=repository.name,
Expand All @@ -61,6 +69,7 @@ def get_repo_provider_service(
),
installation=adapter_auth_info["selected_installation_info"],
fallback_installations=adapter_auth_info["fallback_installations"],
additional_data=additional_data,
)

adapter_params = dict(
Expand Down
33 changes: 33 additions & 0 deletions services/tests/test_owner_service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from shared.rate_limits import gh_app_key_name, owner_key_name
from shared.reports.types import UploadType
from shared.typings.torngit import AdditionalData

from database.models.core import (
GITHUB_APP_INSTALLATION_DEFAULT_NAME,
Expand Down Expand Up @@ -27,6 +29,7 @@ def test_get_owner_provider_service(self, dbsession):
"repo": {},
"installation": None,
"fallback_installations": None,
"additional_data": {},
}
assert res.service == "github"
assert res.data == expected_data
Expand Down Expand Up @@ -70,6 +73,7 @@ def test_get_owner_provider_service_with_installation(self, dbsession, mocker):
"app_id": None,
},
"fallback_installations": [],
"additional_data": {},
}
assert res.service == "github"
assert res.data == expected_data
Expand All @@ -96,6 +100,7 @@ def test_get_owner_provider_service_other_service(self, dbsession):
"repo": {},
"installation": None,
"fallback_installations": None,
"additional_data": {},
}
assert res.service == "gitlab"
assert res.data == expected_data
Expand Down Expand Up @@ -123,6 +128,7 @@ def test_get_owner_provider_service_different_bot(self, dbsession):
"repo": {},
"installation": None,
"fallback_installations": None,
"additional_data": {},
}
assert res.data["repo"] == expected_data["repo"]
assert res.data == expected_data
Expand All @@ -131,3 +137,30 @@ def test_get_owner_provider_service_different_bot(self, dbsession):
"secret": None,
"entity_name": owner_key_name(owner.bot.ownerid),
}

def test_get_owner_provider_service_additional_data(self, dbsession):
owner = OwnerFactory.create(
service="gitlab", unencrypted_oauth_token="testenll80qbqhofao65", bot=None
)
dbsession.add(owner)
dbsession.flush()
additional_data: AdditionalData = {"upload_type": UploadType.BUNDLE_ANALYSIS}
res = get_owner_provider_service(owner, additional_data=additional_data)
expected_data = {
"owner": {
"ownerid": owner.ownerid,
"service_id": owner.service_id,
"username": owner.username,
},
"repo": {},
"installation": None,
"fallback_installations": None,
"additional_data": {"upload_type": UploadType.BUNDLE_ANALYSIS},
}
assert res.service == "gitlab"
assert res.data == expected_data
assert res.token == {
"key": "testenll80qbqhofao65",
"secret": None,
"entity_name": owner_key_name(owner.ownerid),
}
41 changes: 41 additions & 0 deletions services/tests/test_repository_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
from freezegun import freeze_time
from shared.encryption.oauth import get_encryptor_from_configuration
from shared.rate_limits import gh_app_key_name, owner_key_name
from shared.reports.types import UploadType
from shared.torngit.base import TorngitBaseAdapter
from shared.torngit.exceptions import (
TorngitClientError,
TorngitObjectNotFoundError,
TorngitServerUnreachableError,
)
from shared.typings.torngit import (
AdditionalData,
GithubInstallationInfo,
OwnerInfo,
RepoInfo,
Expand Down Expand Up @@ -83,6 +85,38 @@ def test_get_repo_provider_service_github(dbsession, repo):
},
"installation": None,
"fallback_installations": None,
"additional_data": {},
}
assert res.data == expected_data
assert repo.owner.service == "github"
assert res._on_token_refresh is not None
assert inspect.isawaitable(res._on_token_refresh(None))
assert res.token == {
"username": repo.owner.username,
"key": "testyftq3ovzkb3zmt823u3t04lkrt9w",
"secret": None,
"entity_name": owner_key_name(repo.owner.ownerid),
}


def test_get_repo_provider_service_additional_data(dbsession, repo):
additional_data: AdditionalData = {"upload_type": UploadType.TEST_RESULTS}
res = get_repo_provider_service(repo, additional_data=additional_data)
expected_data = {
"owner": {
"ownerid": repo.owner.ownerid,
"service_id": repo.owner.service_id,
"username": repo.owner.username,
},
"repo": {
"name": "example-python",
"using_integration": False,
"service_id": repo.service_id,
"repoid": repo.repoid,
},
"installation": None,
"fallback_installations": None,
"additional_data": {"upload_type": UploadType.TEST_RESULTS},
}
assert res.data == expected_data
assert repo.owner.service == "github"
Expand Down Expand Up @@ -146,6 +180,7 @@ def test_get_repo_provider_service_github_with_installations(dbsession, mocker,
"pem_path": None,
}
],
"additional_data": {},
}
assert res.data == expected_data
assert repo.owner.service == "github"
Expand Down Expand Up @@ -182,6 +217,7 @@ def test_get_repo_provider_service_bitbucket(dbsession):
},
"installation": None,
"fallback_installations": None,
"additional_data": {},
}
assert res.data == expected_data
assert repo.owner.service == "bitbucket"
Expand Down Expand Up @@ -217,6 +253,7 @@ def test_get_repo_provider_service_with_token_refresh_callback(dbsession):
},
"installation": None,
"fallback_installations": None,
"additional_data": {},
}
assert res.data == expected_data
assert res._on_token_refresh is not None
Expand Down Expand Up @@ -253,6 +290,7 @@ def test_get_repo_provider_service_repo_bot(dbsession, mock_configuration):
},
"installation": None,
"fallback_installations": None,
"additional_data": {},
}
assert res.data == expected_data
assert res.token == {
Expand Down Expand Up @@ -309,6 +347,7 @@ def test_get_repo_provider_service_different_bot(dbsession):
},
"installation": None,
"fallback_installations": None,
"additional_data": {},
}
assert res.data["repo"] == expected_data["repo"]
assert res.data == expected_data
Expand Down Expand Up @@ -347,6 +386,7 @@ def test_get_repo_provider_service_no_bot(dbsession):
},
"installation": None,
"fallback_installations": None,
"additional_data": {},
}
assert res.data == expected_data
assert res.token == {
Expand Down Expand Up @@ -1093,6 +1133,7 @@ async def test_get_repo_gh_no_integration(dbsession, mocker):
},
"installation": None,
"fallback_installations": None,
"additional_data": {},
}
assert res.data["repo"] == expected_data["repo"]
assert res.data == expected_data
Expand Down
5 changes: 4 additions & 1 deletion tasks/test_results_finisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from typing import Any

from asgiref.sync import async_to_sync
from shared.reports.types import UploadType
from shared.typings.torngit import AdditionalData
from shared.yaml import UserYaml
from sqlalchemy.orm import Session

Expand Down Expand Up @@ -230,7 +232,8 @@ def process_impl_within_lock(
"queue_notify": True,
}

repo_service = get_repo_provider_service(repo)
additional_data: AdditionalData = {"upload_type": UploadType.TEST_RESULTS}
repo_service = get_repo_provider_service(repo, additional_data=additional_data)
pull = async_to_sync(fetch_and_update_pull_request_information_from_commit)(
repo_service, commit, commit_yaml
)
Expand Down

0 comments on commit 0f8147b

Please sign in to comment.