diff --git a/services/bundle_analysis/notify/contexts/__init__.py b/services/bundle_analysis/notify/contexts/__init__.py index 414b09b91..139813558 100644 --- a/services/bundle_analysis/notify/contexts/__init__.py +++ b/services/bundle_analysis/notify/contexts/__init__.py @@ -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 @@ -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]() diff --git a/services/notification/notifiers/mixins/message/sections.py b/services/notification/notifiers/mixins/message/sections.py index 3c8545e6e..0efaeb7ab 100644 --- a/services/notification/notifiers/mixins/message/sections.py +++ b/services/notification/notifiers/mixins/message/sections.py @@ -8,7 +8,6 @@ from shared.helpers.yaml import walk from shared.reports.resources import Report -from shared.reports.types import ReportTotals from helpers.environment import is_enterprise from helpers.reports import get_totals_from_file_in_reports @@ -124,22 +123,13 @@ def do_write_section(self, comparison, diff, changes, links, behind_by=None): head_report = comparison.head.report pull_dict = comparison.enriched_pull.provider_pull - diff_totals: ReportTotals = head_report.apply_diff(diff) - files_in_diff = diff_totals and diff_totals.files - + diff_totals = head_report.apply_diff(diff) if diff_totals: misses_and_partials = diff_totals.misses + diff_totals.partials patch_coverage = diff_totals.coverage else: misses_and_partials = None patch_coverage = None - # # When your diff changes include non-coverable - # if files_in_diff == 0: - # print("le ici") - # yield ( - # f"No coverable files are found to report :thumbsup:" - # ) - # return if misses_and_partials: ln_text = "lines" if misses_and_partials > 1 else "line" yield ( diff --git a/services/notification/notifiers/mixins/message/writers.py b/services/notification/notifiers/mixins/message/writers.py index 23131ef8f..130263adf 100644 --- a/services/notification/notifiers/mixins/message/writers.py +++ b/services/notification/notifiers/mixins/message/writers.py @@ -29,7 +29,6 @@ def header_lines(self, comparison: ComparisonProxy, diff, settings) -> List[str] head_report = comparison.head.report diff_totals = head_report.apply_diff(diff) - files_in_diff = diff_totals.files if diff_totals: misses_and_partials = diff_totals.misses + diff_totals.partials @@ -37,14 +36,7 @@ def header_lines(self, comparison: ComparisonProxy, diff, settings) -> List[str] else: misses_and_partials = None patch_coverage = None - # When your diff changes include non-coverable - if files_in_diff == 0: - print("le ici") - yield ( - f"No coverable files are found to report :thumbsup:" - ) - return - elif misses_and_partials: + if misses_and_partials: ln_text = "lines" if misses_and_partials > 1 else "line" lines.append( f"Attention: Patch coverage is `{patch_coverage}%` with `{misses_and_partials} {ln_text}` in your changes missing coverage. Please review." diff --git a/services/repository.py b/services/repository.py index 86f074915..35ab227fc 100644 --- a/services/repository.py +++ b/services/repository.py @@ -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 @@ -39,6 +44,7 @@ def get_repo_provider_service( repository: Repository, installation_name_to_use: str = GITHUB_APP_INSTALLATION_DEFAULT_NAME, + additional_data: AdditionalData = {}, ) -> TorngitBaseAdapter: adapter_auth_info = get_adapter_auth_information( repository.owner, @@ -61,6 +67,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( diff --git a/services/tests/test_owner_service.py b/services/tests/test_owner_service.py index ab1e454bd..20ce6e827 100644 --- a/services/tests/test_owner_service.py +++ b/services/tests/test_owner_service.py @@ -27,6 +27,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 @@ -70,6 +71,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 @@ -96,6 +98,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 @@ -123,6 +126,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 diff --git a/services/tests/test_repository_service.py b/services/tests/test_repository_service.py index 001fcbb49..5d067ff23 100644 --- a/services/tests/test_repository_service.py +++ b/services/tests/test_repository_service.py @@ -83,6 +83,7 @@ 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" @@ -146,6 +147,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" @@ -182,6 +184,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" @@ -217,6 +220,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 @@ -253,6 +257,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 == { @@ -309,6 +314,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 @@ -347,6 +353,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 == { @@ -1093,6 +1100,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