dex-connector-gitlab 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,190 @@
1
+ # Copyright (c) 2026 Super Durable
2
+ # SPDX-License-Identifier: MIT
3
+ # ruff: noqa
4
+
5
+ from collections.abc import Callable, Mapping
6
+ from typing import Any, TypeVar
7
+
8
+ import dex
9
+ from dex_connectors.sdk import (
10
+ MutationResult,
11
+ MutationStep,
12
+ MutationStepConfig,
13
+ QueryResult,
14
+ QueryStep,
15
+ QueryStepConfig,
16
+ StepAnnotations,
17
+ )
18
+
19
+ from ..connection import Connection
20
+ from ..models import GetProjectInput, Issue, IssuesPage, ListIssuesInput, Project, UpdateIssueLabelsInput
21
+
22
+ StepInput = TypeVar("StepInput")
23
+
24
+ def new_get_project_step(
25
+ *,
26
+ step_type: str,
27
+ step_input_type: type[StepInput],
28
+ annotations: StepAnnotations | Mapping[str, str],
29
+ connection: Connection,
30
+ connection_name: str,
31
+ map_to_operation_input: Callable[[StepInput], GetProjectInput],
32
+ found: dex.StepTarget[QueryResult[Project]],
33
+ not_found: dex.StepTarget[QueryResult[Project]] | None = None,
34
+ provider_rejected: dex.StepTarget[QueryResult[Project]] | None = None,
35
+ invalid_response: dex.StepTarget[QueryResult[Project]] | None = None,
36
+ defect: dex.StepTarget[QueryResult[Project]] | None = None,
37
+ result_attribute: dex.Attribute[QueryResult[Project]] | None = None,
38
+ step_options_override: dex.StepOptions | None = None,
39
+ ) -> QueryStep[StepInput, GetProjectInput, Project]:
40
+ if connection is None or connection.reference.name != connection_name:
41
+ raise ValueError("GitLab Step connection name must match its connection reference")
42
+ if isinstance(annotations, StepAnnotations):
43
+ step_annotations = annotations
44
+ else:
45
+ if not isinstance(annotations, Mapping) or set(annotations) != {"groupId", "groupLabel", "explanation"}:
46
+ raise ValueError("GitLab Step annotations require groupId, groupLabel, and explanation")
47
+ if any(not isinstance(value, str) for value in annotations.values()):
48
+ raise ValueError("GitLab Step annotations must be strings")
49
+ step_annotations = StepAnnotations(annotations["groupId"], annotations["groupLabel"], annotations["explanation"])
50
+ branches = {
51
+ "found": found,
52
+ }
53
+ if not_found is not None:
54
+ branches["notFound"] = not_found
55
+ if provider_rejected is not None:
56
+ branches["providerRejected"] = provider_rejected
57
+ if invalid_response is not None:
58
+ branches["invalidResponse"] = invalid_response
59
+ if defect is not None:
60
+ branches["defect"] = defect
61
+ return QueryStep(
62
+ QueryStepConfig(
63
+ step_type=step_type,
64
+ step_input_type=step_input_type,
65
+ annotations=step_annotations,
66
+ operation=_bound_operation(connection, "get_project"),
67
+ connection=connection.reference,
68
+ map_to_operation_input=map_to_operation_input,
69
+ branches=branches,
70
+ result_attribute=result_attribute,
71
+ step_options_override=step_options_override,
72
+ )
73
+ )
74
+
75
+ setattr(new_get_project_step, '__module__', 'dex_connectors.gitlab.steps')
76
+
77
+ def new_list_issues_step(
78
+ *,
79
+ step_type: str,
80
+ step_input_type: type[StepInput],
81
+ annotations: StepAnnotations | Mapping[str, str],
82
+ connection: Connection,
83
+ connection_name: str,
84
+ map_to_operation_input: Callable[[StepInput], ListIssuesInput],
85
+ listed: dex.StepTarget[QueryResult[IssuesPage]],
86
+ not_found: dex.StepTarget[QueryResult[IssuesPage]] | None = None,
87
+ provider_rejected: dex.StepTarget[QueryResult[IssuesPage]] | None = None,
88
+ invalid_response: dex.StepTarget[QueryResult[IssuesPage]] | None = None,
89
+ defect: dex.StepTarget[QueryResult[IssuesPage]] | None = None,
90
+ result_attribute: dex.Attribute[QueryResult[IssuesPage]] | None = None,
91
+ step_options_override: dex.StepOptions | None = None,
92
+ ) -> QueryStep[StepInput, ListIssuesInput, IssuesPage]:
93
+ if connection is None or connection.reference.name != connection_name:
94
+ raise ValueError("GitLab Step connection name must match its connection reference")
95
+ if isinstance(annotations, StepAnnotations):
96
+ step_annotations = annotations
97
+ else:
98
+ if not isinstance(annotations, Mapping) or set(annotations) != {"groupId", "groupLabel", "explanation"}:
99
+ raise ValueError("GitLab Step annotations require groupId, groupLabel, and explanation")
100
+ if any(not isinstance(value, str) for value in annotations.values()):
101
+ raise ValueError("GitLab Step annotations must be strings")
102
+ step_annotations = StepAnnotations(annotations["groupId"], annotations["groupLabel"], annotations["explanation"])
103
+ branches = {
104
+ "listed": listed,
105
+ }
106
+ if not_found is not None:
107
+ branches["notFound"] = not_found
108
+ if provider_rejected is not None:
109
+ branches["providerRejected"] = provider_rejected
110
+ if invalid_response is not None:
111
+ branches["invalidResponse"] = invalid_response
112
+ if defect is not None:
113
+ branches["defect"] = defect
114
+ return QueryStep(
115
+ QueryStepConfig(
116
+ step_type=step_type,
117
+ step_input_type=step_input_type,
118
+ annotations=step_annotations,
119
+ operation=_bound_operation(connection, "list_issues"),
120
+ connection=connection.reference,
121
+ map_to_operation_input=map_to_operation_input,
122
+ branches=branches,
123
+ result_attribute=result_attribute,
124
+ step_options_override=step_options_override,
125
+ )
126
+ )
127
+
128
+ setattr(new_list_issues_step, '__module__', 'dex_connectors.gitlab.steps')
129
+
130
+ def new_update_issue_labels_step(
131
+ *,
132
+ step_type: str,
133
+ step_input_type: type[StepInput],
134
+ annotations: StepAnnotations | Mapping[str, str],
135
+ connection: Connection,
136
+ connection_name: str,
137
+ map_to_operation_input: Callable[[StepInput], UpdateIssueLabelsInput],
138
+ updated: dex.StepTarget[MutationResult[Issue]],
139
+ not_found: dex.StepTarget[MutationResult[Issue]] | None = None,
140
+ provider_rejected: dex.StepTarget[MutationResult[Issue]] | None = None,
141
+ invalid_response: dex.StepTarget[MutationResult[Issue]] | None = None,
142
+ defect: dex.StepTarget[MutationResult[Issue]] | None = None,
143
+ result_attribute: dex.Attribute[MutationResult[Issue]] | None = None,
144
+ step_options_override: dex.StepOptions | None = None,
145
+ ) -> MutationStep[StepInput, UpdateIssueLabelsInput, Issue]:
146
+ if connection is None or connection.reference.name != connection_name:
147
+ raise ValueError("GitLab Step connection name must match its connection reference")
148
+ if isinstance(annotations, StepAnnotations):
149
+ step_annotations = annotations
150
+ else:
151
+ if not isinstance(annotations, Mapping) or set(annotations) != {"groupId", "groupLabel", "explanation"}:
152
+ raise ValueError("GitLab Step annotations require groupId, groupLabel, and explanation")
153
+ if any(not isinstance(value, str) for value in annotations.values()):
154
+ raise ValueError("GitLab Step annotations must be strings")
155
+ step_annotations = StepAnnotations(annotations["groupId"], annotations["groupLabel"], annotations["explanation"])
156
+ branches = {
157
+ "updated": updated,
158
+ }
159
+ if not_found is not None:
160
+ branches["notFound"] = not_found
161
+ if provider_rejected is not None:
162
+ branches["providerRejected"] = provider_rejected
163
+ if invalid_response is not None:
164
+ branches["invalidResponse"] = invalid_response
165
+ if defect is not None:
166
+ branches["defect"] = defect
167
+ return MutationStep(
168
+ MutationStepConfig(
169
+ step_type=step_type,
170
+ step_input_type=step_input_type,
171
+ annotations=step_annotations,
172
+ operation=_bound_operation(connection, "update_issue_labels"),
173
+ connection=connection.reference,
174
+ map_to_operation_input=map_to_operation_input,
175
+ branches=branches,
176
+ result_attribute=result_attribute,
177
+ step_options_override=step_options_override,
178
+ )
179
+ )
180
+
181
+ setattr(new_update_issue_labels_step, '__module__', 'dex_connectors.gitlab.steps')
182
+
183
+
184
+ def _bound_operation(connection: Connection, operation_name: str) -> Any:
185
+ source = getattr(connection, operation_name, None)
186
+ if source is None:
187
+ source = getattr(getattr(connection, "operations", None), operation_name, None)
188
+ if source is None:
189
+ raise ValueError(f"connection operation {operation_name} is missing")
190
+ return source() if callable(source) else source
@@ -0,0 +1,428 @@
1
+ # Copyright (c) 2026 Super Durable
2
+ # SPDX-License-Identifier: MIT
3
+ """GitLab project, issue, and label operations with Go-compatible branch classification."""
4
+
5
+ import json
6
+ from collections.abc import Callable
7
+ from dataclasses import dataclass
8
+ from datetime import UTC, datetime
9
+ from datetime import timedelta as timedelta
10
+ from typing import Any, TypeVar
11
+ from urllib.parse import quote, urlencode
12
+
13
+ import httpx
14
+ from dex_connectors.sdk import BranchDefinition as BranchDefinition
15
+ from dex_connectors.sdk import (
16
+ Call,
17
+ CallID,
18
+ CredentialProvider,
19
+ Failure,
20
+ FailureKind,
21
+ IdempotencyKey,
22
+ MutationAttempt,
23
+ MutationDefinition,
24
+ QueryAttempt,
25
+ QueryDefinition,
26
+ ReauthorizationRequiredError,
27
+ Receipt,
28
+ )
29
+ from dex_connectors.sdk import OperationRef as OperationRef
30
+ from dex_connectors.sdk import SecretString as SecretString
31
+ from dex_connectors.sdk import StepDefaults as StepDefaults
32
+ from dex_connectors.sdk.providerhttp import (
33
+ BodyTooLargeError,
34
+ ProviderTransportError,
35
+ is_header_safe_credential,
36
+ new_provider_http_client,
37
+ parse_retry_after,
38
+ read_bounded_body,
39
+ send_traced,
40
+ validate_base_url,
41
+ )
42
+ from dex_connectors.sdk.retry_policy import (
43
+ default_connector_step_execute_retry_policy as default_connector_step_execute_retry_policy,
44
+ )
45
+
46
+ from ._generated.config import (
47
+ Config as Config,
48
+ )
49
+ from ._generated.config import (
50
+ Credentials as Credentials,
51
+ )
52
+ from ._generated.definitions import (
53
+ CONNECTOR_ID as CONNECTOR_ID,
54
+ )
55
+ from ._generated.definitions import (
56
+ DEFECT as DEFECT,
57
+ )
58
+ from ._generated.definitions import (
59
+ FOUND as FOUND,
60
+ )
61
+ from ._generated.definitions import (
62
+ GET_PROJECT_DEFINITION as GET_PROJECT_DEFINITION,
63
+ )
64
+ from ._generated.definitions import (
65
+ GET_PROJECT_OPERATION_ID as GET_PROJECT_OPERATION_ID,
66
+ )
67
+ from ._generated.definitions import (
68
+ INVALID_RESPONSE as INVALID_RESPONSE,
69
+ )
70
+ from ._generated.definitions import (
71
+ LIST_ISSUES_DEFINITION as LIST_ISSUES_DEFINITION,
72
+ )
73
+ from ._generated.definitions import (
74
+ LIST_ISSUES_OPERATION_ID as LIST_ISSUES_OPERATION_ID,
75
+ )
76
+ from ._generated.definitions import (
77
+ LISTED as LISTED,
78
+ )
79
+ from ._generated.definitions import (
80
+ NOT_FOUND as NOT_FOUND,
81
+ )
82
+ from ._generated.definitions import (
83
+ PROVIDER_REJECTED as PROVIDER_REJECTED,
84
+ )
85
+ from ._generated.definitions import (
86
+ UPDATE_ISSUE_LABELS_DEFINITION as UPDATE_ISSUE_LABELS_DEFINITION,
87
+ )
88
+ from ._generated.definitions import (
89
+ UPDATE_ISSUE_LABELS_OPERATION_ID as UPDATE_ISSUE_LABELS_OPERATION_ID,
90
+ )
91
+ from ._generated.definitions import (
92
+ UPDATED as UPDATED,
93
+ )
94
+ from .models import GetProjectInput, Issue, IssuesPage, ListIssuesInput, Project, UpdateIssueLabelsInput
95
+
96
+ _DEFAULT_BASE_URL = "https://gitlab.com/api/v4"
97
+ _DEFAULT_TIMEOUT_SECONDS = 15
98
+ _DEFAULT_MAX_RESPONSE_BYTES = 2_097_152
99
+ _PATH_SEGMENT_SAFE = "$&+:=@"
100
+ _STATUS_KINDS = {
101
+ 401: FailureKind.AUTHENTICATION,
102
+ 403: FailureKind.AUTHORIZATION,
103
+ 404: FailureKind.NOT_FOUND,
104
+ 400: FailureKind.VALIDATION,
105
+ 422: FailureKind.VALIDATION,
106
+ }
107
+
108
+ Output = TypeVar("Output")
109
+
110
+
111
+ @dataclass(frozen=True, slots=True)
112
+ class _Outcome:
113
+ """A terminal or retry attempt whose empty value the calling operation supplies."""
114
+
115
+ branch: str
116
+ failure: Failure
117
+ is_retry: bool = False
118
+ retry_after_seconds: float = 0
119
+
120
+ def as_query(self, empty: Output) -> QueryAttempt[Output]:
121
+ if self.is_retry:
122
+ return QueryAttempt.retry(self.failure, self.retry_after_seconds)
123
+ return QueryAttempt.branch_result(self.branch, empty, Receipt(), self.failure)
124
+
125
+ def as_mutation(self, empty: Output) -> MutationAttempt[Output]:
126
+ if self.is_retry:
127
+ return MutationAttempt.retry(self.failure, self.retry_after_seconds)
128
+ return MutationAttempt.branch_result(self.branch, empty, Receipt(), self.failure)
129
+
130
+
131
+ @dataclass(frozen=True, slots=True)
132
+ class _Success:
133
+ """A decoded happy-branch value."""
134
+
135
+ value: Any
136
+
137
+
138
+ class Client:
139
+ """One redirect-safe HTTP client and call-time credential source."""
140
+
141
+ def __init__(
142
+ self,
143
+ config: Config,
144
+ credentials: CredentialProvider[Credentials],
145
+ http_client: httpx.AsyncClient | None = None,
146
+ ) -> None:
147
+ if config is None:
148
+ raise ValueError("GitLab configuration is required")
149
+ if credentials is None:
150
+ raise ValueError("GitLab credential source is required")
151
+ if config.timeout_seconds < 0 or config.max_response_bytes < 0:
152
+ raise ValueError("GitLab timeout and maxResponseBytes must be positive")
153
+ self.base_url = validate_base_url(config.base_url or _DEFAULT_BASE_URL)
154
+ self.max_response_bytes = config.max_response_bytes or _DEFAULT_MAX_RESPONSE_BYTES
155
+ self.credentials = credentials
156
+ self.http_client = http_client or new_provider_http_client(
157
+ config.timeout_seconds or _DEFAULT_TIMEOUT_SECONDS
158
+ )
159
+
160
+ def get_project(self) -> "GetProjectOperation":
161
+ """Bind the getProject Query to this client."""
162
+ return GetProjectOperation(self)
163
+
164
+ def list_issues(self) -> "ListIssuesOperation":
165
+ """Bind the listIssues Query to this client."""
166
+ return ListIssuesOperation(self)
167
+
168
+ def update_issue_labels(self) -> "UpdateIssueLabelsOperation":
169
+ """Bind the updateIssueLabels Mutation to this client."""
170
+ return UpdateIssueLabelsOperation(self)
171
+
172
+ async def aclose(self) -> None:
173
+ """Close the owned provider HTTP client after application shutdown."""
174
+ await self.http_client.aclose()
175
+
176
+ async def execute(
177
+ self,
178
+ call: Call,
179
+ operation: str,
180
+ method: str,
181
+ path: str,
182
+ body: bytes | None,
183
+ has_not_found: bool,
184
+ decode: Callable[[Any], Any],
185
+ ) -> _Success | _Outcome:
186
+ """Send one request and classify it exactly like the Go executeQuery and executeMutation helpers."""
187
+ try:
188
+ credentials = await self.credentials.resolve(call)
189
+ except (ValueError, LookupError, OSError, ReauthorizationRequiredError):
190
+ return _outcome(
191
+ DEFECT, operation, FailureKind.AUTHENTICATION, "connection credentials are unavailable"
192
+ )
193
+ token = credentials.access_token.reveal()
194
+ if not token or not is_header_safe_credential(token):
195
+ return _outcome(
196
+ DEFECT, operation, FailureKind.AUTHENTICATION, "connection credentials are invalid"
197
+ )
198
+ headers = {"PRIVATE-TOKEN": token, "Accept": "application/json"}
199
+ if body is not None:
200
+ headers["Content-Type"] = "application/x-www-form-urlencoded"
201
+ try:
202
+ request = self.http_client.build_request(
203
+ method, self.base_url + path, content=body, headers=headers
204
+ )
205
+ except (httpx.HTTPError, ValueError):
206
+ return _outcome(DEFECT, operation, FailureKind.LOCAL_DEFECT, "request could not be built")
207
+ try:
208
+ response, _ = await send_traced(self.http_client, request)
209
+ except ProviderTransportError:
210
+ return _outcome("", operation, FailureKind.AVAILABILITY, "GitLab request failed", is_retry=True)
211
+ try:
212
+ status = response.status_code
213
+ if status in (408, 409, 429) or status >= 500:
214
+ kind = FailureKind.RATE_LIMIT if status == 429 else FailureKind.AVAILABILITY
215
+ retry_after = parse_retry_after(response.headers.get("Retry-After", ""), datetime.now(UTC))
216
+ return _outcome("", operation, kind, f"GitLab returned HTTP {status}", True, retry_after)
217
+ if status != 200:
218
+ branch = NOT_FOUND if status == 404 and has_not_found else PROVIDER_REJECTED
219
+ kind = _STATUS_KINDS.get(status, FailureKind.PROVIDER_REJECTION)
220
+ return _outcome(branch, operation, kind, f"GitLab returned HTTP {status}")
221
+ try:
222
+ response_body = await read_bounded_body(response, self.max_response_bytes)
223
+ except BodyTooLargeError:
224
+ return _outcome(
225
+ INVALID_RESPONSE,
226
+ operation,
227
+ FailureKind.RESPONSE_TOO_LARGE,
228
+ "response exceeded the configured limit",
229
+ )
230
+ except ProviderTransportError:
231
+ return _outcome(
232
+ "", operation, FailureKind.AVAILABILITY, "response was interrupted", is_retry=True
233
+ )
234
+ try:
235
+ return _Success(decode(json.loads(response_body)))
236
+ except (ValueError, TypeError, UnicodeDecodeError):
237
+ return _outcome(INVALID_RESPONSE, operation, FailureKind.PROTOCOL, "response was malformed")
238
+ finally:
239
+ await response.aclose()
240
+
241
+
242
+ class GetProjectOperation:
243
+ """Read one GitLab project by numeric ID or namespace path."""
244
+
245
+ def __init__(self, client: Client) -> None:
246
+ if client is None:
247
+ raise ValueError("GitLab client is required")
248
+ self.client = client
249
+
250
+ def definition(self) -> QueryDefinition:
251
+ """Return manifest identity, branches, and retry defaults."""
252
+ return GET_PROJECT_DEFINITION
253
+
254
+ async def invoke(self, call: Call, input: GetProjectInput) -> QueryAttempt[Project]:
255
+ """Validate the project, read once, then select a branch or safe retry."""
256
+ operation = GET_PROJECT_OPERATION_ID
257
+ if not isinstance(input, GetProjectInput) or not _is_nonblank(input.project_id):
258
+ return _query_failed(operation, Project(), "projectId is required")
259
+ result = await self.client.execute(
260
+ call, operation, "GET", _project_path(input.project_id), None, True, _decode_project
261
+ )
262
+ if isinstance(result, _Outcome):
263
+ return result.as_query(Project())
264
+ return QueryAttempt.branch_result(FOUND, result.value, Receipt())
265
+
266
+
267
+ class ListIssuesOperation:
268
+ """List the first page of issues for a GitLab project."""
269
+
270
+ def __init__(self, client: Client) -> None:
271
+ if client is None:
272
+ raise ValueError("GitLab client is required")
273
+ self.client = client
274
+
275
+ def definition(self) -> QueryDefinition:
276
+ """Return manifest identity, branches, and retry defaults."""
277
+ return LIST_ISSUES_DEFINITION
278
+
279
+ async def invoke(self, call: Call, input: ListIssuesInput) -> QueryAttempt[IssuesPage]:
280
+ """Validate the project, list once, then select a branch or safe retry."""
281
+ operation = LIST_ISSUES_OPERATION_ID
282
+ if not isinstance(input, ListIssuesInput) or not _is_nonblank(input.project_id):
283
+ return _query_failed(operation, IssuesPage(), "projectId is required")
284
+ result = await self.client.execute(
285
+ call, operation, "GET", _project_path(input.project_id) + "/issues", None, True, _decode_issues
286
+ )
287
+ if isinstance(result, _Outcome):
288
+ return result.as_query(IssuesPage())
289
+ return QueryAttempt.branch_result(LISTED, result.value, Receipt())
290
+
291
+
292
+ class UpdateIssueLabelsOperation:
293
+ """Replace one issue's complete label set; repeating the request is safe."""
294
+
295
+ def __init__(self, client: Client) -> None:
296
+ if client is None:
297
+ raise ValueError("GitLab client is required")
298
+ self.client = client
299
+
300
+ def definition(self) -> MutationDefinition:
301
+ """Return manifest identity, branches, and retry defaults."""
302
+ return UPDATE_ISSUE_LABELS_DEFINITION
303
+
304
+ def idempotency_key(self, call_id: CallID, input: UpdateIssueLabelsInput) -> IdempotencyKey:
305
+ """Use the stable call ID; this operation sets an absolute state."""
306
+ return IdempotencyKey(str(call_id))
307
+
308
+ async def invoke(self, call: Call, input: UpdateIssueLabelsInput) -> MutationAttempt[Issue]:
309
+ """Validate, replace the labels once, then select a branch or safe retry."""
310
+ operation = UPDATE_ISSUE_LABELS_OPERATION_ID
311
+ message = _label_update_validation_message(input)
312
+ if message:
313
+ return MutationAttempt.branch_result(
314
+ DEFECT, Issue(), Receipt(), Failure(FailureKind.VALIDATION, CONNECTOR_ID, operation, message)
315
+ )
316
+ body = urlencode({"labels": ",".join(input.labels)}).encode()
317
+ path = f"{_project_path(input.project_id)}/issues/{input.issue_iid}"
318
+ result = await self.client.execute(call, operation, "PUT", path, body, True, _decode_updated_issue)
319
+ if isinstance(result, _Outcome):
320
+ return result.as_mutation(Issue())
321
+ return MutationAttempt.branch_result(UPDATED, result.value, Receipt())
322
+
323
+
324
+ def _label_update_validation_message(input: UpdateIssueLabelsInput) -> str:
325
+ if (
326
+ not isinstance(input, UpdateIssueLabelsInput)
327
+ or not _is_nonblank(input.project_id)
328
+ or type(input.issue_iid) is not int
329
+ or input.issue_iid <= 0
330
+ ):
331
+ return "projectId and positive issueIid are required"
332
+ if any(not _is_nonblank(label) or "," in label for label in input.labels):
333
+ return "labels must be nonblank and cannot contain commas"
334
+ return ""
335
+
336
+
337
+ def _project_path(project_id: str) -> str:
338
+ return "/projects/" + quote(project_id, safe=_PATH_SEGMENT_SAFE)
339
+
340
+
341
+ def _is_nonblank(value: object) -> bool:
342
+ return isinstance(value, str) and bool(value.strip())
343
+
344
+
345
+ def _decode_project(document: Any) -> Project:
346
+ document = _object(document)
347
+ project_id = _optional(document, "id", 0)
348
+ fields = tuple(_optional(document, name, "") for name in ("name", "path_with_namespace", "web_url"))
349
+ if type(project_id) is not int or project_id <= 0 or not all(isinstance(value, str) for value in fields):
350
+ raise ValueError
351
+ return Project(project_id, *fields)
352
+
353
+
354
+ def _decode_issues(document: Any) -> IssuesPage:
355
+ if not isinstance(document, list):
356
+ raise ValueError
357
+ return IssuesPage(tuple(_decode_issue(issue) for issue in document))
358
+
359
+
360
+ def _decode_updated_issue(document: Any) -> Issue:
361
+ issue = _decode_issue(document)
362
+ if issue.id <= 0 or issue.iid <= 0:
363
+ raise ValueError
364
+ return issue
365
+
366
+
367
+ def _decode_issue(document: Any) -> Issue:
368
+ document = _object(document)
369
+ issue_id = _optional(document, "id", 0)
370
+ issue_iid = _optional(document, "iid", 0)
371
+ title = _optional(document, "title", "")
372
+ labels = _optional(document, "labels", [])
373
+ web_url = _optional(document, "web_url", "")
374
+ if (
375
+ type(issue_id) is not int
376
+ or type(issue_iid) is not int
377
+ or not isinstance(title, str)
378
+ or not isinstance(web_url, str)
379
+ or not isinstance(labels, list)
380
+ ):
381
+ raise ValueError
382
+ return Issue(issue_id, issue_iid, title, tuple(_label(label) for label in labels), web_url)
383
+
384
+
385
+ def _label(value: Any) -> str:
386
+ if value is None:
387
+ return ""
388
+ if not isinstance(value, str):
389
+ raise ValueError
390
+ return value
391
+
392
+
393
+ def _object(value: Any) -> dict[str, Any]:
394
+ """Return a JSON object, treating null like Go's zero struct."""
395
+ if value is None:
396
+ return {}
397
+ if not isinstance(value, dict):
398
+ raise ValueError
399
+ return value
400
+
401
+
402
+ def _optional(document: dict[str, Any], name: str, default: Any) -> Any:
403
+ """Return a JSON field, treating absent or null like Go's zero value."""
404
+ value = document.get(name)
405
+ return default if value is None else value
406
+
407
+
408
+ def _query_failed(operation: str, value: Output, message: str) -> QueryAttempt[Output]:
409
+ return QueryAttempt.branch_result(
410
+ DEFECT, value, Receipt(), Failure(FailureKind.VALIDATION, CONNECTOR_ID, operation, message)
411
+ )
412
+
413
+
414
+ def _outcome(
415
+ branch: str,
416
+ operation: str,
417
+ kind: FailureKind,
418
+ message: str,
419
+ is_retry: bool = False,
420
+ retry_after_seconds: float = 0,
421
+ ) -> _Outcome:
422
+ return _Outcome(branch, Failure(kind, CONNECTOR_ID, operation, message), is_retry, retry_after_seconds)
423
+
424
+
425
+ Config.__doc__ = "GitLab HTTP settings; zero or blank values use manifest defaults."
426
+ Credentials.__doc__ = (
427
+ "GitLab personal, project, or group access token, resolved anew for every provider attempt."
428
+ )
@@ -0,0 +1,50 @@
1
+ # Copyright (c) 2026 Super Durable
2
+ # SPDX-License-Identifier: MIT
3
+ """GitLab connection and project credential binding."""
4
+
5
+ from typing import Any as Any
6
+
7
+ import httpx as httpx
8
+ from dex_connectors.sdk import Call as Call
9
+ from dex_connectors.sdk import ConnectionRef as ConnectionRef
10
+ from dex_connectors.sdk import Mutation as Mutation
11
+ from dex_connectors.sdk import Query as Query
12
+ from dex_connectors.sdk import SecretString as SecretString
13
+ from dex_connectors.sdk.projectconfig import ConnectionKey as ConnectionKey
14
+ from dex_connectors.sdk.projectconfig import LoadedProject as LoadedProject
15
+
16
+ from ._generated.connection import (
17
+ Connection as Connection,
18
+ )
19
+ from ._generated.connection import (
20
+ new_connection as new_connection,
21
+ )
22
+ from ._generated.connection import (
23
+ new_connection_with_operations as new_connection_with_operations,
24
+ )
25
+ from ._generated.connection import (
26
+ new_project_connection as new_project_connection,
27
+ )
28
+ from .client import CONNECTOR_ID as CONNECTOR_ID
29
+ from .client import GET_PROJECT_DEFINITION as GET_PROJECT_DEFINITION
30
+ from .client import LIST_ISSUES_DEFINITION as LIST_ISSUES_DEFINITION
31
+ from .client import UPDATE_ISSUE_LABELS_DEFINITION as UPDATE_ISSUE_LABELS_DEFINITION
32
+ from .client import Client as Client
33
+ from .client import Config as Config
34
+ from .client import Credentials as Credentials
35
+ from .models import GetProjectInput as GetProjectInput
36
+ from .models import Issue as Issue
37
+ from .models import IssuesPage as IssuesPage
38
+ from .models import ListIssuesInput as ListIssuesInput
39
+ from .models import Project as Project
40
+ from .models import UpdateIssueLabelsInput as UpdateIssueLabelsInput
41
+
42
+ Connection.__doc__ = "Nonserializable GitLab operation bindings for a named project connection."
43
+
44
+ new_connection.__doc__ = "Bind a client to an explicit logical connection reference."
45
+ new_connection_with_operations.__doc__ = (
46
+ "Bind mock operations to the same connection identity as the real provider."
47
+ )
48
+ new_project_connection.__doc__ = (
49
+ "Open declared ordinary settings and resolve the current access token per call."
50
+ )