render-lab-tasks-gitlab 0.1.0__tar.gz
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.
- render_lab_tasks_gitlab-0.1.0/.gitignore +11 -0
- render_lab_tasks_gitlab-0.1.0/LICENSE +21 -0
- render_lab_tasks_gitlab-0.1.0/PKG-INFO +80 -0
- render_lab_tasks_gitlab-0.1.0/README.md +66 -0
- render_lab_tasks_gitlab-0.1.0/pyproject.toml +23 -0
- render_lab_tasks_gitlab-0.1.0/src/render_lab_tasks_gitlab/__init__.py +1 -0
- render_lab_tasks_gitlab-0.1.0/src/render_lab_tasks_gitlab/_app.py +3 -0
- render_lab_tasks_gitlab-0.1.0/src/render_lab_tasks_gitlab/client.py +187 -0
- render_lab_tasks_gitlab-0.1.0/src/render_lab_tasks_gitlab/close_issue.py +18 -0
- render_lab_tasks_gitlab-0.1.0/src/render_lab_tasks_gitlab/comment.py +18 -0
- render_lab_tasks_gitlab-0.1.0/src/render_lab_tasks_gitlab/create_issue.py +18 -0
- render_lab_tasks_gitlab-0.1.0/src/render_lab_tasks_gitlab/create_merge_request.py +18 -0
- render_lab_tasks_gitlab-0.1.0/src/render_lab_tasks_gitlab/get_issue.py +18 -0
- render_lab_tasks_gitlab-0.1.0/src/render_lab_tasks_gitlab/get_merge_request.py +18 -0
- render_lab_tasks_gitlab-0.1.0/src/render_lab_tasks_gitlab/get_pipeline_status.py +18 -0
- render_lab_tasks_gitlab-0.1.0/src/render_lab_tasks_gitlab/list_merge_requests.py +20 -0
- render_lab_tasks_gitlab-0.1.0/src/render_lab_tasks_gitlab/merge_when_green.py +18 -0
- render_lab_tasks_gitlab-0.1.0/src/render_lab_tasks_gitlab/py.typed +0 -0
- render_lab_tasks_gitlab-0.1.0/src/render_lab_tasks_gitlab/retry.py +3 -0
- render_lab_tasks_gitlab-0.1.0/src/render_lab_tasks_gitlab/tasks.py +35 -0
- render_lab_tasks_gitlab-0.1.0/src/render_lab_tasks_gitlab/trigger_pipeline.py +18 -0
- render_lab_tasks_gitlab-0.1.0/src/render_lab_tasks_gitlab/types.py +106 -0
- render_lab_tasks_gitlab-0.1.0/src/render_lab_tasks_gitlab/webhooks.py +32 -0
- render_lab_tasks_gitlab-0.1.0/tests/test_contracts.py +8 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Render Lab
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: render-lab-tasks-gitlab
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: gitlab tasks for Render Workflows
|
|
5
|
+
Project-URL: Repository, https://github.com/render-lab/render-tasks-python
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.12
|
|
9
|
+
Requires-Dist: httpx<0.29,>=0.28
|
|
10
|
+
Requires-Dist: render-lab-tasks-core<0.2,>=0.1.1
|
|
11
|
+
Requires-Dist: render-lab-triggers<0.2,>=0.1.0
|
|
12
|
+
Requires-Dist: render==1.0.1
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
# render-lab-tasks-gitlab
|
|
16
|
+
|
|
17
|
+
Python port of all 10 registered tasks in the pinned TypeScript pack at
|
|
18
|
+
`45f9c2d44bd28e01ae9813e0d2ff56ee6c533816`. Python 3.12+.
|
|
19
|
+
|
|
20
|
+
From the repository, install this pack and its supporting core together:
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
pip install render-lab-tasks-gitlab==0.1.0
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Import task definitions from `render_lab_tasks_gitlab.tasks`. Combine its `app` with
|
|
27
|
+
other pack apps using `Workflows.from_workflows(...)` and call tasks with
|
|
28
|
+
`await ctx.run(task, input)`. Package roots do not register tasks. JSON fields
|
|
29
|
+
retain the TS spelling; Python functions use snake_case.
|
|
30
|
+
|
|
31
|
+
## Tasks
|
|
32
|
+
|
|
33
|
+
| Registered name | Python export (also exposes `_impl`) |
|
|
34
|
+
| --- | --- |
|
|
35
|
+
| `gitlab.closeIssue` | `close_issue` |
|
|
36
|
+
| `gitlab.comment` | `comment` |
|
|
37
|
+
| `gitlab.createIssue` | `create_issue` |
|
|
38
|
+
| `gitlab.createMergeRequest` | `create_merge_request` |
|
|
39
|
+
| `gitlab.getIssue` | `get_issue` |
|
|
40
|
+
| `gitlab.getMergeRequest` | `get_merge_request` |
|
|
41
|
+
| `gitlab.getPipelineStatus` | `get_pipeline_status` |
|
|
42
|
+
| `gitlab.listMergeRequests` | `list_merge_requests` |
|
|
43
|
+
| `gitlab.mergeWhenGreen` | `merge_when_green` |
|
|
44
|
+
| `gitlab.triggerPipeline` | `trigger_pipeline` |
|
|
45
|
+
|
|
46
|
+
## Dependencies and retries
|
|
47
|
+
|
|
48
|
+
Raw implementations accept context first and keyword-only `deps`. The `.client`
|
|
49
|
+
module exports typed `Port`, `Deps`, and `Client` classes (also vendor-named aliases).
|
|
50
|
+
Inject a fake port, or pass a caller-owned `httpx.AsyncClient` to `Client` for custom
|
|
51
|
+
transport/configuration. Default dependencies close their HTTP clients after the
|
|
52
|
+
operation. Credentials resolve at first use. HTTP and SDK retries are disabled;
|
|
53
|
+
`retry.py` owns durable retry settings. DTO types live in `.types`.
|
|
54
|
+
|
|
55
|
+
## Environment
|
|
56
|
+
|
|
57
|
+
| Variable | Contract |
|
|
58
|
+
| --- | --- |
|
|
59
|
+
| `GITLAB_TOKEN` | Required on API calls. |
|
|
60
|
+
| `GITLAB_URL` | Optional GitLab site URL; defaults to https://gitlab.com. |
|
|
61
|
+
|
|
62
|
+
## Verification and limitations
|
|
63
|
+
|
|
64
|
+
mergeWhenGreen preserves the TS behavior: success and manual pipelines permit a merge, failed/canceled pipelines throw a failure, and other/missing states throw a pending error. It inherits the normal three-retry policy, not an hour-long wait. Project paths are URL-encoded. The optional TS webhook adapter is deferred until the Python triggers contract is ported.
|
|
65
|
+
|
|
66
|
+
Shared JSON fixtures compare the Python task output with the actual pinned TS
|
|
67
|
+
implementation. REST fixtures also compare HTTP requests; HubSpot and Linear
|
|
68
|
+
fixtures compare source SDK arguments with HTTP payloads/GraphQL variables.
|
|
69
|
+
No live vendor calls were made for this batch. Registered-task parity does not
|
|
70
|
+
claim live readiness or all supporting TS exports. See the root verification
|
|
71
|
+
tracker and docs/porting-batches.md. Licensed under MIT.
|
|
72
|
+
|
|
73
|
+
## Webhook adapter
|
|
74
|
+
|
|
75
|
+
`render_lab_tasks_gitlab.webhooks.gitlab_adapter(on_event, ...)` returns a
|
|
76
|
+
registration-free adapter for `render_lab_triggers`. The callback receives the
|
|
77
|
+
verified event and returns `{"task": "namespace.task", "args": [event]}` or `None`.
|
|
78
|
+
The signing credential `GITLAB_WEBHOOK_SECRET` is read inside verification unless
|
|
79
|
+
provided explicitly. Importing this module does not register tasks. Signature
|
|
80
|
+
checks use the raw body; live delivery remains in the testing backlog.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# render-lab-tasks-gitlab
|
|
2
|
+
|
|
3
|
+
Python port of all 10 registered tasks in the pinned TypeScript pack at
|
|
4
|
+
`45f9c2d44bd28e01ae9813e0d2ff56ee6c533816`. Python 3.12+.
|
|
5
|
+
|
|
6
|
+
From the repository, install this pack and its supporting core together:
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
pip install render-lab-tasks-gitlab==0.1.0
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Import task definitions from `render_lab_tasks_gitlab.tasks`. Combine its `app` with
|
|
13
|
+
other pack apps using `Workflows.from_workflows(...)` and call tasks with
|
|
14
|
+
`await ctx.run(task, input)`. Package roots do not register tasks. JSON fields
|
|
15
|
+
retain the TS spelling; Python functions use snake_case.
|
|
16
|
+
|
|
17
|
+
## Tasks
|
|
18
|
+
|
|
19
|
+
| Registered name | Python export (also exposes `_impl`) |
|
|
20
|
+
| --- | --- |
|
|
21
|
+
| `gitlab.closeIssue` | `close_issue` |
|
|
22
|
+
| `gitlab.comment` | `comment` |
|
|
23
|
+
| `gitlab.createIssue` | `create_issue` |
|
|
24
|
+
| `gitlab.createMergeRequest` | `create_merge_request` |
|
|
25
|
+
| `gitlab.getIssue` | `get_issue` |
|
|
26
|
+
| `gitlab.getMergeRequest` | `get_merge_request` |
|
|
27
|
+
| `gitlab.getPipelineStatus` | `get_pipeline_status` |
|
|
28
|
+
| `gitlab.listMergeRequests` | `list_merge_requests` |
|
|
29
|
+
| `gitlab.mergeWhenGreen` | `merge_when_green` |
|
|
30
|
+
| `gitlab.triggerPipeline` | `trigger_pipeline` |
|
|
31
|
+
|
|
32
|
+
## Dependencies and retries
|
|
33
|
+
|
|
34
|
+
Raw implementations accept context first and keyword-only `deps`. The `.client`
|
|
35
|
+
module exports typed `Port`, `Deps`, and `Client` classes (also vendor-named aliases).
|
|
36
|
+
Inject a fake port, or pass a caller-owned `httpx.AsyncClient` to `Client` for custom
|
|
37
|
+
transport/configuration. Default dependencies close their HTTP clients after the
|
|
38
|
+
operation. Credentials resolve at first use. HTTP and SDK retries are disabled;
|
|
39
|
+
`retry.py` owns durable retry settings. DTO types live in `.types`.
|
|
40
|
+
|
|
41
|
+
## Environment
|
|
42
|
+
|
|
43
|
+
| Variable | Contract |
|
|
44
|
+
| --- | --- |
|
|
45
|
+
| `GITLAB_TOKEN` | Required on API calls. |
|
|
46
|
+
| `GITLAB_URL` | Optional GitLab site URL; defaults to https://gitlab.com. |
|
|
47
|
+
|
|
48
|
+
## Verification and limitations
|
|
49
|
+
|
|
50
|
+
mergeWhenGreen preserves the TS behavior: success and manual pipelines permit a merge, failed/canceled pipelines throw a failure, and other/missing states throw a pending error. It inherits the normal three-retry policy, not an hour-long wait. Project paths are URL-encoded. The optional TS webhook adapter is deferred until the Python triggers contract is ported.
|
|
51
|
+
|
|
52
|
+
Shared JSON fixtures compare the Python task output with the actual pinned TS
|
|
53
|
+
implementation. REST fixtures also compare HTTP requests; HubSpot and Linear
|
|
54
|
+
fixtures compare source SDK arguments with HTTP payloads/GraphQL variables.
|
|
55
|
+
No live vendor calls were made for this batch. Registered-task parity does not
|
|
56
|
+
claim live readiness or all supporting TS exports. See the root verification
|
|
57
|
+
tracker and docs/porting-batches.md. Licensed under MIT.
|
|
58
|
+
|
|
59
|
+
## Webhook adapter
|
|
60
|
+
|
|
61
|
+
`render_lab_tasks_gitlab.webhooks.gitlab_adapter(on_event, ...)` returns a
|
|
62
|
+
registration-free adapter for `render_lab_triggers`. The callback receives the
|
|
63
|
+
verified event and returns `{"task": "namespace.task", "args": [event]}` or `None`.
|
|
64
|
+
The signing credential `GITLAB_WEBHOOK_SECRET` is read inside verification unless
|
|
65
|
+
provided explicitly. Importing this module does not register tasks. Signature
|
|
66
|
+
checks use the raw body; live delivery remains in the testing backlog.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27,<2"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "render-lab-tasks-gitlab"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "gitlab tasks for Render Workflows"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.12"
|
|
13
|
+
dependencies = ["render-lab-triggers>=0.1.0,<0.2", "render==1.0.1", "httpx>=0.28,<0.29", "render-lab-tasks-core>=0.1.1,<0.2"]
|
|
14
|
+
|
|
15
|
+
[project.urls]
|
|
16
|
+
Repository = "https://github.com/render-lab/render-tasks-python"
|
|
17
|
+
|
|
18
|
+
[tool.uv.sources]
|
|
19
|
+
render-lab-triggers = { workspace = true }
|
|
20
|
+
render-lab-tasks-core = { workspace = true }
|
|
21
|
+
|
|
22
|
+
[tool.hatch.build.targets.wheel]
|
|
23
|
+
packages = ["src/render_lab_tasks_gitlab"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Import .tasks explicitly to register durable tasks."""
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"""Injected vendor interface and one-attempt async HTTP adapter."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from collections.abc import AsyncIterator, Mapping
|
|
7
|
+
from contextlib import asynccontextmanager
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from typing import Any, Protocol
|
|
10
|
+
|
|
11
|
+
import httpx
|
|
12
|
+
from render_lab_tasks_core.http import HttpClient, enc, js_string, nullish, pick, query, required
|
|
13
|
+
|
|
14
|
+
from . import types as t
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def to_issue(raw: Mapping[str, Any]) -> dict[str, Any]:
|
|
18
|
+
return {
|
|
19
|
+
"iid": nullish(raw.get("iid"), 0),
|
|
20
|
+
"title": nullish(raw.get("title"), ""),
|
|
21
|
+
"state": nullish(raw.get("state"), ""),
|
|
22
|
+
"webUrl": nullish(raw.get("web_url"), ""),
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def to_mr(raw: Mapping[str, Any]) -> dict[str, Any]:
|
|
27
|
+
return {
|
|
28
|
+
**to_issue(raw),
|
|
29
|
+
"sourceBranch": nullish(raw.get("source_branch"), ""),
|
|
30
|
+
"targetBranch": nullish(raw.get("target_branch"), ""),
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def to_pipeline(raw: Mapping[str, Any]) -> dict[str, Any]:
|
|
35
|
+
return {
|
|
36
|
+
"id": nullish(raw.get("id"), 0),
|
|
37
|
+
"status": nullish(raw.get("status"), ""),
|
|
38
|
+
"webUrl": nullish(raw.get("web_url"), ""),
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class Port(Protocol):
|
|
43
|
+
async def close_issue(self, input: t.CloseIssueInput) -> t.CloseIssueResult: ...
|
|
44
|
+
async def comment(self, input: t.CommentInput) -> t.CommentResult: ...
|
|
45
|
+
async def create_issue(self, input: t.CreateIssueInput) -> t.CreateIssueResult: ...
|
|
46
|
+
async def create_merge_request(self, input: t.CreateMergeRequestInput) -> t.MergeRequest: ...
|
|
47
|
+
async def get_issue(self, input: t.GetIssueInput) -> t.Issue: ...
|
|
48
|
+
async def get_merge_request(self, input: t.GetMergeRequestInput) -> t.MergeRequest: ...
|
|
49
|
+
async def get_pipeline_status(self, input: t.GetPipelineStatusInput) -> t.Pipeline: ...
|
|
50
|
+
async def list_merge_requests(
|
|
51
|
+
self, input: t.ListMergeRequestsInput
|
|
52
|
+
) -> list[t.MergeRequest]: ...
|
|
53
|
+
async def merge_when_green(self, input: t.MergeWhenGreenInput) -> t.MergeResult: ...
|
|
54
|
+
async def trigger_pipeline(self, input: t.TriggerPipelineInput) -> t.Pipeline: ...
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@dataclass(frozen=True)
|
|
58
|
+
class Deps:
|
|
59
|
+
gitlab: Port
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class Client:
|
|
63
|
+
def __init__(self, http: httpx.AsyncClient, env: Mapping[str, str] | None = None) -> None:
|
|
64
|
+
self.env = os.environ if env is None else env
|
|
65
|
+
self.http = HttpClient(
|
|
66
|
+
http,
|
|
67
|
+
lambda: (self.env.get("GITLAB_URL") or "https://gitlab.com").rstrip("/") + "/api/v4",
|
|
68
|
+
auth=lambda: {"PRIVATE-TOKEN": required(self.env, "GITLAB_TOKEN")},
|
|
69
|
+
label="GitLab API",
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
def _project(self, input: Mapping[str, Any]) -> str:
|
|
73
|
+
return f"/projects/{enc(input['project'])}"
|
|
74
|
+
|
|
75
|
+
async def list_merge_requests(self, input: t.ListMergeRequestsInput) -> Any:
|
|
76
|
+
params: dict[str, Any] = {}
|
|
77
|
+
if "state" in input:
|
|
78
|
+
params["state"] = input["state"]
|
|
79
|
+
if "limit" in input:
|
|
80
|
+
params["per_page"] = input["limit"]
|
|
81
|
+
data = await self.http.call(
|
|
82
|
+
self._project(input) + "/merge_requests" + ("?" + query(params) if params else "")
|
|
83
|
+
)
|
|
84
|
+
return [to_mr(r) for r in data] if isinstance(data, list) else []
|
|
85
|
+
|
|
86
|
+
async def merge_when_green(self, input: t.MergeWhenGreenInput) -> Any:
|
|
87
|
+
path = self._project(input) + f"/merge_requests/{js_string(input['iid'])}"
|
|
88
|
+
data = await self.http.call(path)
|
|
89
|
+
status = nullish(
|
|
90
|
+
((data or {}).get("head_pipeline") or {}).get("status"),
|
|
91
|
+
((data or {}).get("pipeline") or {}).get("status"),
|
|
92
|
+
)
|
|
93
|
+
if status in ("failed", "canceled"):
|
|
94
|
+
raise RuntimeError(f"MR !{js_string(input['iid'])} checks failing")
|
|
95
|
+
if status not in ("success", "manual"):
|
|
96
|
+
raise RuntimeError(f"MR !{js_string(input['iid'])} checks pending")
|
|
97
|
+
data = await self.http.call(path + "/merge", method="PUT")
|
|
98
|
+
state = nullish((data or {}).get("state"), "")
|
|
99
|
+
return {"iid": input["iid"], "merged": state == "merged", "state": state}
|
|
100
|
+
|
|
101
|
+
async def create_issue(self, input: t.CreateIssueInput) -> Any:
|
|
102
|
+
body = pick(input, "title", "description")
|
|
103
|
+
if "labels" in input:
|
|
104
|
+
body["labels"] = ",".join(input["labels"])
|
|
105
|
+
data = await self.http.call(self._project(input) + "/issues", method="POST", body=body)
|
|
106
|
+
return {
|
|
107
|
+
"iid": nullish((data or {}).get("iid"), 0),
|
|
108
|
+
"url": nullish((data or {}).get("web_url"), ""),
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async def comment(self, input: t.CommentInput) -> Any:
|
|
112
|
+
resource = "merge_requests" if input.get("kind") == "merge_request" else "issues"
|
|
113
|
+
data = await self.http.call(
|
|
114
|
+
self._project(input) + f"/{resource}/{js_string(input['iid'])}/notes",
|
|
115
|
+
method="POST",
|
|
116
|
+
body={"body": input["body"]},
|
|
117
|
+
)
|
|
118
|
+
return {"iid": input["iid"], "noteId": nullish((data or {}).get("id"), 0)}
|
|
119
|
+
|
|
120
|
+
async def create_merge_request(self, input: t.CreateMergeRequestInput) -> Any:
|
|
121
|
+
body = {
|
|
122
|
+
"source_branch": input["sourceBranch"],
|
|
123
|
+
"target_branch": input["targetBranch"],
|
|
124
|
+
**pick(input, "title", "description"),
|
|
125
|
+
}
|
|
126
|
+
data = await self.http.call(
|
|
127
|
+
self._project(input) + "/merge_requests", method="POST", body=body
|
|
128
|
+
)
|
|
129
|
+
return to_mr(data or {})
|
|
130
|
+
|
|
131
|
+
async def get_merge_request(self, input: t.GetMergeRequestInput) -> Any:
|
|
132
|
+
return to_mr(
|
|
133
|
+
(
|
|
134
|
+
await self.http.call(
|
|
135
|
+
self._project(input) + f"/merge_requests/{js_string(input['iid'])}"
|
|
136
|
+
)
|
|
137
|
+
)
|
|
138
|
+
or {}
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
async def trigger_pipeline(self, input: t.TriggerPipelineInput) -> Any:
|
|
142
|
+
return to_pipeline(
|
|
143
|
+
(
|
|
144
|
+
await self.http.call(
|
|
145
|
+
self._project(input) + "/pipeline", method="POST", body={"ref": input["ref"]}
|
|
146
|
+
)
|
|
147
|
+
)
|
|
148
|
+
or {}
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
async def get_pipeline_status(self, input: t.GetPipelineStatusInput) -> Any:
|
|
152
|
+
return to_pipeline(
|
|
153
|
+
(await self.http.call(self._project(input) + f"/pipelines/{js_string(input['id'])}"))
|
|
154
|
+
or {}
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
async def get_issue(self, input: t.GetIssueInput) -> Any:
|
|
158
|
+
return to_issue(
|
|
159
|
+
(await self.http.call(self._project(input) + f"/issues/{js_string(input['iid'])}"))
|
|
160
|
+
or {}
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
async def close_issue(self, input: t.CloseIssueInput) -> Any:
|
|
164
|
+
data = await self.http.call(
|
|
165
|
+
self._project(input) + f"/issues/{js_string(input['iid'])}?state_event=close",
|
|
166
|
+
method="PUT",
|
|
167
|
+
)
|
|
168
|
+
return {
|
|
169
|
+
"iid": nullish((data or {}).get("iid"), input["iid"]),
|
|
170
|
+
"state": nullish((data or {}).get("state"), ""),
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
@asynccontextmanager
|
|
175
|
+
async def dependencies(deps: Deps | None) -> AsyncIterator[Deps]:
|
|
176
|
+
if deps is not None:
|
|
177
|
+
yield deps
|
|
178
|
+
else:
|
|
179
|
+
async with httpx.AsyncClient(
|
|
180
|
+
timeout=30, transport=httpx.AsyncHTTPTransport(retries=0)
|
|
181
|
+
) as http:
|
|
182
|
+
yield Deps(gitlab=Client(http))
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
GitLabPort = Port
|
|
186
|
+
GitLabClient = Client
|
|
187
|
+
GitLabDeps = Deps
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import GITLAB_RETRY
|
|
6
|
+
from .types import CloseIssueInput, CloseIssueResult
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def close_issue_impl(
|
|
10
|
+
ctx: TaskContext, input: CloseIssueInput, *, deps: Deps | None = None
|
|
11
|
+
) -> CloseIssueResult:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.gitlab.close_issue(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="gitlab.closeIssue", retry=GITLAB_RETRY)
|
|
17
|
+
async def close_issue(ctx: TaskContext, input: CloseIssueInput) -> CloseIssueResult:
|
|
18
|
+
return await close_issue_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import GITLAB_RETRY
|
|
6
|
+
from .types import CommentInput, CommentResult
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def comment_impl(
|
|
10
|
+
ctx: TaskContext, input: CommentInput, *, deps: Deps | None = None
|
|
11
|
+
) -> CommentResult:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.gitlab.comment(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="gitlab.comment", retry=GITLAB_RETRY)
|
|
17
|
+
async def comment(ctx: TaskContext, input: CommentInput) -> CommentResult:
|
|
18
|
+
return await comment_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import GITLAB_RETRY
|
|
6
|
+
from .types import CreateIssueInput, CreateIssueResult
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def create_issue_impl(
|
|
10
|
+
ctx: TaskContext, input: CreateIssueInput, *, deps: Deps | None = None
|
|
11
|
+
) -> CreateIssueResult:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.gitlab.create_issue(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="gitlab.createIssue", retry=GITLAB_RETRY)
|
|
17
|
+
async def create_issue(ctx: TaskContext, input: CreateIssueInput) -> CreateIssueResult:
|
|
18
|
+
return await create_issue_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import GITLAB_RETRY
|
|
6
|
+
from .types import CreateMergeRequestInput, MergeRequest
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def create_merge_request_impl(
|
|
10
|
+
ctx: TaskContext, input: CreateMergeRequestInput, *, deps: Deps | None = None
|
|
11
|
+
) -> MergeRequest:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.gitlab.create_merge_request(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="gitlab.createMergeRequest", retry=GITLAB_RETRY)
|
|
17
|
+
async def create_merge_request(ctx: TaskContext, input: CreateMergeRequestInput) -> MergeRequest:
|
|
18
|
+
return await create_merge_request_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import GITLAB_RETRY
|
|
6
|
+
from .types import GetIssueInput, Issue
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def get_issue_impl(
|
|
10
|
+
ctx: TaskContext, input: GetIssueInput, *, deps: Deps | None = None
|
|
11
|
+
) -> Issue:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.gitlab.get_issue(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="gitlab.getIssue", retry=GITLAB_RETRY)
|
|
17
|
+
async def get_issue(ctx: TaskContext, input: GetIssueInput) -> Issue:
|
|
18
|
+
return await get_issue_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import GITLAB_RETRY
|
|
6
|
+
from .types import GetMergeRequestInput, MergeRequest
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def get_merge_request_impl(
|
|
10
|
+
ctx: TaskContext, input: GetMergeRequestInput, *, deps: Deps | None = None
|
|
11
|
+
) -> MergeRequest:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.gitlab.get_merge_request(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="gitlab.getMergeRequest", retry=GITLAB_RETRY)
|
|
17
|
+
async def get_merge_request(ctx: TaskContext, input: GetMergeRequestInput) -> MergeRequest:
|
|
18
|
+
return await get_merge_request_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import GITLAB_RETRY
|
|
6
|
+
from .types import GetPipelineStatusInput, Pipeline
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def get_pipeline_status_impl(
|
|
10
|
+
ctx: TaskContext, input: GetPipelineStatusInput, *, deps: Deps | None = None
|
|
11
|
+
) -> Pipeline:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.gitlab.get_pipeline_status(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="gitlab.getPipelineStatus", retry=GITLAB_RETRY)
|
|
17
|
+
async def get_pipeline_status(ctx: TaskContext, input: GetPipelineStatusInput) -> Pipeline:
|
|
18
|
+
return await get_pipeline_status_impl(ctx, input)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import GITLAB_RETRY
|
|
6
|
+
from .types import ListMergeRequestsInput, MergeRequest
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def list_merge_requests_impl(
|
|
10
|
+
ctx: TaskContext, input: ListMergeRequestsInput, *, deps: Deps | None = None
|
|
11
|
+
) -> list[MergeRequest]:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.gitlab.list_merge_requests(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="gitlab.listMergeRequests", retry=GITLAB_RETRY)
|
|
17
|
+
async def list_merge_requests(
|
|
18
|
+
ctx: TaskContext, input: ListMergeRequestsInput
|
|
19
|
+
) -> list[MergeRequest]:
|
|
20
|
+
return await list_merge_requests_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import GITLAB_RETRY
|
|
6
|
+
from .types import MergeResult, MergeWhenGreenInput
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def merge_when_green_impl(
|
|
10
|
+
ctx: TaskContext, input: MergeWhenGreenInput, *, deps: Deps | None = None
|
|
11
|
+
) -> MergeResult:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.gitlab.merge_when_green(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="gitlab.mergeWhenGreen", retry=GITLAB_RETRY)
|
|
17
|
+
async def merge_when_green(ctx: TaskContext, input: MergeWhenGreenInput) -> MergeResult:
|
|
18
|
+
return await merge_when_green_impl(ctx, input)
|
|
File without changes
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from ._app import app
|
|
2
|
+
from .close_issue import close_issue, close_issue_impl
|
|
3
|
+
from .comment import comment, comment_impl
|
|
4
|
+
from .create_issue import create_issue, create_issue_impl
|
|
5
|
+
from .create_merge_request import create_merge_request, create_merge_request_impl
|
|
6
|
+
from .get_issue import get_issue, get_issue_impl
|
|
7
|
+
from .get_merge_request import get_merge_request, get_merge_request_impl
|
|
8
|
+
from .get_pipeline_status import get_pipeline_status, get_pipeline_status_impl
|
|
9
|
+
from .list_merge_requests import list_merge_requests, list_merge_requests_impl
|
|
10
|
+
from .merge_when_green import merge_when_green, merge_when_green_impl
|
|
11
|
+
from .trigger_pipeline import trigger_pipeline, trigger_pipeline_impl
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
"app",
|
|
15
|
+
"close_issue",
|
|
16
|
+
"close_issue_impl",
|
|
17
|
+
"comment",
|
|
18
|
+
"comment_impl",
|
|
19
|
+
"create_issue",
|
|
20
|
+
"create_issue_impl",
|
|
21
|
+
"create_merge_request",
|
|
22
|
+
"create_merge_request_impl",
|
|
23
|
+
"get_issue",
|
|
24
|
+
"get_issue_impl",
|
|
25
|
+
"get_merge_request",
|
|
26
|
+
"get_merge_request_impl",
|
|
27
|
+
"get_pipeline_status",
|
|
28
|
+
"get_pipeline_status_impl",
|
|
29
|
+
"list_merge_requests",
|
|
30
|
+
"list_merge_requests_impl",
|
|
31
|
+
"merge_when_green",
|
|
32
|
+
"merge_when_green_impl",
|
|
33
|
+
"trigger_pipeline",
|
|
34
|
+
"trigger_pipeline_impl",
|
|
35
|
+
]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import GITLAB_RETRY
|
|
6
|
+
from .types import Pipeline, TriggerPipelineInput
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def trigger_pipeline_impl(
|
|
10
|
+
ctx: TaskContext, input: TriggerPipelineInput, *, deps: Deps | None = None
|
|
11
|
+
) -> Pipeline:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.gitlab.trigger_pipeline(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="gitlab.triggerPipeline", retry=GITLAB_RETRY)
|
|
17
|
+
async def trigger_pipeline(ctx: TaskContext, input: TriggerPipelineInput) -> Pipeline:
|
|
18
|
+
return await trigger_pipeline_impl(ctx, input)
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"""JSON contracts ported from the pinned TypeScript pack."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Literal, NotRequired, TypedDict
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class MergeRequest(TypedDict):
|
|
9
|
+
iid: float
|
|
10
|
+
title: str
|
|
11
|
+
state: str
|
|
12
|
+
webUrl: str
|
|
13
|
+
sourceBranch: str
|
|
14
|
+
targetBranch: str
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class ListMergeRequestsInput(TypedDict):
|
|
18
|
+
project: str
|
|
19
|
+
state: NotRequired[Literal["opened"] | Literal["merged"] | Literal["closed"]]
|
|
20
|
+
limit: NotRequired[float]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class MergeWhenGreenInput(TypedDict):
|
|
24
|
+
project: str
|
|
25
|
+
iid: float
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class MergeResult(TypedDict):
|
|
29
|
+
iid: float
|
|
30
|
+
merged: bool
|
|
31
|
+
state: str
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class CreateIssueInput(TypedDict):
|
|
35
|
+
project: str
|
|
36
|
+
title: str
|
|
37
|
+
description: NotRequired[str]
|
|
38
|
+
labels: NotRequired[list[str]]
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class CreateIssueResult(TypedDict):
|
|
42
|
+
iid: float
|
|
43
|
+
url: str
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class CommentInput(TypedDict):
|
|
47
|
+
project: str
|
|
48
|
+
iid: float
|
|
49
|
+
body: str
|
|
50
|
+
kind: NotRequired[Literal["issue"] | Literal["merge_request"]]
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class CommentResult(TypedDict):
|
|
54
|
+
iid: float
|
|
55
|
+
noteId: float
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class CreateMergeRequestInput(TypedDict):
|
|
59
|
+
project: str
|
|
60
|
+
sourceBranch: str
|
|
61
|
+
targetBranch: str
|
|
62
|
+
title: str
|
|
63
|
+
description: NotRequired[str]
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class GetMergeRequestInput(TypedDict):
|
|
67
|
+
project: str
|
|
68
|
+
iid: float
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class Pipeline(TypedDict):
|
|
72
|
+
id: float
|
|
73
|
+
status: str
|
|
74
|
+
webUrl: str
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class TriggerPipelineInput(TypedDict):
|
|
78
|
+
project: str
|
|
79
|
+
ref: str
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
class GetPipelineStatusInput(TypedDict):
|
|
83
|
+
project: str
|
|
84
|
+
id: float
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class Issue(TypedDict):
|
|
88
|
+
iid: float
|
|
89
|
+
title: str
|
|
90
|
+
state: str
|
|
91
|
+
webUrl: str
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
class GetIssueInput(TypedDict):
|
|
95
|
+
project: str
|
|
96
|
+
iid: float
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
class CloseIssueInput(TypedDict):
|
|
100
|
+
project: str
|
|
101
|
+
iid: float
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class CloseIssueResult(TypedDict):
|
|
105
|
+
iid: float
|
|
106
|
+
state: str
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""Registration-free gitlab webhook verification and event mapping."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from collections.abc import Callable
|
|
7
|
+
|
|
8
|
+
from render_lab_tasks_core.signatures import safe_equal
|
|
9
|
+
from render_lab_triggers.types import Adapter, Json, WebhookContext, WebhookDispatch, WebhookRequest
|
|
10
|
+
|
|
11
|
+
type OnEvent = Callable[[dict[str, Json]], WebhookDispatch | None]
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def verify_gitlab_token(secret: str, token: str | None) -> bool:
|
|
15
|
+
return bool(token) and safe_equal(token, secret)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def gitlab_adapter(
|
|
19
|
+
on_event: OnEvent, *, secret: str | None = None, header_name: str = "x-gitlab-token"
|
|
20
|
+
) -> Adapter:
|
|
21
|
+
def verify(req: WebhookRequest) -> bool:
|
|
22
|
+
key = secret if secret is not None else os.getenv("GITLAB_WEBHOOK_SECRET")
|
|
23
|
+
return bool(key) and (
|
|
24
|
+
verify_gitlab_token(key or "", req["headers"].get(header_name.lower()))
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
def map_event(ctx: WebhookContext) -> WebhookDispatch | None:
|
|
28
|
+
payload = ctx["body"] if ctx["body"] is not None else {}
|
|
29
|
+
headers = ctx["headers"]
|
|
30
|
+
return on_event({"event": headers.get("x-gitlab-event", ""), "payload": payload})
|
|
31
|
+
|
|
32
|
+
return Adapter(verify, map_event)
|