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.
- dex_connector_gitlab-0.1.0.dist-info/METADATA +54 -0
- dex_connector_gitlab-0.1.0.dist-info/RECORD +18 -0
- dex_connector_gitlab-0.1.0.dist-info/WHEEL +4 -0
- dex_connectors/gitlab/__init__.py +59 -0
- dex_connectors/gitlab/_generated/__init__.py +2 -0
- dex_connectors/gitlab/_generated/config.py +25 -0
- dex_connectors/gitlab/_generated/connection.py +145 -0
- dex_connectors/gitlab/_generated/definitions.py +76 -0
- dex_connectors/gitlab/_generated/mock.py +164 -0
- dex_connectors/gitlab/_generated/models.py +106 -0
- dex_connectors/gitlab/_generated/steps.py +190 -0
- dex_connectors/gitlab/client.py +428 -0
- dex_connectors/gitlab/connection.py +50 -0
- dex_connectors/gitlab/dex-connector.json +125 -0
- dex_connectors/gitlab/gitlabmock/__init__.py +78 -0
- dex_connectors/gitlab/models.py +26 -0
- dex_connectors/gitlab/py.typed +0 -0
- dex_connectors/gitlab/steps.py +46 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: dex-connector-gitlab
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: GitLab connector for Dex Flows
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Requires-Python: >=3.11
|
|
7
|
+
Requires-Dist: dex-connectors-sdk==0.1.0
|
|
8
|
+
Requires-Dist: dex-python-sdk>=1.28.0
|
|
9
|
+
Requires-Dist: httpx>=0.27
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
|
|
12
|
+
# GitLab connector for Python
|
|
13
|
+
|
|
14
|
+
Install with `pip install dex-connector-gitlab==0.1.0`. The package requires
|
|
15
|
+
`dex-connectors-sdk==0.1.0` and `dex-python-sdk>=1.28.0`, and implements the
|
|
16
|
+
manifest operations `getProject` and `listIssues` (Queries) and
|
|
17
|
+
`updateIssueLabels` (Mutation) with the same branches, defaults, and failure
|
|
18
|
+
classification as the Go module.
|
|
19
|
+
|
|
20
|
+
## Operations
|
|
21
|
+
|
|
22
|
+
| Operation | Factory | Happy branch | Optional branches |
|
|
23
|
+
| --- | --- | --- | --- |
|
|
24
|
+
| `getProject` | `new_get_project_step` | `found` | `notFound`, `providerRejected`, `invalidResponse`, `defect` |
|
|
25
|
+
| `listIssues` | `new_list_issues_step` | `listed` | `notFound`, `providerRejected`, `invalidResponse`, `defect` |
|
|
26
|
+
| `updateIssueLabels` | `new_update_issue_labels_step` | `updated` | `notFound`, `providerRejected`, `invalidResponse`, `defect` |
|
|
27
|
+
|
|
28
|
+
A project is a numeric ID or a namespace path such as `meridian/web`, which is
|
|
29
|
+
path-escaped. `listIssues` reads GitLab's default first page of issues.
|
|
30
|
+
`updateIssueLabels` replaces the issue's complete label set with a form-encoded
|
|
31
|
+
`labels` value (an empty set clears every label), so a retry writes the same
|
|
32
|
+
absolute state; labels must be nonblank and cannot contain commas.
|
|
33
|
+
|
|
34
|
+
All operations retry on 408, 409, 429, 5xx, and transport failures. HTTP 404
|
|
35
|
+
selects `notFound`; other statuses select `providerRejected` with
|
|
36
|
+
authentication (401), authorization (403), or validation (400, 422) kinds.
|
|
37
|
+
|
|
38
|
+
## Authorization
|
|
39
|
+
|
|
40
|
+
Create a Dex Web connection named `gitlab` as described in the
|
|
41
|
+
[connector README](../README.md#authorization). The access token travels only
|
|
42
|
+
in the `PRIVATE-TOKEN` header and is resolved for every attempt.
|
|
43
|
+
|
|
44
|
+
## Example
|
|
45
|
+
|
|
46
|
+
[`examples/gitlab_lookup`](examples/gitlab_lookup/flow.py) reads one project.
|
|
47
|
+
Run the Worker with `uv run python -m examples.gitlab_lookup.worker` after
|
|
48
|
+
`dexcli dev` has loaded a project containing the `gitlab` connection.
|
|
49
|
+
|
|
50
|
+
## Tests
|
|
51
|
+
|
|
52
|
+
`gitlabmock.Mock` scripts every operation and defaults to the manifest
|
|
53
|
+
answers. Run `uv run pytest tests` for provider parity and manifest contract
|
|
54
|
+
checks.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
dex_connectors/gitlab/__init__.py,sha256=92uxg62TZsF0boui1fuTa1997Cjeijv_9fpWC2l8mLg,1523
|
|
2
|
+
dex_connectors/gitlab/client.py,sha256=MUa-3EyGPb0mAXczMSsyazYqXAgp8g5v4CMFiB5JWuA,16047
|
|
3
|
+
dex_connectors/gitlab/connection.py,sha256=K4uhAz4AWVLBENa2EsVr9R4YCSuKpY-pgKTFEQJu4dE,2065
|
|
4
|
+
dex_connectors/gitlab/dex-connector.json,sha256=s91V46IIku19WLOuIpyT4odozRwFNq2n4BXqEV6XlHM,2878
|
|
5
|
+
dex_connectors/gitlab/models.py,sha256=s8nQQj5qHNlycq3uBKfSK96chu9xgSJVbyPvFOfqaDY,1134
|
|
6
|
+
dex_connectors/gitlab/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
dex_connectors/gitlab/steps.py,sha256=mZtEJY1iaF3HG8gXItlDKgCXOlkXZ38L7HuQ0CwrBCo,1812
|
|
8
|
+
dex_connectors/gitlab/_generated/__init__.py,sha256=ShfMsAGzSt4xuhCaf20ibgtfXl4pXomZb00ovUw6CeI,66
|
|
9
|
+
dex_connectors/gitlab/_generated/config.py,sha256=dGpemQy2Z5mNpdpBS_WUXEq-dFo32Y6K8xSJRB4rGcA,550
|
|
10
|
+
dex_connectors/gitlab/_generated/connection.py,sha256=_PpZWumJNK5x0csDWS8exT8bXRdHjjXuhImoN9AU8jI,6448
|
|
11
|
+
dex_connectors/gitlab/_generated/definitions.py,sha256=agUSKASHwWRh4VPmrurtR3TsuMcUWnrAsFLMnDGDlVY,2934
|
|
12
|
+
dex_connectors/gitlab/_generated/mock.py,sha256=Li5yOkgYgkcbLZqJpSDWc5oX5r70y-CNNKghqx5zuK4,7646
|
|
13
|
+
dex_connectors/gitlab/_generated/models.py,sha256=EVl9i46VS_awW5HUu7kqp1hvVu_mWYqq7yzUJr5u2YI,3682
|
|
14
|
+
dex_connectors/gitlab/_generated/steps.py,sha256=_jXp4O2x9rBihHn6Pqi_YDnWPUH_HzxciAIkIhJEM9w,8389
|
|
15
|
+
dex_connectors/gitlab/gitlabmock/__init__.py,sha256=8EpCzJBRFJ2hmBCLhxYiFMnGBd6dxGePa8YaVT5Nmx8,3569
|
|
16
|
+
dex_connector_gitlab-0.1.0.dist-info/METADATA,sha256=CwR6f4Vag2TTXpRzNZyFv6SgnXP6vX423ONELo2YwpU,2342
|
|
17
|
+
dex_connector_gitlab-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
18
|
+
dex_connector_gitlab-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""GitLab project, issue, and label operations for Dex connector Steps."""
|
|
4
|
+
|
|
5
|
+
from .client import (
|
|
6
|
+
CONNECTOR_ID,
|
|
7
|
+
DEFECT,
|
|
8
|
+
FOUND,
|
|
9
|
+
GET_PROJECT_DEFINITION,
|
|
10
|
+
INVALID_RESPONSE,
|
|
11
|
+
LIST_ISSUES_DEFINITION,
|
|
12
|
+
LISTED,
|
|
13
|
+
NOT_FOUND,
|
|
14
|
+
PROVIDER_REJECTED,
|
|
15
|
+
UPDATE_ISSUE_LABELS_DEFINITION,
|
|
16
|
+
UPDATED,
|
|
17
|
+
Client,
|
|
18
|
+
Config,
|
|
19
|
+
Credentials,
|
|
20
|
+
GetProjectOperation,
|
|
21
|
+
ListIssuesOperation,
|
|
22
|
+
UpdateIssueLabelsOperation,
|
|
23
|
+
)
|
|
24
|
+
from .connection import Connection, new_connection, new_connection_with_operations, new_project_connection
|
|
25
|
+
from .models import GetProjectInput, Issue, IssuesPage, ListIssuesInput, Project, UpdateIssueLabelsInput
|
|
26
|
+
from .steps import new_get_project_step, new_list_issues_step, new_update_issue_labels_step
|
|
27
|
+
|
|
28
|
+
__all__ = [
|
|
29
|
+
"Client",
|
|
30
|
+
"Config",
|
|
31
|
+
"Connection",
|
|
32
|
+
"Credentials",
|
|
33
|
+
"GetProjectInput",
|
|
34
|
+
"GetProjectOperation",
|
|
35
|
+
"Issue",
|
|
36
|
+
"IssuesPage",
|
|
37
|
+
"ListIssuesInput",
|
|
38
|
+
"ListIssuesOperation",
|
|
39
|
+
"Project",
|
|
40
|
+
"UpdateIssueLabelsInput",
|
|
41
|
+
"UpdateIssueLabelsOperation",
|
|
42
|
+
"new_connection",
|
|
43
|
+
"new_connection_with_operations",
|
|
44
|
+
"new_get_project_step",
|
|
45
|
+
"new_list_issues_step",
|
|
46
|
+
"new_project_connection",
|
|
47
|
+
"new_update_issue_labels_step",
|
|
48
|
+
"CONNECTOR_ID",
|
|
49
|
+
"DEFECT",
|
|
50
|
+
"FOUND",
|
|
51
|
+
"GET_PROJECT_DEFINITION",
|
|
52
|
+
"INVALID_RESPONSE",
|
|
53
|
+
"LIST_ISSUES_DEFINITION",
|
|
54
|
+
"LISTED",
|
|
55
|
+
"NOT_FOUND",
|
|
56
|
+
"PROVIDER_REJECTED",
|
|
57
|
+
"UPDATE_ISSUE_LABELS_DEFINITION",
|
|
58
|
+
"UPDATED",
|
|
59
|
+
]
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
|
|
7
|
+
from dex_connectors.sdk import SecretString
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass(frozen=True, slots=True)
|
|
11
|
+
class Config:
|
|
12
|
+
|
|
13
|
+
base_url: str = "https://gitlab.com/api/v4"
|
|
14
|
+
timeout_seconds: float = 15
|
|
15
|
+
max_response_bytes: int = 2097152
|
|
16
|
+
|
|
17
|
+
setattr(Config, '__module__', 'dex_connectors.gitlab.client')
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True, slots=True)
|
|
21
|
+
class Credentials:
|
|
22
|
+
|
|
23
|
+
access_token: SecretString
|
|
24
|
+
|
|
25
|
+
setattr(Credentials, '__module__', 'dex_connectors.gitlab.client')
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
import httpx
|
|
8
|
+
from dex_connectors.sdk import ConnectionRef, Mutation, Query, Call, SecretString
|
|
9
|
+
from dex_connectors.sdk.projectconfig import ConnectionKey, LoadedProject
|
|
10
|
+
|
|
11
|
+
from ..client import Client, Config, Credentials
|
|
12
|
+
from .definitions import CONNECTOR_ID, GET_PROJECT_DEFINITION, LIST_ISSUES_DEFINITION, UPDATE_ISSUE_LABELS_DEFINITION
|
|
13
|
+
from ..models import GetProjectInput, Issue, IssuesPage, ListIssuesInput, Project, UpdateIssueLabelsInput
|
|
14
|
+
|
|
15
|
+
class Connection:
|
|
16
|
+
|
|
17
|
+
__slots__ = ('_get_project', '_list_issues', '_update_issue_labels', '_client', 'reference')
|
|
18
|
+
|
|
19
|
+
def __init__(self,
|
|
20
|
+
reference: ConnectionRef,
|
|
21
|
+
get_project: Query[GetProjectInput, Project],
|
|
22
|
+
list_issues: Query[ListIssuesInput, IssuesPage],
|
|
23
|
+
update_issue_labels: Mutation[UpdateIssueLabelsInput, Issue],
|
|
24
|
+
client: Client | None = None,
|
|
25
|
+
) -> None:
|
|
26
|
+
reference.validate()
|
|
27
|
+
if reference.provider != CONNECTOR_ID or get_project is None or list_issues is None or update_issue_labels is None:
|
|
28
|
+
raise ValueError("GitLab connection provider and operations are required")
|
|
29
|
+
if get_project.definition().operation != GET_PROJECT_DEFINITION.operation:
|
|
30
|
+
raise ValueError("GitLab connection operation identity differs")
|
|
31
|
+
if list_issues.definition().operation != LIST_ISSUES_DEFINITION.operation:
|
|
32
|
+
raise ValueError("GitLab connection operation identity differs")
|
|
33
|
+
if update_issue_labels.definition().operation != UPDATE_ISSUE_LABELS_DEFINITION.operation:
|
|
34
|
+
raise ValueError("GitLab connection operation identity differs")
|
|
35
|
+
self.reference = reference
|
|
36
|
+
self._get_project = get_project
|
|
37
|
+
self._list_issues = list_issues
|
|
38
|
+
self._update_issue_labels = update_issue_labels
|
|
39
|
+
self._client = client
|
|
40
|
+
|
|
41
|
+
def get_project(self) -> Query[GetProjectInput, Project]:
|
|
42
|
+
return self._get_project
|
|
43
|
+
|
|
44
|
+
def list_issues(self) -> Query[ListIssuesInput, IssuesPage]:
|
|
45
|
+
return self._list_issues
|
|
46
|
+
|
|
47
|
+
def update_issue_labels(self) -> Mutation[UpdateIssueLabelsInput, Issue]:
|
|
48
|
+
return self._update_issue_labels
|
|
49
|
+
|
|
50
|
+
async def aclose(self) -> None:
|
|
51
|
+
if self._client is not None:
|
|
52
|
+
await self._client.aclose()
|
|
53
|
+
|
|
54
|
+
def __repr__(self) -> str:
|
|
55
|
+
return "gitlab.Connection([REDACTED])"
|
|
56
|
+
|
|
57
|
+
def __reduce__(self) -> tuple[object, ...]:
|
|
58
|
+
raise TypeError("GitLab connections cannot be serialized")
|
|
59
|
+
|
|
60
|
+
setattr(Connection, '__module__', 'dex_connectors.gitlab.connection')
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def new_connection(client: Client, reference: ConnectionRef) -> Connection:
|
|
64
|
+
if client is None:
|
|
65
|
+
raise ValueError("GitLab client is required")
|
|
66
|
+
return Connection(reference, client.get_project(), client.list_issues(), client.update_issue_labels(), client)
|
|
67
|
+
|
|
68
|
+
setattr(new_connection, '__module__', 'dex_connectors.gitlab.connection')
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def new_connection_with_operations(
|
|
72
|
+
get_project: Query[GetProjectInput, Project],
|
|
73
|
+
list_issues: Query[ListIssuesInput, IssuesPage],
|
|
74
|
+
update_issue_labels: Mutation[UpdateIssueLabelsInput, Issue],
|
|
75
|
+
reference: ConnectionRef,
|
|
76
|
+
) -> Connection:
|
|
77
|
+
return Connection(reference, get_project, list_issues, update_issue_labels)
|
|
78
|
+
|
|
79
|
+
setattr(new_connection_with_operations, '__module__', 'dex_connectors.gitlab.connection')
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
class _ProjectCredentialSource:
|
|
83
|
+
|
|
84
|
+
def __init__(self, project: LoadedProject, key: ConnectionKey) -> None:
|
|
85
|
+
self.project = project
|
|
86
|
+
self.key = key
|
|
87
|
+
|
|
88
|
+
async def resolve(self, call: Call) -> Credentials:
|
|
89
|
+
material = await self.project.resolve_credential(self.key, str(call.id))
|
|
90
|
+
if not isinstance(material, dict):
|
|
91
|
+
raise ValueError("GitLab stored credential does not match the connector credential fields")
|
|
92
|
+
if set(material) - set(('access_token',)):
|
|
93
|
+
raise ValueError("GitLab stored credential does not match the connector credential fields")
|
|
94
|
+
access_token = material.get("access_token")
|
|
95
|
+
if access_token is not None and not (isinstance(access_token, str)):
|
|
96
|
+
raise ValueError("GitLab credential access_token has an invalid type")
|
|
97
|
+
if not access_token:
|
|
98
|
+
raise ValueError("GitLab credential access_token is required")
|
|
99
|
+
return Credentials(SecretString(access_token))
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def new_project_connection(
|
|
103
|
+
project: LoadedProject, connection_name: str, http_client: httpx.AsyncClient | None = None
|
|
104
|
+
) -> Connection:
|
|
105
|
+
if project is None:
|
|
106
|
+
raise ValueError("GitLab connection requires loaded project configuration")
|
|
107
|
+
reference = ConnectionRef(CONNECTOR_ID, connection_name)
|
|
108
|
+
reference.validate()
|
|
109
|
+
key = ConnectionKey(CONNECTOR_ID, connection_name)
|
|
110
|
+
matching = [
|
|
111
|
+
entry
|
|
112
|
+
for entry in project.configuration.connections
|
|
113
|
+
if entry.connector_id == CONNECTOR_ID and entry.connection_name == connection_name
|
|
114
|
+
]
|
|
115
|
+
if len(matching) != 1:
|
|
116
|
+
raise ValueError("GitLab project connection is missing or duplicated")
|
|
117
|
+
if matching[0].provider != CONNECTOR_ID:
|
|
118
|
+
raise ValueError("GitLab project connection provider differs")
|
|
119
|
+
config = _decode_config(matching[0].configuration)
|
|
120
|
+
client = Client(config, _ProjectCredentialSource(project, key), http_client)
|
|
121
|
+
return new_connection(client, reference)
|
|
122
|
+
|
|
123
|
+
setattr(new_project_connection, '__module__', 'dex_connectors.gitlab.connection')
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _decode_config(value: dict[str, Any]) -> Config:
|
|
127
|
+
if set(value) - {"baseUrl", "timeout", "maxResponseBytes"}:
|
|
128
|
+
raise ValueError("GitLab configuration has unknown fields")
|
|
129
|
+
config_arguments: dict[str, Any] = {}
|
|
130
|
+
if "baseUrl" in value:
|
|
131
|
+
base_url = value["baseUrl"]
|
|
132
|
+
if not (isinstance(base_url, str)):
|
|
133
|
+
raise ValueError("GitLab configuration baseUrl has an invalid type")
|
|
134
|
+
config_arguments['base_url'] = base_url
|
|
135
|
+
if "timeout" in value:
|
|
136
|
+
timeout = value["timeout"]
|
|
137
|
+
if not (type(timeout) is int):
|
|
138
|
+
raise ValueError("GitLab configuration timeout has an invalid type")
|
|
139
|
+
config_arguments['timeout_seconds'] = timeout / 1_000_000_000
|
|
140
|
+
if "maxResponseBytes" in value:
|
|
141
|
+
max_response_bytes = value["maxResponseBytes"]
|
|
142
|
+
if not (type(max_response_bytes) is int):
|
|
143
|
+
raise ValueError("GitLab configuration maxResponseBytes has an invalid type")
|
|
144
|
+
config_arguments['max_response_bytes'] = max_response_bytes
|
|
145
|
+
return Config(**config_arguments)
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from datetime import timedelta
|
|
6
|
+
|
|
7
|
+
from dex_connectors.sdk import (
|
|
8
|
+
BranchDefinition,
|
|
9
|
+
MutationDefinition,
|
|
10
|
+
OperationRef,
|
|
11
|
+
QueryDefinition,
|
|
12
|
+
RetryPolicy,
|
|
13
|
+
StepDefaults,
|
|
14
|
+
default_connector_step_execute_retry_policy,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
CONNECTOR_ID = "gitlab"
|
|
18
|
+
PROVIDER = "gitlab"
|
|
19
|
+
GET_PROJECT_OPERATION_ID = "getProject"
|
|
20
|
+
LIST_ISSUES_OPERATION_ID = "listIssues"
|
|
21
|
+
UPDATE_ISSUE_LABELS_OPERATION_ID = "updateIssueLabels"
|
|
22
|
+
DEFECT = "defect"
|
|
23
|
+
FOUND = "found"
|
|
24
|
+
INVALID_RESPONSE = "invalidResponse"
|
|
25
|
+
LISTED = "listed"
|
|
26
|
+
NOT_FOUND = "notFound"
|
|
27
|
+
PROVIDER_REJECTED = "providerRejected"
|
|
28
|
+
UPDATED = "updated"
|
|
29
|
+
|
|
30
|
+
GET_PROJECT_DEFINITION = QueryDefinition(
|
|
31
|
+
OperationRef(CONNECTOR_ID, GET_PROJECT_OPERATION_ID),
|
|
32
|
+
(
|
|
33
|
+
BranchDefinition(FOUND, "Read one GitLab project by numeric ID or namespace path.", False),
|
|
34
|
+
BranchDefinition(NOT_FOUND, "The requested resource does not exist or is inaccessible.", True),
|
|
35
|
+
BranchDefinition(PROVIDER_REJECTED, "The provider rejected the request.", True),
|
|
36
|
+
BranchDefinition(INVALID_RESPONSE, "The provider returned malformed or oversized JSON.", True),
|
|
37
|
+
BranchDefinition(DEFECT, "Local input or connection credentials are invalid.", True),
|
|
38
|
+
),
|
|
39
|
+
StepDefaults(
|
|
40
|
+
timedelta(seconds=30),
|
|
41
|
+
2,
|
|
42
|
+
execute_retry=default_connector_step_execute_retry_policy(),
|
|
43
|
+
),
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
LIST_ISSUES_DEFINITION = QueryDefinition(
|
|
47
|
+
OperationRef(CONNECTOR_ID, LIST_ISSUES_OPERATION_ID),
|
|
48
|
+
(
|
|
49
|
+
BranchDefinition(LISTED, "List the first page of issues for a GitLab project.", False),
|
|
50
|
+
BranchDefinition(NOT_FOUND, "The requested resource does not exist or is inaccessible.", True),
|
|
51
|
+
BranchDefinition(PROVIDER_REJECTED, "The provider rejected the request.", True),
|
|
52
|
+
BranchDefinition(INVALID_RESPONSE, "The provider returned malformed or oversized JSON.", True),
|
|
53
|
+
BranchDefinition(DEFECT, "Local input or connection credentials are invalid.", True),
|
|
54
|
+
),
|
|
55
|
+
StepDefaults(
|
|
56
|
+
timedelta(seconds=30),
|
|
57
|
+
2,
|
|
58
|
+
execute_retry=default_connector_step_execute_retry_policy(),
|
|
59
|
+
),
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
UPDATE_ISSUE_LABELS_DEFINITION = MutationDefinition(
|
|
63
|
+
OperationRef(CONNECTOR_ID, UPDATE_ISSUE_LABELS_OPERATION_ID),
|
|
64
|
+
(
|
|
65
|
+
BranchDefinition(UPDATED, "Replace one GitLab issue's complete label set; repeating the request is safe.", False),
|
|
66
|
+
BranchDefinition(NOT_FOUND, "The requested resource does not exist or is inaccessible.", True),
|
|
67
|
+
BranchDefinition(PROVIDER_REJECTED, "The provider rejected the request.", True),
|
|
68
|
+
BranchDefinition(INVALID_RESPONSE, "The provider returned malformed or oversized JSON.", True),
|
|
69
|
+
BranchDefinition(DEFECT, "Local input or connection credentials are invalid.", True),
|
|
70
|
+
),
|
|
71
|
+
StepDefaults(
|
|
72
|
+
timedelta(seconds=30),
|
|
73
|
+
2,
|
|
74
|
+
execute_retry=default_connector_step_execute_retry_policy(),
|
|
75
|
+
),
|
|
76
|
+
)
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
|
|
7
|
+
from dex_connectors.sdk import ConnectionRef, Failure, FailureKind
|
|
8
|
+
from dex_connectors.sdk.connectormock import Case, Mutation, Query
|
|
9
|
+
|
|
10
|
+
from ..connection import Connection, new_connection_with_operations
|
|
11
|
+
from ..models import GetProjectInput, Issue, IssuesPage, ListIssuesInput, Project, UpdateIssueLabelsInput
|
|
12
|
+
from .definitions import CONNECTOR_ID, DEFECT, FOUND, GET_PROJECT_DEFINITION, INVALID_RESPONSE, LISTED, LIST_ISSUES_DEFINITION, NOT_FOUND, PROVIDER_REJECTED, UPDATED, UPDATE_ISSUE_LABELS_DEFINITION
|
|
13
|
+
|
|
14
|
+
def get_project_found(value: Project, failure: Failure | None = None) -> Case[Project]:
|
|
15
|
+
return Case.branch_result(FOUND, value, failure)
|
|
16
|
+
|
|
17
|
+
setattr(get_project_found, '__module__', "dex_connectors.gitlab.gitlabmock")
|
|
18
|
+
|
|
19
|
+
def get_project_not_found(value: Project, failure: Failure | None = None) -> Case[Project]:
|
|
20
|
+
return Case.branch_result(NOT_FOUND, value, failure)
|
|
21
|
+
|
|
22
|
+
setattr(get_project_not_found, '__module__', "dex_connectors.gitlab.gitlabmock")
|
|
23
|
+
|
|
24
|
+
def get_project_provider_rejected(value: Project, failure: Failure | None = None) -> Case[Project]:
|
|
25
|
+
return Case.branch_result(PROVIDER_REJECTED, value, failure)
|
|
26
|
+
|
|
27
|
+
setattr(get_project_provider_rejected, '__module__', "dex_connectors.gitlab.gitlabmock")
|
|
28
|
+
|
|
29
|
+
def get_project_invalid_response(value: Project, failure: Failure | None = None) -> Case[Project]:
|
|
30
|
+
return Case.branch_result(INVALID_RESPONSE, value, failure)
|
|
31
|
+
|
|
32
|
+
setattr(get_project_invalid_response, '__module__', "dex_connectors.gitlab.gitlabmock")
|
|
33
|
+
|
|
34
|
+
def get_project_defect(value: Project, failure: Failure | None = None) -> Case[Project]:
|
|
35
|
+
return Case.branch_result(DEFECT, value, failure)
|
|
36
|
+
|
|
37
|
+
setattr(get_project_defect, '__module__', "dex_connectors.gitlab.gitlabmock")
|
|
38
|
+
|
|
39
|
+
def get_project_retry(failure: Failure, after_seconds: float = 0) -> Case[Project]:
|
|
40
|
+
return Case.retry(failure, after_seconds)
|
|
41
|
+
|
|
42
|
+
setattr(get_project_retry, '__module__', "dex_connectors.gitlab.gitlabmock")
|
|
43
|
+
|
|
44
|
+
def get_project_found_default() -> Case[Project]:
|
|
45
|
+
return Case.branch_result(FOUND, Project(id=42, name='Meridian Web', path_with_namespace='meridian/web', web_url='https://gitlab.com/meridian/web'))
|
|
46
|
+
|
|
47
|
+
setattr(get_project_found_default, '__module__', "dex_connectors.gitlab.gitlabmock")
|
|
48
|
+
|
|
49
|
+
def list_issues_listed(value: IssuesPage, failure: Failure | None = None) -> Case[IssuesPage]:
|
|
50
|
+
return Case.branch_result(LISTED, value, failure)
|
|
51
|
+
|
|
52
|
+
setattr(list_issues_listed, '__module__', "dex_connectors.gitlab.gitlabmock")
|
|
53
|
+
|
|
54
|
+
def list_issues_not_found(value: IssuesPage, failure: Failure | None = None) -> Case[IssuesPage]:
|
|
55
|
+
return Case.branch_result(NOT_FOUND, value, failure)
|
|
56
|
+
|
|
57
|
+
setattr(list_issues_not_found, '__module__', "dex_connectors.gitlab.gitlabmock")
|
|
58
|
+
|
|
59
|
+
def list_issues_provider_rejected(value: IssuesPage, failure: Failure | None = None) -> Case[IssuesPage]:
|
|
60
|
+
return Case.branch_result(PROVIDER_REJECTED, value, failure)
|
|
61
|
+
|
|
62
|
+
setattr(list_issues_provider_rejected, '__module__', "dex_connectors.gitlab.gitlabmock")
|
|
63
|
+
|
|
64
|
+
def list_issues_invalid_response(value: IssuesPage, failure: Failure | None = None) -> Case[IssuesPage]:
|
|
65
|
+
return Case.branch_result(INVALID_RESPONSE, value, failure)
|
|
66
|
+
|
|
67
|
+
setattr(list_issues_invalid_response, '__module__', "dex_connectors.gitlab.gitlabmock")
|
|
68
|
+
|
|
69
|
+
def list_issues_defect(value: IssuesPage, failure: Failure | None = None) -> Case[IssuesPage]:
|
|
70
|
+
return Case.branch_result(DEFECT, value, failure)
|
|
71
|
+
|
|
72
|
+
setattr(list_issues_defect, '__module__', "dex_connectors.gitlab.gitlabmock")
|
|
73
|
+
|
|
74
|
+
def list_issues_retry(failure: Failure, after_seconds: float = 0) -> Case[IssuesPage]:
|
|
75
|
+
return Case.retry(failure, after_seconds)
|
|
76
|
+
|
|
77
|
+
setattr(list_issues_retry, '__module__', "dex_connectors.gitlab.gitlabmock")
|
|
78
|
+
|
|
79
|
+
def list_issues_listed_default() -> Case[IssuesPage]:
|
|
80
|
+
return Case.branch_result(LISTED, IssuesPage(issues=(Issue(id=123, iid=7, title='Review release notes', labels=('review',), web_url='https://gitlab.com/meridian/web/-/issues/7'),)))
|
|
81
|
+
|
|
82
|
+
setattr(list_issues_listed_default, '__module__', "dex_connectors.gitlab.gitlabmock")
|
|
83
|
+
|
|
84
|
+
def update_issue_labels_updated(value: Issue, failure: Failure | None = None) -> Case[Issue]:
|
|
85
|
+
return Case.branch_result(UPDATED, value, failure)
|
|
86
|
+
|
|
87
|
+
setattr(update_issue_labels_updated, '__module__', "dex_connectors.gitlab.gitlabmock")
|
|
88
|
+
|
|
89
|
+
def update_issue_labels_not_found(value: Issue, failure: Failure | None = None) -> Case[Issue]:
|
|
90
|
+
return Case.branch_result(NOT_FOUND, value, failure)
|
|
91
|
+
|
|
92
|
+
setattr(update_issue_labels_not_found, '__module__', "dex_connectors.gitlab.gitlabmock")
|
|
93
|
+
|
|
94
|
+
def update_issue_labels_provider_rejected(value: Issue, failure: Failure | None = None) -> Case[Issue]:
|
|
95
|
+
return Case.branch_result(PROVIDER_REJECTED, value, failure)
|
|
96
|
+
|
|
97
|
+
setattr(update_issue_labels_provider_rejected, '__module__', "dex_connectors.gitlab.gitlabmock")
|
|
98
|
+
|
|
99
|
+
def update_issue_labels_invalid_response(value: Issue, failure: Failure | None = None) -> Case[Issue]:
|
|
100
|
+
return Case.branch_result(INVALID_RESPONSE, value, failure)
|
|
101
|
+
|
|
102
|
+
setattr(update_issue_labels_invalid_response, '__module__', "dex_connectors.gitlab.gitlabmock")
|
|
103
|
+
|
|
104
|
+
def update_issue_labels_defect(value: Issue, failure: Failure | None = None) -> Case[Issue]:
|
|
105
|
+
return Case.branch_result(DEFECT, value, failure)
|
|
106
|
+
|
|
107
|
+
setattr(update_issue_labels_defect, '__module__', "dex_connectors.gitlab.gitlabmock")
|
|
108
|
+
|
|
109
|
+
def update_issue_labels_retry(failure: Failure, after_seconds: float = 0) -> Case[Issue]:
|
|
110
|
+
return Case.retry(failure, after_seconds)
|
|
111
|
+
|
|
112
|
+
setattr(update_issue_labels_retry, '__module__', "dex_connectors.gitlab.gitlabmock")
|
|
113
|
+
|
|
114
|
+
def update_issue_labels_updated_default() -> Case[Issue]:
|
|
115
|
+
return Case.branch_result(UPDATED, Issue(id=123, iid=7, title='Review release notes', labels=('review', 'ready'), web_url='https://gitlab.com/meridian/web/-/issues/7'))
|
|
116
|
+
|
|
117
|
+
setattr(update_issue_labels_updated_default, '__module__', "dex_connectors.gitlab.gitlabmock")
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
class Mock:
|
|
121
|
+
|
|
122
|
+
def __init__(self, connection_name: str = "gitlab") -> None:
|
|
123
|
+
self.get_project_script: Query[GetProjectInput, Project] = Query(GET_PROJECT_DEFINITION)
|
|
124
|
+
self.get_project_script.default(get_project_found_default())
|
|
125
|
+
self.list_issues_script: Query[ListIssuesInput, IssuesPage] = Query(LIST_ISSUES_DEFINITION)
|
|
126
|
+
self.list_issues_script.default(list_issues_listed_default())
|
|
127
|
+
self.update_issue_labels_script: Mutation[UpdateIssueLabelsInput, Issue] = Mutation(UPDATE_ISSUE_LABELS_DEFINITION)
|
|
128
|
+
self.update_issue_labels_script.default(update_issue_labels_updated_default())
|
|
129
|
+
self._connection = new_connection_with_operations(
|
|
130
|
+
get_project=self.get_project_script,
|
|
131
|
+
list_issues=self.list_issues_script,
|
|
132
|
+
update_issue_labels=self.update_issue_labels_script,
|
|
133
|
+
reference=ConnectionRef(CONNECTOR_ID, connection_name),
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
def connection(self) -> Connection:
|
|
137
|
+
return self._connection
|
|
138
|
+
|
|
139
|
+
setattr(Mock, '__module__', "dex_connectors.gitlab.gitlabmock")
|
|
140
|
+
|
|
141
|
+
__all__ = [
|
|
142
|
+
"Mock",
|
|
143
|
+
"get_project_found",
|
|
144
|
+
"get_project_not_found",
|
|
145
|
+
"get_project_provider_rejected",
|
|
146
|
+
"get_project_invalid_response",
|
|
147
|
+
"get_project_defect",
|
|
148
|
+
"get_project_retry",
|
|
149
|
+
"get_project_found_default",
|
|
150
|
+
"list_issues_listed",
|
|
151
|
+
"list_issues_not_found",
|
|
152
|
+
"list_issues_provider_rejected",
|
|
153
|
+
"list_issues_invalid_response",
|
|
154
|
+
"list_issues_defect",
|
|
155
|
+
"list_issues_retry",
|
|
156
|
+
"list_issues_listed_default",
|
|
157
|
+
"update_issue_labels_updated",
|
|
158
|
+
"update_issue_labels_not_found",
|
|
159
|
+
"update_issue_labels_provider_rejected",
|
|
160
|
+
"update_issue_labels_invalid_response",
|
|
161
|
+
"update_issue_labels_defect",
|
|
162
|
+
"update_issue_labels_retry",
|
|
163
|
+
"update_issue_labels_updated_default",
|
|
164
|
+
]
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass, field as _dataclass_field
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
def _replace_nil_slices(value: Any, depth: int) -> Any:
|
|
9
|
+
if value is None:
|
|
10
|
+
return ()
|
|
11
|
+
if depth == 1:
|
|
12
|
+
return tuple(value)
|
|
13
|
+
return tuple(_replace_nil_slices(item, depth - 1) for item in value)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# GetProjectInput identifies a project by numeric ID or namespace path.
|
|
17
|
+
@dataclass(frozen=True, slots=True)
|
|
18
|
+
class GetProjectInput:
|
|
19
|
+
# ProjectID is a numeric ID or namespace path, such as meridian/web.
|
|
20
|
+
project_id: str = _dataclass_field(default='', metadata={'dex_json_name': 'projectId'})
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
setattr(GetProjectInput, '__module__', 'dex_connectors.gitlab.models')
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# Project is a GitLab project summary.
|
|
27
|
+
@dataclass(frozen=True, slots=True)
|
|
28
|
+
class Project:
|
|
29
|
+
# ID is the project's numeric identifier.
|
|
30
|
+
id: int = 0
|
|
31
|
+
# Name is the project display name.
|
|
32
|
+
name: str = ''
|
|
33
|
+
# PathWithNamespace is the full group and project path.
|
|
34
|
+
path_with_namespace: str = ''
|
|
35
|
+
# WebURL links to the project's GitLab page.
|
|
36
|
+
web_url: str = ''
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
setattr(Project, '__module__', 'dex_connectors.gitlab.models')
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
# ListIssuesInput identifies the project whose issues are listed.
|
|
43
|
+
@dataclass(frozen=True, slots=True)
|
|
44
|
+
class ListIssuesInput:
|
|
45
|
+
# ProjectID is a numeric ID or namespace path.
|
|
46
|
+
project_id: str = _dataclass_field(default='', metadata={'dex_json_name': 'projectId'})
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
setattr(ListIssuesInput, '__module__', 'dex_connectors.gitlab.models')
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
# Issue is a GitLab issue summary.
|
|
53
|
+
@dataclass(frozen=True, slots=True)
|
|
54
|
+
class Issue:
|
|
55
|
+
# ID is the global issue identifier.
|
|
56
|
+
id: int = 0
|
|
57
|
+
# IID is the issue number inside its project.
|
|
58
|
+
iid: int = 0
|
|
59
|
+
# Title is the issue title.
|
|
60
|
+
title: str = ''
|
|
61
|
+
# Labels is the issue's complete label set.
|
|
62
|
+
labels: tuple[str, ...] = ()
|
|
63
|
+
# WebURL links to the issue in GitLab.
|
|
64
|
+
web_url: str = ''
|
|
65
|
+
|
|
66
|
+
def __post_init__(self) -> None:
|
|
67
|
+
object.__setattr__(self, 'labels', _replace_nil_slices(self.labels, 1))
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
Issue.__annotations__['labels'] = tuple[str, ...] | None
|
|
71
|
+
Issue.__dataclass_fields__['labels'].type = tuple[str, ...] | None
|
|
72
|
+
setattr(Issue, '__module__', 'dex_connectors.gitlab.models')
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
# IssuesPage contains GitLab's default issue page.
|
|
76
|
+
@dataclass(frozen=True, slots=True)
|
|
77
|
+
class IssuesPage:
|
|
78
|
+
# Issues contains one provider page, possibly empty.
|
|
79
|
+
issues: tuple[Issue, ...] = ()
|
|
80
|
+
|
|
81
|
+
def __post_init__(self) -> None:
|
|
82
|
+
object.__setattr__(self, 'issues', _replace_nil_slices(self.issues, 1))
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
IssuesPage.__annotations__['issues'] = tuple[Issue, ...] | None
|
|
86
|
+
IssuesPage.__dataclass_fields__['issues'].type = tuple[Issue, ...] | None
|
|
87
|
+
setattr(IssuesPage, '__module__', 'dex_connectors.gitlab.models')
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
# UpdateIssueLabelsInput replaces every label on one issue; an empty list clears them.
|
|
91
|
+
@dataclass(frozen=True, slots=True)
|
|
92
|
+
class UpdateIssueLabelsInput:
|
|
93
|
+
# ProjectID is a numeric ID or namespace path.
|
|
94
|
+
project_id: str = _dataclass_field(default='', metadata={'dex_json_name': 'projectId'})
|
|
95
|
+
# IssueIID is the positive project-local issue number.
|
|
96
|
+
issue_iid: int = _dataclass_field(default=0, metadata={'dex_json_name': 'issueIid'})
|
|
97
|
+
# Labels is the desired complete label set; empty clears all labels.
|
|
98
|
+
labels: tuple[str, ...] = ()
|
|
99
|
+
|
|
100
|
+
def __post_init__(self) -> None:
|
|
101
|
+
object.__setattr__(self, 'labels', _replace_nil_slices(self.labels, 1))
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
UpdateIssueLabelsInput.__annotations__['labels'] = tuple[str, ...] | None
|
|
105
|
+
UpdateIssueLabelsInput.__dataclass_fields__['labels'].type = tuple[str, ...] | None
|
|
106
|
+
setattr(UpdateIssueLabelsInput, '__module__', 'dex_connectors.gitlab.models')
|