5
5
import typing
6
6
import uuid
7
7
from copy import deepcopy
8
- from dataclasses import asdict
9
8
10
9
from core .models import (
11
10
AbstractBaseExportableModel ,
23
22
from django .utils import timezone
24
23
from django_lifecycle import (
25
24
AFTER_CREATE ,
25
+ AFTER_DELETE ,
26
26
AFTER_SAVE ,
27
27
BEFORE_CREATE ,
28
28
BEFORE_SAVE ,
74
74
STRING ,
75
75
)
76
76
from features .versioning .models import EnvironmentFeatureVersion
77
- from integrations .github .models import GithubConfiguration
78
77
from metadata .models import Metadata
79
78
from projects .models import Project
80
79
from projects .tags .models import Tag
@@ -139,10 +138,7 @@ class Meta:
139
138
140
139
@hook (AFTER_SAVE )
141
140
def create_github_comment (self ) -> None :
142
- from integrations .github .github import GithubData , generate_data
143
- from integrations .github .tasks import (
144
- call_github_app_webhook_for_feature_state ,
145
- )
141
+ from integrations .github .github import call_github_task
146
142
from webhooks .webhooks import WebhookEventType
147
143
148
144
if (
@@ -151,19 +147,14 @@ def create_github_comment(self) -> None:
151
147
and self .project .organisation .github_config .exists ()
152
148
and self .deleted_at
153
149
):
154
- github_configuration = GithubConfiguration .objects .get (
155
- organisation_id = self .project .organisation_id
156
- )
157
150
158
- feature_data : GithubData = generate_data (
159
- github_configuration = github_configuration ,
160
- feature = self ,
151
+ call_github_task (
152
+ organisation_id = self .project .organisation_id ,
161
153
type = WebhookEventType .FLAG_DELETED .value ,
162
- feature_states = [],
163
- )
164
-
165
- call_github_app_webhook_for_feature_state .delay (
166
- args = (asdict (feature_data ),),
154
+ feature = self ,
155
+ segment_name = None ,
156
+ url = None ,
157
+ feature_states = None ,
167
158
)
168
159
169
160
@hook (AFTER_CREATE )
@@ -219,6 +210,7 @@ def get_next_segment_priority(feature):
219
210
220
211
221
212
class FeatureSegment (
213
+ LifecycleModelMixin ,
222
214
AbstractBaseExportableModel ,
223
215
OrderedModelBase ,
224
216
abstract_base_auditable_model_factory (["uuid" ]),
@@ -406,6 +398,26 @@ def get_delete_log_message(self, history_instance) -> typing.Optional[str]:
406
398
def _get_environment (self ) -> "Environment" :
407
399
return self .environment
408
400
401
+ @hook (AFTER_DELETE )
402
+ def create_github_comment (self ) -> None :
403
+ from integrations .github .github import call_github_task
404
+ from webhooks .webhooks import WebhookEventType
405
+
406
+ if (
407
+ self .feature .external_resources .exists ()
408
+ and self .feature .project .github_project .exists ()
409
+ and self .feature .project .organisation .github_config .exists ()
410
+ ):
411
+
412
+ call_github_task (
413
+ self .feature .project .organisation_id ,
414
+ WebhookEventType .SEGMENT_OVERRIDE_DELETED .value ,
415
+ self .feature ,
416
+ self .segment .name ,
417
+ None ,
418
+ None ,
419
+ )
420
+
409
421
410
422
class FeatureState (
411
423
SoftDeleteExportableModel ,
0 commit comments