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 1 commit
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 @@ -147,6 +147,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 @@ -75,6 +75,7 @@ class Meta:
languages = []
languages_last_updated = factory.LazyAttribute(lambda o: datetime.now())
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 @@ -177,6 +177,28 @@ def create_message(self, comparison: ComparisonProxy, pull_dict, yaml_settings):
section_writer,
)

extra_message = []

if not self.repository.test_analytics_enabled:
extra_message.append(
"- [Flaky Tests Detection](https://docs.codecov.com/docs/test-result-ingestion-beta) - Identify and resolve unreliable tests more easily."
)
if not self.repository.bundle_analysis_enabled and set(
{"javascript", "typescript"}
).intersection(self.repository.languages or {}):
extra_message.append(
"- [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis) - Gain insights into your bundle size and performance."
)

if extra_message:
for i in [
"----",
"🚀 Exciting News! Check out our new features. Give them a try today!",
"",
*extra_message,
]:
write(i)

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

def _possibly_write_install_app(
Expand Down
59 changes: 59 additions & 0 deletions services/notification/notifiers/tests/unit/test_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2986,6 +2986,65 @@ def test_message_hide_details_bitbucket(
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)

promotional_message = (
"🚀 Exciting News! Check out our new features. Give them a try today!"
)
flake_message = "- [Flaky Tests Detection](https://docs.codecov.com/docs/test-result-ingestion-beta) - Identify and resolve unreliable tests more easily."
bundle_message = "- [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis) - Gain insights into your bundle size and performance."

end_of_message = []

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

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

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

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

print(result)
assert 0 == 1


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