Skip to content

Commit

Permalink
add upload type to tornigit baseclass constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian-codecov committed Dec 9, 2024
1 parent 13c6e59 commit 3e0a819
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 21 deletions.
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
12 changes: 1 addition & 11 deletions services/notification/notifiers/mixins/message/sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 (
Expand Down
10 changes: 1 addition & 9 deletions services/notification/notifiers/mixins/message/writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,14 @@ 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
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
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."
Expand Down
9 changes: 8 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,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,
Expand All @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions services/tests/test_owner_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions services/tests/test_repository_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 == {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 == {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3e0a819

Please sign in to comment.