Skip to content
Merged
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
2 changes: 1 addition & 1 deletion api/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ def api_client() -> APIClient:


@pytest.fixture()
def feature(project: Project, environment: Environment) -> Feature:
def feature(project: Project) -> Feature:
return Feature.objects.create(name="Test Feature1", project=project) # type: ignore[no-any-return]


Expand Down
2 changes: 1 addition & 1 deletion api/integrations/github/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class GithubData:
feature_id: int
feature_name: str
type: str
feature_states: list[dict[str, Any]] | None = None
feature_states: list[dict[str, Any]] = field(default_factory=list)
url: str | None = None
project_id: int | None = None
segment_name: str | None = None
Expand Down
7 changes: 4 additions & 3 deletions api/integrations/github/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ def handle_github_webhook_event(event_type: str, payload: dict[str, Any]) -> Non
def generate_body_comment(
name: str,
event_type: str,
project_id: int,
feature_id: int,
feature_states: list[dict[str, typing.Any]],
project_id: int | None = None,
segment_name: str | None = None,
) -> str:
is_removed = event_type == GitHubEventType.FEATURE_EXTERNAL_RESOURCE_REMOVED.value
Expand Down Expand Up @@ -197,8 +197,9 @@ def generate_data(
url: str | None = None,
segment_name: str | None = None,
) -> GithubData:
feature_states_list = []

if feature_states:
feature_states_list = []
for feature_state in feature_states:
feature_state_value = feature_state.get_feature_state_value()
feature_env_data = {}
Expand Down Expand Up @@ -234,7 +235,7 @@ def generate_data(
if type == GitHubEventType.FEATURE_EXTERNAL_RESOURCE_REMOVED.value
else None
),
feature_states=feature_states_list if feature_states else None,
feature_states=feature_states_list,
project_id=feature.project_id,
segment_name=segment_name,
)
Expand Down
18 changes: 8 additions & 10 deletions api/integrations/github/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,16 @@ def send_post_request(data: CallGithubData) -> None:
feature_id = data.github_data.feature_id
project_id = data.github_data.project_id
event_type = data.event_type
feature_states = (
data.github_data.feature_states if data.github_data.feature_states else None
)
feature_states = data.github_data.feature_states or []
installation_id = data.github_data.installation_id
segment_name: str | None = data.github_data.segment_name
segment_name = data.github_data.segment_name
body = generate_body_comment(
feature_name,
event_type,
project_id, # type: ignore[arg-type]
feature_id,
feature_states, # type: ignore[arg-type]
segment_name,
name=feature_name,
event_type=event_type,
project_id=project_id,
feature_id=feature_id,
feature_states=feature_states,
segment_name=segment_name,
Comment thread
khvn26 marked this conversation as resolved.
)

if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,21 @@
if typing.TYPE_CHECKING:
from django.db.models import Model

from features.workflows.core.models import ChangeRequest


def test_on_environment_create_makes_feature_states(
organisation: Organisation,
feature: Feature,
project: Project,
) -> None:
# Given
assert feature.feature_states.count() == 1
assert not feature.feature_states.exists()

# When
Environment.objects.create(name="New Environment", project=project)

# Then
# A new environment comes with a new feature state.
feature.feature_states.count() == 2
Comment thread
khvn26 marked this conversation as resolved.
assert feature.feature_states.count() == 1


def test_on_environment_update_feature_states(
Expand Down
1 change: 1 addition & 0 deletions api/tests/unit/features/test_unit_features_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ def test_feature_state_gt_operator_throws_value_error_if_different_environments(
def test_feature_state_gt_operator_throws_value_error_if_different_features(
project: Project,
feature: Feature,
environment: Environment,
) -> None:
# Given
another_feature = Feature.objects.create(name="Another feature", project=project)
Expand Down
Loading