Skip to content

Commit

Permalink
Merge branch 'main' into joseph/fix-test-results-notify
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-sentry authored Feb 22, 2024
2 parents 0a1ea45 + ab83780 commit 0eea563
Show file tree
Hide file tree
Showing 24 changed files with 692 additions and 217 deletions.
13 changes: 1 addition & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,10 @@ jobs:
uses: codecov/gha-workflows/.github/workflows/[email protected]
secrets: inherit

ats:
name: ATS
needs: [build]
if: ${{ !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov' }}
uses: codecov/gha-workflows/.github/workflows/[email protected]
secrets: inherit
with:
repo: ${{ vars.CODECOV_IMAGE_V2 || 'codecov/self-hosted-worker' }}
codecov_cli_upload_args: '--plugin pycoverage --plugin compress-pycoverage --flag onlysomelabels'
app_container_name: worker

test:
name: Test
needs: [build]
uses: codecov/gha-workflows/.github/workflows/[email protected].12
uses: codecov/gha-workflows/.github/workflows/[email protected].15
secrets: inherit
with:
repo: ${{ vars.CODECOV_IMAGE_V2 || 'codecov/self-hosted-worker' }}
Expand Down
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export WORKER_DOCKER_VERSION=${VERSION}
export CODECOV_TOKEN=${CODECOV_UPLOAD_TOKEN}

# Codecov CLI version to use
CODECOV_CLI_VERSION := 0.4.1
CODECOV_CLI_VERSION := 0.4.6

build:
$(MAKE) build.requirements
Expand All @@ -48,13 +48,13 @@ lint:
make lint.run

test:
python -m pytest --cov=./
python -m pytest --cov=./ --junitxml=junit.xml

test.unit:
python -m pytest --cov=./ -m "not integration" --cov-report=xml:unit.coverage.xml
python -m pytest --cov=./ -m "not integration" --cov-report=xml:unit.coverage.xml --junitxml=unit.junit.xml

test.integration:
python -m pytest --cov=./ -m "integration" --cov-report=xml:integration.coverage.xml
python -m pytest --cov=./ -m "integration" --cov-report=xml:integration.coverage.xml --junitxml=integration.junit.xml


update-requirements:
Expand Down Expand Up @@ -220,12 +220,16 @@ test_env.run_integration:

test_env.upload:
docker-compose exec worker make test_env.container_upload CODECOV_UPLOAD_TOKEN=${CODECOV_UPLOAD_TOKEN} CODECOV_URL=${CODECOV_URL}
docker-compose exec worker make test_env.container_upload_test_results CODECOV_UPLOAD_TOKEN=${CODECOV_UPLOAD_TOKEN} CODECOV_URL=${CODECOV_URL}

test_env.container_upload:
codecovcli -u ${CODECOV_URL} do-upload --flag latest-uploader-overall
codecovcli -u ${CODECOV_URL} do-upload --flag unit --file unit.coverage.xml
codecovcli -u ${CODECOV_URL} do-upload --flag integration --file integration.coverage.xml

test_env.container_upload_test_results:
codecovcli -v -u ${CODECOV_URL} do-upload --report-type test_results || true

test_env.static_analysis:
docker-compose exec worker make test_env.container_static_analysis CODECOV_STATIC_TOKEN=${CODECOV_STATIC_TOKEN}

Expand Down
3 changes: 3 additions & 0 deletions database/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ class GithubAppInstallation(CodecovBaseModel, MixinBaseClass):
repository_service_ids = Column(
postgresql.ARRAY(types.Text), server_default=FetchedValue()
)
# Data required to get a token from gh
app_id = Column(types.Text, server_default=FetchedValue())
pem_path = Column(types.Text, server_default=FetchedValue())

ownerid = Column("owner_id", types.Integer, ForeignKey("owners.ownerid"))
owner = relationship(
Expand Down
5 changes: 3 additions & 2 deletions requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ coverage
factory-boy
google-cloud-storage>=2.10.0
httpx
jinja2
jinja2>=3.1.3
analytics-python==1.3.0b1
lxml>=4.9.1
mock
Expand All @@ -25,11 +25,12 @@ pytest-freezegun
pytest
python-dateutil
python-json-logger
python-redis-lock
PyYAML
redis>=4.4.4
requests>=2.31.0
respx
sentry-sdk
sentry-sdk>=1.40.0
SQLAlchemy-Utils
SQLAlchemy
statsd
Expand Down
16 changes: 7 additions & 9 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#
# This file is autogenerated by pip-compile with Python 3.9
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# pip-compile
# pip-compile requirements.in
#
amqp==5.1.0
# via kombu
Expand Down Expand Up @@ -102,8 +102,6 @@ ecdsa==0.18.0
# via tlslite-ng
excel-base==1.0.4
# via django-excel-response2
exceptiongroup==1.2.0
# via pytest
factory-boy==3.2.0
# via -r requirements.in
faker==8.8.2
Expand Down Expand Up @@ -183,7 +181,7 @@ iniconfig==1.1.1
# via pytest
isoweek==1.3.3
# via timeconvert
jinja2==3.1.2
jinja2==3.1.3
# via -r requirements.in
jmespath==0.10.0
# via
Expand Down Expand Up @@ -308,6 +306,8 @@ python-dateutil==2.8.1
# timeconvert
python-json-logger==0.1.11
# via -r requirements.in
python-redis-lock==4.0.0
# via -r requirements.in
pytz==2022.1
# via
# celery
Expand All @@ -321,6 +321,7 @@ pyyaml==6.0.1
redis==4.5.4
# via
# -r requirements.in
# python-redis-lock
# shared
requests==2.31.0
# via
Expand All @@ -342,7 +343,7 @@ s3transfer==0.3.4
# via boto3
screen==1.0.1
# via excel-base
sentry-sdk==1.19.1
sentry-sdk==1.40.0
# via -r requirements.in
shared @ https://github.com/codecov/shared/archive/55c9af294031d3027fed9b49a83153cacf437bdb.tar.gz
# via -r requirements.in
Expand Down Expand Up @@ -388,15 +389,12 @@ timestring==1.6.4
# via -r requirements.in
tlslite-ng==0.8.0b1
# via shared
tomli==2.0.1
# via pytest
tqdm==4.66.1
# via openai
typing==3.7.4.3
# via shared
typing-extensions==4.6.3
# via
# asgiref
# openai
# opentelemetry-sdk
# pydantic
Expand Down
8 changes: 0 additions & 8 deletions services/bots.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,6 @@ def get_owner_installation_id(
if owner.integration_id and deprecated_using_integration:
return owner.integration_id
# DEPRECATED FLOW - end
log.warning(
"(owner has no ghapp installation AND no integration_id) OR not using integration",
extra=dict(
repoid=(repository.repoid if repository else "no_repo"),
ownerid=owner.ownerid,
using_integration=deprecated_using_integration,
),
)
return None


Expand Down
2 changes: 1 addition & 1 deletion services/bundle_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def _bytes_readable(self, bytes: int) -> str:
kilobytes = bytes / 1000
if kilobytes < 1000:
kilobytes = round(kilobytes, 2)
return f"{kilobytes}KB"
return f"{kilobytes}kB"

megabytes = kilobytes / 1000
if megabytes < 1000:
Expand Down
31 changes: 15 additions & 16 deletions services/notification/notifiers/mixins/message/sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,19 @@ async def do_write_section(self, comparison, diff, changes, links, behind_by=Non
yaml = self.current_yaml
base_report = comparison.project_coverage_base.report
head_report = comparison.head.report
pull = comparison.pull
pull_dict = comparison.enriched_pull.provider_pull
repo_service = comparison.repository_service.service

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
if misses_and_partials:
yield (
f"Attention: `{misses_and_partials} lines` in your changes are missing coverage. Please review."
f"Attention: Patch coverage is `{patch_coverage}%` with `{misses_and_partials} lines` in your changes are missing coverage. Please review."
)
else:
yield "All modified and coverable lines are covered by tests :white_check_mark:"
Expand All @@ -130,13 +130,10 @@ async def do_write_section(self, comparison, diff, changes, links, behind_by=Non

if base_report and head_report:
yield (
"> Comparison is base [(`{commitid_base}`)]({links[base]}?el=desc) {base_cov}% compared to head [(`{commitid_head}`)]({links[pull]}?src=pr&el=desc) {head_cov}%.".format(
pull=pull.pullid,
base=pull_dict["base"]["branch"],
"> Project coverage is {head_cov}%. Comparing base [(`{commitid_base}`)]({links[base]}?el=desc) to head [(`{commitid_head}`)]({links[pull]}?src=pr&el=desc).".format(
commitid_head=comparison.head.commit.commitid[:7],
commitid_base=comparison.project_coverage_base.commit.commitid[:7],
links=links,
base_cov=round_number(yaml, Decimal(base_report.totals.coverage)),
head_cov=round_number(yaml, Decimal(head_report.totals.coverage)),
)
)
Expand All @@ -148,9 +145,9 @@ async def do_write_section(self, comparison, diff, changes, links, behind_by=Non
commit=pull_dict["base" if not base_report else "head"]["commitid"][
:7
],
request_type="merge request"
if repo_service == "gitlab"
else "pull request",
request_type=(
"merge request" if repo_service == "gitlab" else "pull request"
),
)
)

Expand Down Expand Up @@ -634,9 +631,9 @@ async def do_write_section(self, comparison, diff, changes, links, behind_by=Non
"name": name,
"before": get_totals_from_file_in_reports(base_flags, name),
"after": flag.totals,
"diff": flag.apply_diff(diff)
if walk(diff, ("files",))
else None,
"diff": (
flag.apply_diff(diff) if walk(diff, ("files",)) else None
),
"carriedforward": flag.carriedforward,
"carriedforward_from": flag.carriedforward_from,
}
Expand Down Expand Up @@ -754,9 +751,11 @@ async def _get_table_data_for_components(
component_data.append(
{
"name": component.get_display_name(),
"before": filtered_comparison.project_coverage_base.report.totals
if filtered_comparison.project_coverage_base.report is not None
else None,
"before": (
filtered_comparison.project_coverage_base.report.totals
if filtered_comparison.project_coverage_base.report is not None
else None
),
"after": filtered_comparison.head.report.totals,
"diff": filtered_comparison.head.report.apply_diff(
diff, _save=False
Expand Down
10 changes: 4 additions & 6 deletions services/notification/notifiers/mixins/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ async def get_changes_status(self, comparison) -> Tuple[str, str]:
lpc = len(changes)
eng = "files have" if lpc > 1 else "file has"
description = (
"{0} {1} unexpected coverage changes not visible in diff".format(
lpc, eng
)
"{0} {1} indirect coverage changes not visible in diff".format(lpc, eng)
)
state = (
"success"
Expand All @@ -98,12 +96,12 @@ async def get_changes_status(self, comparison) -> Tuple[str, str]:
)
return (state, description)

description = "No unexpected coverage changes found"
description = "No indirect coverage changes found"
return ("success", description)


class StatusProjectMixin(object):
DEFAULT_REMOVED_CODE_BEHAVIOR = "fully_covered_patch"
DEFAULT_REMOVED_CODE_BEHAVIOR = "adjust_base"

async def _apply_removals_only_behavior(
self, comparison: Union[ComparisonProxy, FilteredComparison]
Expand Down Expand Up @@ -260,7 +258,7 @@ async def _apply_fully_covered_patch_behavior(
if coverage == 100.0:
return (
"success",
", passed because patch was fully covered by tests with no unexpected coverage changes",
", passed because patch was fully covered by tests, and no indirect coverage changes",
)
return None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ async def test_notify(self, sample_comparison, codecov_vcr, mock_configuration):
message = [
"## [Codecov](https://app.codecov.io/gh/joseph-sentry/codecov-demo/pull/9?src=pr&el=h1) Report",
"All modified and coverable lines are covered by tests :white_check_mark:",
"> Comparison is base [(`5b174c2`)](https://app.codecov.io/gh/joseph-sentry/codecov-demo/commit/5b174c2b40d501a70c479e91025d5109b1ad5c1b?el=desc) 50.00% compared to head [(`5601846`)](https://app.codecov.io/gh/joseph-sentry/codecov-demo/pull/9?src=pr&el=desc) 60.00%.",
"> Project coverage is 60.00%. Comparing base [(`5b174c2`)](https://app.codecov.io/gh/joseph-sentry/codecov-demo/commit/5b174c2b40d501a70c479e91025d5109b1ad5c1b?el=desc) to head [(`5601846`)](https://app.codecov.io/gh/joseph-sentry/codecov-demo/pull/9?src=pr&el=desc).",
"> Report is 2 commits behind head on main.",
"",
":exclamation: Your organization needs to install the [Codecov GitHub app](https://github.com/apps/codecov/installations/select_target) to enable full functionality.",
Expand Down Expand Up @@ -502,7 +502,7 @@ async def test_notify_gitlab(
message = [
"## [Codecov](https://app.codecov.io/gl/joseph-sentry/example-python/pull/1?src=pr&el=h1) Report",
"All modified and coverable lines are covered by tests :white_check_mark:",
"> Comparison is base [(`0fc784a`)](https://app.codecov.io/gl/joseph-sentry/example-python/commit/0fc784af11c401449e56b24a174bae7b9af86c98?el=desc) 50.00% compared to head [(`0b6a213`)](https://app.codecov.io/gl/joseph-sentry/example-python/pull/1?src=pr&el=desc) 60.00%.",
"> Project coverage is 60.00%. Comparing base [(`0fc784a`)](https://app.codecov.io/gl/joseph-sentry/example-python/commit/0fc784af11c401449e56b24a174bae7b9af86c98?el=desc) to head [(`0b6a213`)](https://app.codecov.io/gl/joseph-sentry/example-python/pull/1?src=pr&el=desc).",
"",
"[![Impacted file tree graph](https://app.codecov.io/gl/joseph-sentry/example-python/pull/1/graphs/tree.svg?width=650&height=150&src=pr&token=abcdefghij)](https://app.codecov.io/gl/joseph-sentry/example-python/pull/1?src=pr&el=tree)",
"",
Expand Down Expand Up @@ -568,7 +568,7 @@ async def test_notify_new_layout(
message = [
"## [Codecov](https://app.codecov.io/gh/joseph-sentry/codecov-demo/pull/9?src=pr&el=h1) Report",
"All modified and coverable lines are covered by tests :white_check_mark:",
"> Comparison is base [(`5b174c2`)](https://app.codecov.io/gh/joseph-sentry/codecov-demo/commit/5b174c2b40d501a70c479e91025d5109b1ad5c1b?el=desc) 50.00% compared to head [(`5601846`)](https://app.codecov.io/gh/joseph-sentry/codecov-demo/pull/9?src=pr&el=desc) 60.00%.",
"> Project coverage is 60.00%. Comparing base [(`5b174c2`)](https://app.codecov.io/gh/joseph-sentry/codecov-demo/commit/5b174c2b40d501a70c479e91025d5109b1ad5c1b?el=desc) to head [(`5601846`)](https://app.codecov.io/gh/joseph-sentry/codecov-demo/pull/9?src=pr&el=desc).",
"> Report is 2 commits behind head on main.",
"",
":exclamation: Your organization needs to install the [Codecov GitHub app](https://github.com/apps/codecov/installations/select_target) to enable full functionality.",
Expand Down Expand Up @@ -644,7 +644,7 @@ async def test_notify_with_components(
message = [
"## [Codecov](https://app.codecov.io/gh/joseph-sentry/codecov-demo/pull/9?src=pr&el=h1) Report",
"All modified and coverable lines are covered by tests :white_check_mark:",
"> Comparison is base [(`5b174c2`)](https://app.codecov.io/gh/joseph-sentry/codecov-demo/commit/5b174c2b40d501a70c479e91025d5109b1ad5c1b?el=desc) 50.00% compared to head [(`5601846`)](https://app.codecov.io/gh/joseph-sentry/codecov-demo/pull/9?src=pr&el=desc) 60.00%.",
"> Project coverage is 60.00%. Comparing base [(`5b174c2`)](https://app.codecov.io/gh/joseph-sentry/codecov-demo/commit/5b174c2b40d501a70c479e91025d5109b1ad5c1b?el=desc) to head [(`5601846`)](https://app.codecov.io/gh/joseph-sentry/codecov-demo/pull/9?src=pr&el=desc).",
"> Report is 2 commits behind head on main.",
"",
":exclamation: Your organization needs to install the [Codecov GitHub app](https://github.com/apps/codecov/installations/select_target) to enable full functionality.",
Expand Down
Loading

0 comments on commit 0eea563

Please sign in to comment.