Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add promotional message for new message to end of PR comment #754

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions database/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ class Repository(CodecovBaseModel):
webhook_secret = Column(types.Text)
activated = Column(types.Boolean, default=False)
bundle_analysis_enabled = Column(types.Boolean, default=False)
test_analytics_enabled = Column(types.Boolean, default=False)
upload_token = Column(postgresql.UUID, server_default=FetchedValue())

# DEPRECATED - prefer GithubAppInstallation.is_repo_covered_by_integration
Expand Down
1 change: 1 addition & 0 deletions database/tests/factories/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class Meta:
lambda o: datetime.now(tz=timezone.utc)
)
bundle_analysis_enabled = False
test_analytics_enabled = True


class BranchFactory(Factory):
Expand Down
22 changes: 22 additions & 0 deletions services/notification/notifiers/mixins/message/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,28 @@
section_writer,
)

extra_message = []

if not self.repository.test_analytics_enabled:
extra_message.append(

Check warning on line 185 in services/notification/notifiers/mixins/message/__init__.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/notification/notifiers/mixins/message/__init__.py#L185

Added line #L185 was not covered by tests
"- [Flaky Tests Detection](https://docs.codecov.com/docs/test-result-ingestion-beta) - Detect and resolve failed and flaky tests"
)
if not self.repository.bundle_analysis_enabled and set(
{"javascript", "typescript"}
).intersection(self.repository.languages or {}):
extra_message.append(

Check warning on line 191 in services/notification/notifiers/mixins/message/__init__.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/notification/notifiers/mixins/message/__init__.py#L191

Added line #L191 was not covered by tests
"- [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis) - Avoid shipping oversized bundles"
)

if extra_message:
for i in [

Check warning on line 196 in services/notification/notifiers/mixins/message/__init__.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/notification/notifiers/mixins/message/__init__.py#L196

Added line #L196 was not covered by tests
"----",
"🚨 Try these New Features:",
"",
*extra_message,
]:
write(i)

Check warning on line 202 in services/notification/notifiers/mixins/message/__init__.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/notification/notifiers/mixins/message/__init__.py#L202

Added line #L202 was not covered by tests

return [m for m in message if m is not None]

def _possibly_write_install_app(
Expand Down
54 changes: 54 additions & 0 deletions services/notification/notifiers/tests/unit/test_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -3037,6 +3037,60 @@
assert exp == res
assert result == expected_result

@pytest.mark.parametrize(
"test_analytics_enabled,bundle_analysis_enabled",
[(False, False), (False, True), (True, False), (True, True)],
)
def test_build_message_new_feature_message(
self,
dbsession,
mock_configuration,
mock_repo_provider,
sample_comparison,
test_analytics_enabled,
bundle_analysis_enabled,
):
mock_configuration.params["setup"]["codecov_dashboard_url"] = "test.example.br"
comparison = sample_comparison
pull = comparison.pull
notifier = CommentNotifier(
repository=sample_comparison.head.commit.repository,
title="title",
notifier_yaml_settings={"layout": "reach, diff, flags, files, footer"},
notifier_site_settings=True,
current_yaml={},
)
repository = sample_comparison.head.commit.repository
if bundle_analysis_enabled:
repository.languages = ["javascript"]
if test_analytics_enabled:
repository.test_analytics_enabled = False
dbsession.flush()
result = notifier.build_message(comparison)

Check warning on line 3069 in services/notification/notifiers/tests/unit/test_comment.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/notification/notifiers/tests/unit/test_comment.py#L3063-L3069

Added lines #L3063 - L3069 were not covered by tests

promotional_message = "🚨 Try these New Features:"
flake_message = "- [Flaky Tests Detection](https://docs.codecov.com/docs/test-result-ingestion-beta) - Detect and resolve failed and flaky tests"
bundle_message = "- [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis) - Avoid shipping oversized bundles"

Check warning on line 3073 in services/notification/notifiers/tests/unit/test_comment.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/notification/notifiers/tests/unit/test_comment.py#L3071-L3073

Added lines #L3071 - L3073 were not covered by tests

end_of_message = []

Check warning on line 3075 in services/notification/notifiers/tests/unit/test_comment.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/notification/notifiers/tests/unit/test_comment.py#L3075

Added line #L3075 was not covered by tests

if test_analytics_enabled or bundle_analysis_enabled:
end_of_message += [promotional_message, ""]
assert promotional_message in result

Check warning on line 3079 in services/notification/notifiers/tests/unit/test_comment.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/notification/notifiers/tests/unit/test_comment.py#L3077-L3079

Added lines #L3077 - L3079 were not covered by tests

if test_analytics_enabled:
end_of_message.append(flake_message)
assert flake_message in result

Check warning on line 3083 in services/notification/notifiers/tests/unit/test_comment.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/notification/notifiers/tests/unit/test_comment.py#L3081-L3083

Added lines #L3081 - L3083 were not covered by tests

if bundle_analysis_enabled:
end_of_message.append(bundle_message)
assert bundle_message in result

Check warning on line 3087 in services/notification/notifiers/tests/unit/test_comment.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/notification/notifiers/tests/unit/test_comment.py#L3085-L3087

Added lines #L3085 - L3087 were not covered by tests

if len(end_of_message):
assert result[-len(end_of_message) :] == end_of_message

Check warning on line 3090 in services/notification/notifiers/tests/unit/test_comment.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/notification/notifiers/tests/unit/test_comment.py#L3089-L3090

Added lines #L3089 - L3090 were not covered by tests
else:
assert result[-1] == ""

Check warning on line 3092 in services/notification/notifiers/tests/unit/test_comment.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/notification/notifiers/tests/unit/test_comment.py#L3092

Added line #L3092 was not covered by tests


class TestFileSectionWriter(object):
def test_filesection_no_extra_settings(self, sample_comparison, mocker):
Expand Down
Loading