Skip to content

Commit 207da17

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 2185d42 commit 207da17

9 files changed

Lines changed: 53 additions & 39 deletions

File tree

api/features/feature_external_resources/models.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,7 @@ def _handle_gitlab_after_save(self, state: str) -> None:
170170
self.feature.save()
171171

172172
feature_states: list[FeatureState] = []
173-
environments = Environment.objects.filter(
174-
project_id=self.feature.project_id
175-
)
173+
environments = Environment.objects.filter(project_id=self.feature.project_id)
176174
for environment in environments:
177175
q = Q(
178176
feature_id=self.feature_id,

api/features/feature_external_resources/views.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,14 @@ def list(self, request, *args, **kwargs) -> Response: # type: ignore[no-untyped
6868
)
6969
elif resource_type.startswith("GITLAB_"):
7070
try:
71+
import re as _re
72+
7173
from integrations.gitlab.client import (
7274
get_gitlab_issue_mr_title_and_state as get_gitlab_metadata,
7375
)
7476
from integrations.gitlab.models import (
7577
GitLabConfiguration,
7678
)
77-
import re as _re
7879

7980
feature_obj = get_object_or_404(
8081
Feature.objects.filter(id=self.kwargs["feature_pk"]),
@@ -85,10 +86,16 @@ def list(self, request, *args, **kwargs) -> Response: # type: ignore[no-untyped
8586
if gitlab_config and gitlab_config.gitlab_project_id:
8687
# Parse resource IID from URL
8788
if resource_type == "GITLAB_MR":
88-
match = _re.search(r"https?://[^/]+/([^/-]+(?:/[^/-]+)*)/-/merge_requests/(\d+)$", resource_url)
89+
match = _re.search(
90+
r"https?://[^/]+/([^/-]+(?:/[^/-]+)*)/-/merge_requests/(\d+)$",
91+
resource_url,
92+
)
8993
api_type = "merge_requests"
9094
else:
91-
match = _re.search(r"https?://[^/]+/([^/-]+(?:/[^/-]+)*)/-/(?:issues|work_items)/(\d+)$", resource_url)
95+
match = _re.search(
96+
r"https?://[^/]+/([^/-]+(?:/[^/-]+)*)/-/(?:issues|work_items)/(\d+)$",
97+
resource_url,
98+
)
9299
api_type = "issues"
93100

94101
if match:
@@ -141,7 +148,9 @@ def create(self, request, *args, **kwargs): # type: ignore[no-untyped-def]
141148
url_match = re.search(pattern, url)
142149
if url_match:
143150
_project_path, resource_iid = url_match.groups()
144-
api_resource_type = "merge_requests" if resource_type == "GITLAB_MR" else "issues"
151+
api_resource_type = (
152+
"merge_requests" if resource_type == "GITLAB_MR" else "issues"
153+
)
145154
if gitlab_config.tagging_enabled and gitlab_config.gitlab_project_id:
146155
label_gitlab_issue_mr(
147156
instance_url=gitlab_config.gitlab_instance_url,

api/integrations/gitlab/gitlab.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@
4747

4848

4949
def tag_feature_per_gitlab_event(
50-
event_type: str, action: str, metadata: dict[str, Any], project_path: str,
50+
event_type: str,
51+
action: str,
52+
metadata: dict[str, Any],
53+
project_path: str,
5154
) -> None:
5255
web_url = metadata.get("web_url", "")
5356

@@ -90,7 +93,9 @@ def tag_feature_per_gitlab_event(
9093
else:
9194
# Generic update — no tag change needed
9295
return None
93-
elif event_type in tag_by_event_type and action in tag_by_event_type[event_type]:
96+
elif (
97+
event_type in tag_by_event_type and action in tag_by_event_type[event_type]
98+
):
9499
tag_value = tag_by_event_type[event_type][action]
95100

96101
if tag_value is None:
@@ -259,9 +264,7 @@ def call_gitlab_task(
259264
url: str | None,
260265
feature_states: typing.Union[list[typing.Any], list[typing.Any]] | None,
261266
) -> None:
262-
gitlab_configuration = GitLabConfiguration.objects.get(
263-
project_id=project_id
264-
)
267+
gitlab_configuration = GitLabConfiguration.objects.get(project_id=project_id)
265268

266269
feature_data: GitLabData = generate_data(
267270
gitlab_configuration=gitlab_configuration,

api/integrations/gitlab/helpers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
def gitlab_webhook_payload_is_valid(
2-
secret_token: str, gitlab_token_header: str | None,
2+
secret_token: str,
3+
gitlab_token_header: str | None,
34
) -> bool:
45
"""Verify that the webhook was sent from GitLab by comparing the secret token."""
56
if not gitlab_token_header:

api/integrations/gitlab/models.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ class GitLabConfiguration(LifecycleModelMixin, SoftDeleteExportableModel): # ty
5454

5555
@staticmethod
5656
def has_gitlab_configuration(project_id: int) -> bool:
57-
return GitLabConfiguration.objects.filter(
58-
project_id=project_id
59-
).exists()
57+
return GitLabConfiguration.objects.filter(project_id=project_id).exists()
6058

6159
class Meta:
6260
constraints = [

api/integrations/gitlab/views.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@
5151
def gitlab_auth_required(func): # type: ignore[no-untyped-def]
5252
@wraps(func)
5353
def wrapper(request, project_pk): # type: ignore[no-untyped-def]
54-
if not GitLabConfiguration.has_gitlab_configuration(
55-
project_id=project_pk
56-
):
54+
if not GitLabConfiguration.has_gitlab_configuration(project_id=project_pk):
5755
return Response(
5856
data={
5957
"detail": "This Project doesn't have a valid GitLab Configuration"
@@ -110,7 +108,9 @@ def get_serializer_class(self): # type: ignore[no-untyped-def]
110108
def perform_create(self, serializer): # type: ignore[no-untyped-def]
111109
project_id = self.kwargs["project_pk"]
112110
serializer.save(project_id=project_id)
113-
if serializer.validated_data.get("tagging_enabled", False) and serializer.validated_data.get("gitlab_project_id"):
111+
if serializer.validated_data.get(
112+
"tagging_enabled", False
113+
) and serializer.validated_data.get("gitlab_project_id"):
114114
create_flagsmith_flag_label(
115115
instance_url=serializer.validated_data["gitlab_instance_url"],
116116
access_token=serializer.validated_data["access_token"],
@@ -121,9 +121,7 @@ def get_queryset(self): # type: ignore[no-untyped-def]
121121
if getattr(self, "swagger_fake_view", False):
122122
return GitLabConfiguration.objects.none()
123123

124-
return GitLabConfiguration.objects.filter(
125-
project_id=self.kwargs["project_pk"]
126-
)
124+
return GitLabConfiguration.objects.filter(project_id=self.kwargs["project_pk"])
127125

128126
def create(self, request, *args, **kwargs): # type: ignore[no-untyped-def]
129127
try:
@@ -165,7 +163,9 @@ def fetch_merge_requests(request, project_pk) -> Response: # type: ignore[no-un
165163
access_token=gitlab_config.access_token,
166164
params=query_serializer.validated_data,
167165
)
168-
return Response(data=data, content_type="application/json", status=status.HTTP_200_OK)
166+
return Response(
167+
data=data, content_type="application/json", status=status.HTTP_200_OK
168+
)
169169

170170

171171
@api_view(["GET"])
@@ -186,7 +186,9 @@ def fetch_issues(request, project_pk) -> Response: # type: ignore[no-untyped-de
186186
access_token=gitlab_config.access_token,
187187
params=query_serializer.validated_data,
188188
)
189-
return Response(data=data, content_type="application/json", status=status.HTTP_200_OK)
189+
return Response(
190+
data=data, content_type="application/json", status=status.HTTP_200_OK
191+
)
190192

191193

192194
@api_view(["GET"])
@@ -205,7 +207,9 @@ def fetch_projects(request, project_pk: int) -> Response | None: # type: ignore
205207
access_token=gitlab_config.access_token,
206208
params=query_serializer.validated_data,
207209
)
208-
return Response(data=data, content_type="application/json", status=status.HTTP_200_OK)
210+
return Response(
211+
data=data, content_type="application/json", status=status.HTTP_200_OK
212+
)
209213

210214

211215
@api_view(["GET"])
@@ -225,7 +229,9 @@ def fetch_project_members(request, project_pk) -> Response: # type: ignore[no-u
225229
access_token=gitlab_config.access_token,
226230
params=query_serializer.validated_data,
227231
)
228-
return Response(data=response, content_type="application/json", status=status.HTTP_200_OK)
232+
return Response(
233+
data=response, content_type="application/json", status=status.HTTP_200_OK
234+
)
229235

230236

231237
@api_view(["POST"])
@@ -279,7 +285,9 @@ def create_cleanup_issue(request, project_pk: int) -> Response: # type: ignore[
279285
url_parts = summary.repository_url.rstrip("/").split("/")
280286
repo_path = "/".join(url_parts[-2:]) # e.g. "group/project"
281287

282-
if not gitlab_config.project_name or not gitlab_config.project_name.endswith(repo_path):
288+
if not gitlab_config.project_name or not gitlab_config.project_name.endswith(
289+
repo_path
290+
):
283291
continue
284292

285293
if not gitlab_config.gitlab_project_id:

api/projects/urls.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@
2121
from integrations.datadog.views import DataDogConfigurationViewSet
2222
from integrations.gitlab.views import (
2323
GitLabConfigurationViewSet,
24-
create_cleanup_issue as gitlab_create_cleanup_issue,
25-
fetch_issues as gitlab_fetch_issues,
2624
fetch_merge_requests,
2725
fetch_project_members,
2826
fetch_projects,
2927
)
28+
from integrations.gitlab.views import (
29+
create_cleanup_issue as gitlab_create_cleanup_issue,
30+
)
31+
from integrations.gitlab.views import (
32+
fetch_issues as gitlab_fetch_issues,
33+
)
3034
from integrations.grafana.views import GrafanaProjectConfigurationViewSet
3135
from integrations.launch_darkly.views import LaunchDarklyImportRequestViewSet
3236
from integrations.new_relic.views import NewRelicConfigurationViewSet

api/tests/unit/integrations/gitlab/test_unit_gitlab_client.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22

33
from integrations.gitlab.client import (
44
build_request_headers,
5-
create_flagsmith_flag_label,
65
create_gitlab_issue,
76
fetch_gitlab_projects,
87
fetch_search_gitlab_resource,
98
get_gitlab_issue_mr_title_and_state,
10-
label_gitlab_issue_mr,
119
post_comment_to_gitlab,
1210
)
1311
from integrations.gitlab.dataclasses import IssueQueryParams, PaginatedQueryParams
1412

15-
1613
INSTANCE_URL = "https://gitlab.example.com"
1714
ACCESS_TOKEN = "test-access-token"
1815

api/tests/unit/integrations/gitlab/test_unit_gitlab_views.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ def test_create_gitlab_configuration__valid_data__returns_201(
7070
response = admin_client_new.post(url, data)
7171
# Then
7272
assert response.status_code == status.HTTP_201_CREATED
73-
assert GitLabConfiguration.objects.filter(
74-
project=project
75-
).exists()
73+
assert GitLabConfiguration.objects.filter(project=project).exists()
7674

7775

7876
def test_create_gitlab_configuration__duplicate__returns_400(
@@ -114,9 +112,7 @@ def test_delete_gitlab_configuration__valid_configuration__returns_204(
114112
response = admin_client_new.delete(url)
115113
# Then
116114
assert response.status_code == status.HTTP_204_NO_CONTENT
117-
assert not GitLabConfiguration.objects.filter(
118-
id=gitlab_configuration.id
119-
).exists()
115+
assert not GitLabConfiguration.objects.filter(id=gitlab_configuration.id).exists()
120116

121117

122118
def test_delete_gitlab_configuration__removes_external_resources(

0 commit comments

Comments
 (0)