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: TA/BA Comment Messaging #1118

Merged
merged 7 commits into from
Mar 5, 2025
Merged
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
27 changes: 26 additions & 1 deletion services/notification/notifiers/mixins/message/__init__.py
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ def create_message(
Parameters:
yaml_settings: YAML settings for notifier

Note: Github Checks Notifers are initialized with "status" YAML settings.
Note: Github Checks Notifiers are initialized with "status" YAML settings.
Thus, the comment block of the codecov YAML is passed as the "yaml_settings" parameter for these Notifiers.

"""
@@ -186,6 +186,8 @@ def create_message(
section_writer,
)

self.write_cross_pollination_message(write=write)

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

def _possibly_write_install_app(
@@ -303,3 +305,26 @@ def get_lower_section_name(self, settings):
"layout", ""
) or "condensed_footer" in settings.get("layout", ""):
return "newfooter"

def write_cross_pollination_message(self, write: Callable):
extra_message = []

ta_message = "- ❄ [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems."
ba_message = "- 📦 [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges."

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

if not self.repository.bundle_analysis_enabled and set(
{"javascript", "typescript"}
).intersection(self.repository.languages or {}):
extra_message.append(ba_message)

if extra_message:
for i in [
"<details><summary>🚀 New features to boost your workflow: </summary>",
"",
*extra_message,
"</details>",
]:
write(i)
57 changes: 57 additions & 0 deletions services/notification/notifiers/tests/unit/test_comment.py
Original file line number Diff line number Diff line change
@@ -3055,6 +3055,63 @@ def test_filesection_no_extra_settings(self, sample_comparison, mocker):
"... and [3 files with indirect coverage changes](pull.link/indirect-changes?src=pr&el=tree-more)",
]

@pytest.mark.parametrize(
"test_analytics_enabled,bundle_analysis_enabled",
[(False, False), (False, True), (True, False), (True, True)],
)
@pytest.mark.django_db
def test_build_cross_pollination_message(
self,
dbsession,
mock_configuration,
mock_repo_provider,
sample_comparison,
test_analytics_enabled,
bundle_analysis_enabled,
):
mock_all_plans_and_tiers()
mock_configuration.params["setup"]["codecov_dashboard_url"] = "test.example.br"
comparison = sample_comparison
comparison.pull.is_first_coverage_pull = False
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_service=mock_repo_provider,
)
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)

header = "<details><summary>🚀 New features to boost your workflow: </summary>"
ta_message = "- ❄ [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems."
ba_message = "- 📦 [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges."

end_of_message = []

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

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

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

if len(end_of_message):
assert result[-1] == "</details>"
else:
assert result[-1] == ""

def test_get_tree_cell(self):
typ = "added"
path = "path/to/test_file.go"
Loading
Oops, something went wrong.