qodev-gitlab-api 0.1.2__tar.gz → 0.2.1__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.
- qodev_gitlab_api-0.2.1/LICENSE +21 -0
- qodev_gitlab_api-0.2.1/PKG-INFO +255 -0
- qodev_gitlab_api-0.2.1/README.md +225 -0
- {qodev_gitlab_api-0.1.2 → qodev_gitlab_api-0.2.1}/pyproject.toml +2 -1
- qodev_gitlab_api-0.1.2/PKG-INFO +0 -45
- qodev_gitlab_api-0.1.2/README.md +0 -17
- {qodev_gitlab_api-0.1.2 → qodev_gitlab_api-0.2.1}/.github/workflows/ci.yml +0 -0
- {qodev_gitlab_api-0.1.2 → qodev_gitlab_api-0.2.1}/.github/workflows/publish.yml +0 -0
- {qodev_gitlab_api-0.1.2 → qodev_gitlab_api-0.2.1}/.gitignore +0 -0
- {qodev_gitlab_api-0.1.2 → qodev_gitlab_api-0.2.1}/src/qodev_gitlab_api/__init__.py +0 -0
- {qodev_gitlab_api-0.1.2 → qodev_gitlab_api-0.2.1}/src/qodev_gitlab_api/_base.py +0 -0
- {qodev_gitlab_api-0.1.2 → qodev_gitlab_api-0.2.1}/src/qodev_gitlab_api/_files.py +0 -0
- {qodev_gitlab_api-0.1.2 → qodev_gitlab_api-0.2.1}/src/qodev_gitlab_api/_issues.py +0 -0
- {qodev_gitlab_api-0.1.2 → qodev_gitlab_api-0.2.1}/src/qodev_gitlab_api/_merge_requests.py +0 -0
- {qodev_gitlab_api-0.1.2 → qodev_gitlab_api-0.2.1}/src/qodev_gitlab_api/_pipelines.py +0 -0
- {qodev_gitlab_api-0.1.2 → qodev_gitlab_api-0.2.1}/src/qodev_gitlab_api/_releases.py +0 -0
- {qodev_gitlab_api-0.1.2 → qodev_gitlab_api-0.2.1}/src/qodev_gitlab_api/_variables.py +0 -0
- {qodev_gitlab_api-0.1.2 → qodev_gitlab_api-0.2.1}/src/qodev_gitlab_api/client.py +0 -0
- {qodev_gitlab_api-0.1.2 → qodev_gitlab_api-0.2.1}/src/qodev_gitlab_api/exceptions.py +0 -0
- {qodev_gitlab_api-0.1.2 → qodev_gitlab_api-0.2.1}/src/qodev_gitlab_api/models.py +0 -0
- {qodev_gitlab_api-0.1.2 → qodev_gitlab_api-0.2.1}/src/qodev_gitlab_api/py.typed +0 -0
- {qodev_gitlab_api-0.1.2 → qodev_gitlab_api-0.2.1}/tests/conftest.py +0 -0
- {qodev_gitlab_api-0.1.2 → qodev_gitlab_api-0.2.1}/tests/test_client.py +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 qodev GmbH
|
|
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,255 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: qodev-gitlab-api
|
|
3
|
+
Version: 0.2.1
|
|
4
|
+
Summary: Python client for the GitLab API
|
|
5
|
+
Project-URL: Homepage, https://github.com/qodevai/gitlab-api
|
|
6
|
+
Project-URL: Repository, https://github.com/qodevai/gitlab-api
|
|
7
|
+
Project-URL: Issues, https://github.com/qodevai/gitlab-api/issues
|
|
8
|
+
Author-email: Jan Scheffler <jan.scheffler@qodev.ai>
|
|
9
|
+
License: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: api,client,gitlab
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Typing :: Typed
|
|
20
|
+
Requires-Python: >=3.11
|
|
21
|
+
Requires-Dist: httpx>=0.28.1
|
|
22
|
+
Requires-Dist: python-dotenv>=1.1.0
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: mypy>=1.13.0; extra == 'dev'
|
|
25
|
+
Requires-Dist: pytest-cov>=4.1.0; extra == 'dev'
|
|
26
|
+
Requires-Dist: pytest-mock>=3.12.0; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest>=8.0.0; extra == 'dev'
|
|
28
|
+
Requires-Dist: ruff>=0.8.0; extra == 'dev'
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# qodev-gitlab-api
|
|
32
|
+
|
|
33
|
+
A lightweight, typed Python client for the GitLab REST API. Built on [httpx](https://www.python-httpx.org/) with automatic pagination, structured error handling, and `.env` support, it provides a clean interface for common GitLab operations without the weight of a full-featured SDK.
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install qodev-gitlab-api
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Quick Start
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from qodev_gitlab_api import GitLabClient
|
|
45
|
+
|
|
46
|
+
# Reads GITLAB_TOKEN and GITLAB_URL from environment or .env file
|
|
47
|
+
client = GitLabClient()
|
|
48
|
+
|
|
49
|
+
# Or pass credentials explicitly
|
|
50
|
+
client = GitLabClient(token="glpat-xxxxxxxxxxxx", base_url="https://gitlab.example.com")
|
|
51
|
+
|
|
52
|
+
# Skip connection validation for faster startup
|
|
53
|
+
client = GitLabClient(validate=False)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Features
|
|
57
|
+
|
|
58
|
+
- **Merge requests** -- create, update, merge, close, and review with inline diff comments
|
|
59
|
+
- **Pipelines and jobs** -- list, inspect, wait for completion, retry, and download artifacts
|
|
60
|
+
- **Issues** -- create, update, close, and comment
|
|
61
|
+
- **Releases** -- create, update, delete, and list with asset links
|
|
62
|
+
- **CI/CD variables** -- get, list, create, update, and upsert (set) project variables
|
|
63
|
+
- **File operations** -- read repository files at any ref, upload files for markdown embedding
|
|
64
|
+
- **Automatic pagination** -- all list endpoints handle multi-page results transparently
|
|
65
|
+
- **Typed exceptions** -- `AuthenticationError`, `NotFoundError`, `APIError`, `ConfigurationError`
|
|
66
|
+
|
|
67
|
+
## Configuration
|
|
68
|
+
|
|
69
|
+
The client reads configuration from environment variables, with `.env` file support via `python-dotenv`:
|
|
70
|
+
|
|
71
|
+
| Variable | Description | Default |
|
|
72
|
+
|---|---|---|
|
|
73
|
+
| `GITLAB_TOKEN` | GitLab personal access token (required) | -- |
|
|
74
|
+
| `GITLAB_URL` | GitLab instance base URL | `https://gitlab.com` |
|
|
75
|
+
|
|
76
|
+
You can also use `GITLAB_BASE_URL` as an alias for `GITLAB_URL`.
|
|
77
|
+
|
|
78
|
+
Create a `.env` file in your project root:
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
GITLAB_TOKEN=glpat-xxxxxxxxxxxxxxxxxxxx
|
|
82
|
+
GITLAB_URL=https://gitlab.example.com
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## API Reference
|
|
86
|
+
|
|
87
|
+
### Projects
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
projects = client.get_projects(owned=True)
|
|
91
|
+
project = client.get_project("my-group/my-project")
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Merge Requests
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
# List and inspect
|
|
98
|
+
mrs = client.get_merge_requests("my-group/my-project", state="opened")
|
|
99
|
+
mr = client.get_merge_request("my-group/my-project", mr_iid=42)
|
|
100
|
+
changes = client.get_mr_changes("my-group/my-project", mr_iid=42)
|
|
101
|
+
commits = client.get_mr_commits("my-group/my-project", mr_iid=42)
|
|
102
|
+
approvals = client.get_mr_approvals("my-group/my-project", mr_iid=42)
|
|
103
|
+
|
|
104
|
+
# Create
|
|
105
|
+
mr = client.create_merge_request(
|
|
106
|
+
"my-group/my-project",
|
|
107
|
+
source_branch="feature/foo",
|
|
108
|
+
target_branch="main",
|
|
109
|
+
title="Add foo feature",
|
|
110
|
+
description="Implements the foo feature.",
|
|
111
|
+
assignee_ids=[123],
|
|
112
|
+
reviewer_ids=[456],
|
|
113
|
+
labels="enhancement",
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
# Update, merge, close
|
|
117
|
+
client.update_mr("my-group/my-project", mr_iid=42, title="Updated title")
|
|
118
|
+
client.merge_mr("my-group/my-project", mr_iid=42, squash=True)
|
|
119
|
+
client.close_mr("my-group/my-project", mr_iid=42)
|
|
120
|
+
|
|
121
|
+
# Discussions and comments
|
|
122
|
+
discussions = client.get_mr_discussions("my-group/my-project", mr_iid=42)
|
|
123
|
+
client.create_mr_note("my-group/my-project", mr_iid=42, body="Looks good!")
|
|
124
|
+
client.reply_to_discussion("my-group/my-project", mr_iid=42, discussion_id="abc123", body="Fixed.")
|
|
125
|
+
client.resolve_discussion("my-group/my-project", mr_iid=42, discussion_id="abc123", resolved=True)
|
|
126
|
+
|
|
127
|
+
# Inline diff comment
|
|
128
|
+
from qodev_gitlab_api import DiffPosition
|
|
129
|
+
|
|
130
|
+
client.create_mr_discussion(
|
|
131
|
+
"my-group/my-project",
|
|
132
|
+
mr_iid=42,
|
|
133
|
+
body="Consider renaming this variable.",
|
|
134
|
+
position=DiffPosition(file_path="src/main.py", new_line=15),
|
|
135
|
+
)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Pipelines and Jobs
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
pipelines = client.get_pipelines("my-group/my-project", ref="main")
|
|
142
|
+
pipeline = client.get_pipeline("my-group/my-project", pipeline_id=1001)
|
|
143
|
+
jobs = client.get_pipeline_jobs("my-group/my-project", pipeline_id=1001)
|
|
144
|
+
|
|
145
|
+
# Job details, logs, and artifacts
|
|
146
|
+
job = client.get_job("my-group/my-project", job_id=5001)
|
|
147
|
+
log = client.get_job_log("my-group/my-project", job_id=5001)
|
|
148
|
+
artifact = client.get_job_artifact("my-group/my-project", job_id=5001, artifact_path="report.xml")
|
|
149
|
+
|
|
150
|
+
# Retry a failed job
|
|
151
|
+
client.retry_job("my-group/my-project", job_id=5001)
|
|
152
|
+
|
|
153
|
+
# Wait for pipeline completion (blocks until done or timeout)
|
|
154
|
+
result = client.wait_for_pipeline("my-group/my-project", pipeline_id=1001, timeout_seconds=600)
|
|
155
|
+
print(result["final_status"]) # "success", "failed", "canceled", "skipped", or "timeout"
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Issues
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
issues = client.get_issues("my-group/my-project", state="opened", labels="bug")
|
|
162
|
+
issue = client.get_issue("my-group/my-project", issue_iid=10)
|
|
163
|
+
|
|
164
|
+
issue = client.create_issue(
|
|
165
|
+
"my-group/my-project",
|
|
166
|
+
title="Fix login bug",
|
|
167
|
+
description="Users cannot log in with SSO.",
|
|
168
|
+
labels="bug,urgent",
|
|
169
|
+
assignee_ids=[123],
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
client.update_issue("my-group/my-project", issue_iid=10, labels="bug,resolved")
|
|
173
|
+
client.close_issue("my-group/my-project", issue_iid=10)
|
|
174
|
+
|
|
175
|
+
# Comments
|
|
176
|
+
notes = client.get_issue_notes("my-group/my-project", issue_iid=10)
|
|
177
|
+
client.create_issue_note("my-group/my-project", issue_iid=10, body="Investigating this now.")
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Releases
|
|
181
|
+
|
|
182
|
+
```python
|
|
183
|
+
releases = client.get_releases("my-group/my-project")
|
|
184
|
+
release = client.get_release("my-group/my-project", tag_name="v1.0.0")
|
|
185
|
+
|
|
186
|
+
release = client.create_release(
|
|
187
|
+
"my-group/my-project",
|
|
188
|
+
tag_name="v1.1.0",
|
|
189
|
+
name="Version 1.1.0",
|
|
190
|
+
description="## What's new\n- Feature A\n- Bug fix B",
|
|
191
|
+
ref="main",
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
client.update_release("my-group/my-project", tag_name="v1.1.0", description="Updated notes.")
|
|
195
|
+
client.delete_release("my-group/my-project", tag_name="v1.1.0")
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### CI/CD Variables
|
|
199
|
+
|
|
200
|
+
```python
|
|
201
|
+
variables = client.list_project_variables("my-group/my-project")
|
|
202
|
+
var = client.get_project_variable("my-group/my-project", key="API_KEY")
|
|
203
|
+
|
|
204
|
+
# Create or update (upsert)
|
|
205
|
+
var, action = client.set_project_variable(
|
|
206
|
+
"my-group/my-project",
|
|
207
|
+
key="API_KEY",
|
|
208
|
+
value="secret-value",
|
|
209
|
+
masked=True,
|
|
210
|
+
protected=True,
|
|
211
|
+
)
|
|
212
|
+
print(action) # "created" or "updated"
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### File Operations
|
|
216
|
+
|
|
217
|
+
```python
|
|
218
|
+
# Read a file from the repository
|
|
219
|
+
content = client.get_file_content("my-group/my-project", file_path="README.md", ref="main")
|
|
220
|
+
|
|
221
|
+
# Upload a file (for embedding in issues/MRs)
|
|
222
|
+
from qodev_gitlab_api import FileFromPath
|
|
223
|
+
|
|
224
|
+
result = client.upload_file("my-group/my-project", source=FileFromPath(path="/tmp/screenshot.png"))
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## Error Handling
|
|
228
|
+
|
|
229
|
+
All API errors raise typed exceptions that inherit from `GitLabError`:
|
|
230
|
+
|
|
231
|
+
```python
|
|
232
|
+
from qodev_gitlab_api import GitLabClient, AuthenticationError, NotFoundError, APIError, ConfigurationError
|
|
233
|
+
|
|
234
|
+
try:
|
|
235
|
+
client = GitLabClient()
|
|
236
|
+
mr = client.get_merge_request("my-group/my-project", mr_iid=999)
|
|
237
|
+
except ConfigurationError:
|
|
238
|
+
print("Missing or invalid GITLAB_TOKEN / GITLAB_URL")
|
|
239
|
+
except AuthenticationError:
|
|
240
|
+
print("Token is invalid or expired")
|
|
241
|
+
except NotFoundError:
|
|
242
|
+
print("Merge request not found")
|
|
243
|
+
except APIError as e:
|
|
244
|
+
print(f"API error {e.status_code}: {e.response_body}")
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
## Requirements
|
|
248
|
+
|
|
249
|
+
- Python 3.11+
|
|
250
|
+
- [httpx](https://www.python-httpx.org/) >= 0.28.1
|
|
251
|
+
- [python-dotenv](https://github.com/theskumar/python-dotenv) >= 1.1.0
|
|
252
|
+
|
|
253
|
+
## License
|
|
254
|
+
|
|
255
|
+
MIT -- see [LICENSE](LICENSE) for details.
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# qodev-gitlab-api
|
|
2
|
+
|
|
3
|
+
A lightweight, typed Python client for the GitLab REST API. Built on [httpx](https://www.python-httpx.org/) with automatic pagination, structured error handling, and `.env` support, it provides a clean interface for common GitLab operations without the weight of a full-featured SDK.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install qodev-gitlab-api
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from qodev_gitlab_api import GitLabClient
|
|
15
|
+
|
|
16
|
+
# Reads GITLAB_TOKEN and GITLAB_URL from environment or .env file
|
|
17
|
+
client = GitLabClient()
|
|
18
|
+
|
|
19
|
+
# Or pass credentials explicitly
|
|
20
|
+
client = GitLabClient(token="glpat-xxxxxxxxxxxx", base_url="https://gitlab.example.com")
|
|
21
|
+
|
|
22
|
+
# Skip connection validation for faster startup
|
|
23
|
+
client = GitLabClient(validate=False)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Features
|
|
27
|
+
|
|
28
|
+
- **Merge requests** -- create, update, merge, close, and review with inline diff comments
|
|
29
|
+
- **Pipelines and jobs** -- list, inspect, wait for completion, retry, and download artifacts
|
|
30
|
+
- **Issues** -- create, update, close, and comment
|
|
31
|
+
- **Releases** -- create, update, delete, and list with asset links
|
|
32
|
+
- **CI/CD variables** -- get, list, create, update, and upsert (set) project variables
|
|
33
|
+
- **File operations** -- read repository files at any ref, upload files for markdown embedding
|
|
34
|
+
- **Automatic pagination** -- all list endpoints handle multi-page results transparently
|
|
35
|
+
- **Typed exceptions** -- `AuthenticationError`, `NotFoundError`, `APIError`, `ConfigurationError`
|
|
36
|
+
|
|
37
|
+
## Configuration
|
|
38
|
+
|
|
39
|
+
The client reads configuration from environment variables, with `.env` file support via `python-dotenv`:
|
|
40
|
+
|
|
41
|
+
| Variable | Description | Default |
|
|
42
|
+
|---|---|---|
|
|
43
|
+
| `GITLAB_TOKEN` | GitLab personal access token (required) | -- |
|
|
44
|
+
| `GITLAB_URL` | GitLab instance base URL | `https://gitlab.com` |
|
|
45
|
+
|
|
46
|
+
You can also use `GITLAB_BASE_URL` as an alias for `GITLAB_URL`.
|
|
47
|
+
|
|
48
|
+
Create a `.env` file in your project root:
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
GITLAB_TOKEN=glpat-xxxxxxxxxxxxxxxxxxxx
|
|
52
|
+
GITLAB_URL=https://gitlab.example.com
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## API Reference
|
|
56
|
+
|
|
57
|
+
### Projects
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
projects = client.get_projects(owned=True)
|
|
61
|
+
project = client.get_project("my-group/my-project")
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Merge Requests
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
# List and inspect
|
|
68
|
+
mrs = client.get_merge_requests("my-group/my-project", state="opened")
|
|
69
|
+
mr = client.get_merge_request("my-group/my-project", mr_iid=42)
|
|
70
|
+
changes = client.get_mr_changes("my-group/my-project", mr_iid=42)
|
|
71
|
+
commits = client.get_mr_commits("my-group/my-project", mr_iid=42)
|
|
72
|
+
approvals = client.get_mr_approvals("my-group/my-project", mr_iid=42)
|
|
73
|
+
|
|
74
|
+
# Create
|
|
75
|
+
mr = client.create_merge_request(
|
|
76
|
+
"my-group/my-project",
|
|
77
|
+
source_branch="feature/foo",
|
|
78
|
+
target_branch="main",
|
|
79
|
+
title="Add foo feature",
|
|
80
|
+
description="Implements the foo feature.",
|
|
81
|
+
assignee_ids=[123],
|
|
82
|
+
reviewer_ids=[456],
|
|
83
|
+
labels="enhancement",
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
# Update, merge, close
|
|
87
|
+
client.update_mr("my-group/my-project", mr_iid=42, title="Updated title")
|
|
88
|
+
client.merge_mr("my-group/my-project", mr_iid=42, squash=True)
|
|
89
|
+
client.close_mr("my-group/my-project", mr_iid=42)
|
|
90
|
+
|
|
91
|
+
# Discussions and comments
|
|
92
|
+
discussions = client.get_mr_discussions("my-group/my-project", mr_iid=42)
|
|
93
|
+
client.create_mr_note("my-group/my-project", mr_iid=42, body="Looks good!")
|
|
94
|
+
client.reply_to_discussion("my-group/my-project", mr_iid=42, discussion_id="abc123", body="Fixed.")
|
|
95
|
+
client.resolve_discussion("my-group/my-project", mr_iid=42, discussion_id="abc123", resolved=True)
|
|
96
|
+
|
|
97
|
+
# Inline diff comment
|
|
98
|
+
from qodev_gitlab_api import DiffPosition
|
|
99
|
+
|
|
100
|
+
client.create_mr_discussion(
|
|
101
|
+
"my-group/my-project",
|
|
102
|
+
mr_iid=42,
|
|
103
|
+
body="Consider renaming this variable.",
|
|
104
|
+
position=DiffPosition(file_path="src/main.py", new_line=15),
|
|
105
|
+
)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Pipelines and Jobs
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
pipelines = client.get_pipelines("my-group/my-project", ref="main")
|
|
112
|
+
pipeline = client.get_pipeline("my-group/my-project", pipeline_id=1001)
|
|
113
|
+
jobs = client.get_pipeline_jobs("my-group/my-project", pipeline_id=1001)
|
|
114
|
+
|
|
115
|
+
# Job details, logs, and artifacts
|
|
116
|
+
job = client.get_job("my-group/my-project", job_id=5001)
|
|
117
|
+
log = client.get_job_log("my-group/my-project", job_id=5001)
|
|
118
|
+
artifact = client.get_job_artifact("my-group/my-project", job_id=5001, artifact_path="report.xml")
|
|
119
|
+
|
|
120
|
+
# Retry a failed job
|
|
121
|
+
client.retry_job("my-group/my-project", job_id=5001)
|
|
122
|
+
|
|
123
|
+
# Wait for pipeline completion (blocks until done or timeout)
|
|
124
|
+
result = client.wait_for_pipeline("my-group/my-project", pipeline_id=1001, timeout_seconds=600)
|
|
125
|
+
print(result["final_status"]) # "success", "failed", "canceled", "skipped", or "timeout"
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Issues
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
issues = client.get_issues("my-group/my-project", state="opened", labels="bug")
|
|
132
|
+
issue = client.get_issue("my-group/my-project", issue_iid=10)
|
|
133
|
+
|
|
134
|
+
issue = client.create_issue(
|
|
135
|
+
"my-group/my-project",
|
|
136
|
+
title="Fix login bug",
|
|
137
|
+
description="Users cannot log in with SSO.",
|
|
138
|
+
labels="bug,urgent",
|
|
139
|
+
assignee_ids=[123],
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
client.update_issue("my-group/my-project", issue_iid=10, labels="bug,resolved")
|
|
143
|
+
client.close_issue("my-group/my-project", issue_iid=10)
|
|
144
|
+
|
|
145
|
+
# Comments
|
|
146
|
+
notes = client.get_issue_notes("my-group/my-project", issue_iid=10)
|
|
147
|
+
client.create_issue_note("my-group/my-project", issue_iid=10, body="Investigating this now.")
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Releases
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
releases = client.get_releases("my-group/my-project")
|
|
154
|
+
release = client.get_release("my-group/my-project", tag_name="v1.0.0")
|
|
155
|
+
|
|
156
|
+
release = client.create_release(
|
|
157
|
+
"my-group/my-project",
|
|
158
|
+
tag_name="v1.1.0",
|
|
159
|
+
name="Version 1.1.0",
|
|
160
|
+
description="## What's new\n- Feature A\n- Bug fix B",
|
|
161
|
+
ref="main",
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
client.update_release("my-group/my-project", tag_name="v1.1.0", description="Updated notes.")
|
|
165
|
+
client.delete_release("my-group/my-project", tag_name="v1.1.0")
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### CI/CD Variables
|
|
169
|
+
|
|
170
|
+
```python
|
|
171
|
+
variables = client.list_project_variables("my-group/my-project")
|
|
172
|
+
var = client.get_project_variable("my-group/my-project", key="API_KEY")
|
|
173
|
+
|
|
174
|
+
# Create or update (upsert)
|
|
175
|
+
var, action = client.set_project_variable(
|
|
176
|
+
"my-group/my-project",
|
|
177
|
+
key="API_KEY",
|
|
178
|
+
value="secret-value",
|
|
179
|
+
masked=True,
|
|
180
|
+
protected=True,
|
|
181
|
+
)
|
|
182
|
+
print(action) # "created" or "updated"
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### File Operations
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
# Read a file from the repository
|
|
189
|
+
content = client.get_file_content("my-group/my-project", file_path="README.md", ref="main")
|
|
190
|
+
|
|
191
|
+
# Upload a file (for embedding in issues/MRs)
|
|
192
|
+
from qodev_gitlab_api import FileFromPath
|
|
193
|
+
|
|
194
|
+
result = client.upload_file("my-group/my-project", source=FileFromPath(path="/tmp/screenshot.png"))
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## Error Handling
|
|
198
|
+
|
|
199
|
+
All API errors raise typed exceptions that inherit from `GitLabError`:
|
|
200
|
+
|
|
201
|
+
```python
|
|
202
|
+
from qodev_gitlab_api import GitLabClient, AuthenticationError, NotFoundError, APIError, ConfigurationError
|
|
203
|
+
|
|
204
|
+
try:
|
|
205
|
+
client = GitLabClient()
|
|
206
|
+
mr = client.get_merge_request("my-group/my-project", mr_iid=999)
|
|
207
|
+
except ConfigurationError:
|
|
208
|
+
print("Missing or invalid GITLAB_TOKEN / GITLAB_URL")
|
|
209
|
+
except AuthenticationError:
|
|
210
|
+
print("Token is invalid or expired")
|
|
211
|
+
except NotFoundError:
|
|
212
|
+
print("Merge request not found")
|
|
213
|
+
except APIError as e:
|
|
214
|
+
print(f"API error {e.status_code}: {e.response_body}")
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Requirements
|
|
218
|
+
|
|
219
|
+
- Python 3.11+
|
|
220
|
+
- [httpx](https://www.python-httpx.org/) >= 0.28.1
|
|
221
|
+
- [python-dotenv](https://github.com/theskumar/python-dotenv) >= 1.1.0
|
|
222
|
+
|
|
223
|
+
## License
|
|
224
|
+
|
|
225
|
+
MIT -- see [LICENSE](LICENSE) for details.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "qodev-gitlab-api"
|
|
3
|
-
version = "0.1
|
|
3
|
+
version = "0.2.1"
|
|
4
4
|
description = "Python client for the GitLab API"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
authors = [
|
|
@@ -25,6 +25,7 @@ dependencies = [
|
|
|
25
25
|
]
|
|
26
26
|
|
|
27
27
|
[project.urls]
|
|
28
|
+
Homepage = "https://github.com/qodevai/gitlab-api"
|
|
28
29
|
Repository = "https://github.com/qodevai/gitlab-api"
|
|
29
30
|
Issues = "https://github.com/qodevai/gitlab-api/issues"
|
|
30
31
|
|
qodev_gitlab_api-0.1.2/PKG-INFO
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: qodev-gitlab-api
|
|
3
|
-
Version: 0.1.2
|
|
4
|
-
Summary: Python client for the GitLab API
|
|
5
|
-
Project-URL: Repository, https://github.com/qodevai/gitlab-api
|
|
6
|
-
Project-URL: Issues, https://github.com/qodevai/gitlab-api/issues
|
|
7
|
-
Author-email: Jan Scheffler <jan.scheffler@qodev.ai>
|
|
8
|
-
License: MIT
|
|
9
|
-
Keywords: api,client,gitlab
|
|
10
|
-
Classifier: Development Status :: 4 - Beta
|
|
11
|
-
Classifier: Intended Audience :: Developers
|
|
12
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
-
Classifier: Programming Language :: Python :: 3
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
-
Classifier: Typing :: Typed
|
|
18
|
-
Requires-Python: >=3.11
|
|
19
|
-
Requires-Dist: httpx>=0.28.1
|
|
20
|
-
Requires-Dist: python-dotenv>=1.1.0
|
|
21
|
-
Provides-Extra: dev
|
|
22
|
-
Requires-Dist: mypy>=1.13.0; extra == 'dev'
|
|
23
|
-
Requires-Dist: pytest-cov>=4.1.0; extra == 'dev'
|
|
24
|
-
Requires-Dist: pytest-mock>=3.12.0; extra == 'dev'
|
|
25
|
-
Requires-Dist: pytest>=8.0.0; extra == 'dev'
|
|
26
|
-
Requires-Dist: ruff>=0.8.0; extra == 'dev'
|
|
27
|
-
Description-Content-Type: text/markdown
|
|
28
|
-
|
|
29
|
-
# qodev-gitlab-api
|
|
30
|
-
|
|
31
|
-
Python client for the GitLab API.
|
|
32
|
-
|
|
33
|
-
## Installation
|
|
34
|
-
|
|
35
|
-
```bash
|
|
36
|
-
pip install qodev-gitlab-api
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
## Usage
|
|
40
|
-
|
|
41
|
-
```python
|
|
42
|
-
from qodev_gitlab_api import GitLabClient
|
|
43
|
-
|
|
44
|
-
client = GitLabClient()
|
|
45
|
-
```
|
qodev_gitlab_api-0.1.2/README.md
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|