Skip to content

Commit

Permalink
rip out more of labels
Browse files Browse the repository at this point in the history
  • Loading branch information
Swatinem committed Oct 14, 2024
1 parent c7b8873 commit a862064
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 2,928 deletions.
73 changes: 0 additions & 73 deletions helpers/labels.py

This file was deleted.

42 changes: 5 additions & 37 deletions services/report/raw_upload_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from database.models.reports import Upload
from helpers.exceptions import ReportEmptyError, ReportExpiredException
from helpers.labels import get_all_report_labels, get_labels_per_session
from services.path_fixer import PathFixer
from services.report.parser.types import ParsedRawReport
from services.report.report_builder import ReportBuilder
Expand Down Expand Up @@ -124,7 +123,7 @@ def process_raw_upload(
# Adjust sessions removed carryforward sessions that are being replaced
if session.flags:
session_adjustment = clear_carryforward_sessions(
report, temporary_report, session.flags, commit_yaml, upload
report, session.flags, commit_yaml
)
else:
session_adjustment = SessionAdjustmentResult([], [])
Expand All @@ -138,52 +137,21 @@ def process_raw_upload(
@sentry_sdk.trace
def clear_carryforward_sessions(
original_report: Report,
to_merge_report: Report,
to_merge_flags: list[str],
current_yaml: UserYaml,
upload: Upload | None = None,
) -> SessionAdjustmentResult:
flags_under_carryforward_rules = {
to_fully_overwrite_flags = {
f for f in to_merge_flags if current_yaml.flag_has_carryfoward(f)
}
to_partially_overwrite_flags = {
f
for f in flags_under_carryforward_rules
if current_yaml.get_flag_configuration(f).get("carryforward_mode") == "labels"
}
to_fully_overwrite_flags = flags_under_carryforward_rules.difference(
to_partially_overwrite_flags
)

if upload is None and to_partially_overwrite_flags:
log.warning("Upload is None, but there are partial_overwrite_flags present")

session_ids_to_fully_delete = []
session_ids_to_partially_delete = []

if to_fully_overwrite_flags or to_partially_overwrite_flags:
if to_fully_overwrite_flags:
for session_id, session in original_report.sessions.items():
if session.session_type == SessionType.carriedforward and session.flags:
if any(f in to_fully_overwrite_flags for f in session.flags):
session_ids_to_fully_delete.append(session_id)
if any(f in to_partially_overwrite_flags for f in session.flags):
session_ids_to_partially_delete.append(session_id)

actually_fully_deleted_sessions = set()
if session_ids_to_fully_delete:
original_report.delete_multiple_sessions(session_ids_to_fully_delete)
actually_fully_deleted_sessions.update(session_ids_to_fully_delete)

if session_ids_to_partially_delete:
all_labels = get_all_report_labels(to_merge_report)
original_report.delete_labels(session_ids_to_partially_delete, all_labels)
for s in session_ids_to_partially_delete:
labels_now = get_labels_per_session(original_report, s)
if not labels_now:
actually_fully_deleted_sessions.add(s)
original_report.delete_session(s)

return SessionAdjustmentResult(
sorted(actually_fully_deleted_sessions),
sorted(set(session_ids_to_partially_delete) - actually_fully_deleted_sessions),
)

return SessionAdjustmentResult(sorted(session_ids_to_fully_delete), [])
39 changes: 0 additions & 39 deletions services/report/report_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,42 +107,3 @@ def __init__(

def create_report_builder_session(self, filepath) -> ReportBuilderSession:
return ReportBuilderSession(self, filepath)

def supports_labels(self) -> bool:
"""Returns wether a report supports labels.
This is true if the client has configured some flag with carryforward_mode == "labels"
"""
if self.current_yaml is None or self.current_yaml == {}:
return False
old_flag_style = self.current_yaml.get("flags")
flag_management = self.current_yaml.get("flag_management")
# Check if some of the old style flags uses labels
old_flag_with_carryforward_labels = False
if old_flag_style:
old_flag_with_carryforward_labels = any(
map(
lambda flag_definition: flag_definition.get("carryforward_mode")
== "labels",
old_flag_style.values(),
)
)
# Check if some of the flags or default rules use labels
flag_management_default_rule_carryforward_labels = False
flag_management_flag_with_carryforward_labels = False
if flag_management:
flag_management_default_rule_carryforward_labels = (
flag_management.get("default_rules", {}).get("carryforward_mode")
== "labels"
)
flag_management_flag_with_carryforward_labels = any(
map(
lambda flag_definition: flag_definition.get("carryforward_mode")
== "labels",
flag_management.get("individual_flags", []),
)
)
return (
old_flag_with_carryforward_labels
or flag_management_default_rule_carryforward_labels
or flag_management_flag_with_carryforward_labels
)
60 changes: 0 additions & 60 deletions services/report/tests/unit/test_report_builder.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pytest
from shared.reports.resources import LineSession, ReportFile, ReportLine

from services.report.report_builder import CoverageType, ReportBuilder
Expand Down Expand Up @@ -178,62 +177,3 @@ def test_report_builder_session_create_line_mixed_labels(mocker):
)
],
)


@pytest.mark.parametrize(
"current_yaml,expected_result",
[
({}, False),
({"flags": {"oldflag": {"carryforward": "true"}}}, False),
(
{
"flags": {
"oldflag": {"carryforward": "true", "carryforward_mode": "labels"}
}
},
True,
),
(
{
"flag_management": {
"default_rules": {
"carryforward": "true",
"carryforward_mode": "labels",
}
}
},
True,
),
(
{
"flag_management": {
"default_rules": {
"carryforward": "true",
"carryforward_mode": "all",
}
}
},
False,
),
(
{
"flag_management": {
"default_rules": {
"carryforward": "true",
"carryforward_mode": "all",
},
"individual_flags": [
{
"name": "some_flag",
"carryforward_mode": "labels",
}
],
}
},
True,
),
],
)
def test_report_builder_supports_flags(current_yaml, expected_result):
builder = ReportBuilder(current_yaml, 0, None, None)
assert builder.supports_labels() == expected_result
Loading

0 comments on commit a862064

Please sign in to comment.