-
Notifications
You must be signed in to change notification settings - Fork 521
Expand file tree
/
Copy pathmappers.py
More file actions
42 lines (31 loc) · 1.45 KB
/
mappers.py
File metadata and controls
42 lines (31 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from typing import Any
from django.utils.formats import get_format
from features.models import FeatureState
from integrations.gitlab.constants import GitLabEventType
def map_feature_states_to_dicts(
feature_states: list[FeatureState],
event_type: str,
) -> list[dict[str, Any]]:
"""Map FeatureState objects to dicts suitable for comment generation.
Used by both GitHub and GitLab integrations.
"""
result: list[dict[str, Any]] = []
for feature_state in feature_states:
feature_state_value = feature_state.get_feature_state_value()
env_data: dict[str, Any] = {}
if feature_state_value is not None:
env_data["feature_state_value"] = feature_state_value
if event_type != GitLabEventType.FEATURE_EXTERNAL_RESOURCE_REMOVED.value:
env_data["environment_name"] = feature_state.environment.name # type: ignore[union-attr]
env_data["enabled"] = feature_state.enabled
env_data["last_updated"] = feature_state.updated_at.strftime(
get_format("DATETIME_INPUT_FORMATS")[0]
)
env_data["environment_api_key"] = feature_state.environment.api_key # type: ignore[union-attr]
if (
hasattr(feature_state, "feature_segment")
and feature_state.feature_segment is not None
):
env_data["segment_name"] = feature_state.feature_segment.segment.name
result.append(env_data)
return result