clear-skies-gitlab 2.0.4__tar.gz → 2.0.5__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.
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/CHANGELOG.md +8 -0
- clear_skies_gitlab-2.0.5/LATEST_CHANGELOG.md +6 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/PKG-INFO +1 -1
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/pyproject.toml +1 -1
- clear_skies_gitlab-2.0.5/src/clearskies_gitlab/defaults/gitlab_default_auth.py +41 -0
- clear_skies_gitlab-2.0.5/src/clearskies_gitlab/defaults/gitlab_default_host.py +39 -0
- clear_skies_gitlab-2.0.5/src/clearskies_gitlab/rest/backends/gitlab_rest_backend.py +173 -0
- clear_skies_gitlab-2.0.5/src/clearskies_gitlab/rest/gitlab_branch_rule.py +94 -0
- clear_skies_gitlab-2.0.5/src/clearskies_gitlab/rest/gitlab_cicd_variable.py +97 -0
- clear_skies_gitlab-2.0.5/src/clearskies_gitlab/rest/gitlab_member.py +100 -0
- clear_skies_gitlab-2.0.5/src/clearskies_gitlab/rest/models/gitlab_rest_advanced_search.py +104 -0
- clear_skies_gitlab-2.0.5/src/clearskies_gitlab/rest/models/gitlab_rest_advanced_search_blob.py +94 -0
- clear_skies_gitlab-2.0.5/src/clearskies_gitlab/rest/models/gitlab_rest_current_user.py +179 -0
- clear_skies_gitlab-2.0.5/src/clearskies_gitlab/rest/models/gitlab_rest_group.py +107 -0
- clear_skies_gitlab-2.0.5/src/clearskies_gitlab/rest/models/gitlab_rest_group_access_token.py +135 -0
- clear_skies_gitlab-2.0.5/src/clearskies_gitlab/rest/models/gitlab_rest_group_base.py +408 -0
- clear_skies_gitlab-2.0.5/src/clearskies_gitlab/rest/models/gitlab_rest_group_member.py +92 -0
- clear_skies_gitlab-2.0.5/src/clearskies_gitlab/rest/models/gitlab_rest_group_project.py +42 -0
- clear_skies_gitlab-2.0.5/src/clearskies_gitlab/rest/models/gitlab_rest_group_search.py +49 -0
- clear_skies_gitlab-2.0.5/src/clearskies_gitlab/rest/models/gitlab_rest_group_search_blob.py +39 -0
- clear_skies_gitlab-2.0.5/src/clearskies_gitlab/rest/models/gitlab_rest_group_subgroup.py +100 -0
- clear_skies_gitlab-2.0.5/src/clearskies_gitlab/rest/models/gitlab_rest_group_variable.py +67 -0
- clear_skies_gitlab-2.0.5/src/clearskies_gitlab/rest/models/gitlab_rest_namespace.py +265 -0
- clear_skies_gitlab-2.0.5/src/clearskies_gitlab/rest/models/gitlab_rest_project.py +701 -0
- clear_skies_gitlab-2.0.5/src/clearskies_gitlab/rest/models/gitlab_rest_project_approval_config.py +105 -0
- clear_skies_gitlab-2.0.5/src/clearskies_gitlab/rest/models/gitlab_rest_project_approval_rule.py +133 -0
- clear_skies_gitlab-2.0.5/src/clearskies_gitlab/rest/models/gitlab_rest_project_member.py +90 -0
- clear_skies_gitlab-2.0.5/src/clearskies_gitlab/rest/models/gitlab_rest_project_protected_branch.py +166 -0
- clear_skies_gitlab-2.0.5/src/clearskies_gitlab/rest/models/gitlab_rest_project_repository_commit.py +196 -0
- clear_skies_gitlab-2.0.5/src/clearskies_gitlab/rest/models/gitlab_rest_project_repository_commit_diff.py +123 -0
- clear_skies_gitlab-2.0.5/src/clearskies_gitlab/rest/models/gitlab_rest_project_repository_contributor.py +100 -0
- clear_skies_gitlab-2.0.5/src/clearskies_gitlab/rest/models/gitlab_rest_project_repository_file.py +128 -0
- clear_skies_gitlab-2.0.5/src/clearskies_gitlab/rest/models/gitlab_rest_project_repository_file_raw.py +85 -0
- clear_skies_gitlab-2.0.5/src/clearskies_gitlab/rest/models/gitlab_rest_project_variable.py +71 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/uv.lock +380 -343
- clear_skies_gitlab-2.0.4/LATEST_CHANGELOG.md +0 -7
- clear_skies_gitlab-2.0.4/src/clearskies_gitlab/defaults/gitlab_default_auth.py +0 -10
- clear_skies_gitlab-2.0.4/src/clearskies_gitlab/defaults/gitlab_default_host.py +0 -10
- clear_skies_gitlab-2.0.4/src/clearskies_gitlab/rest/backends/gitlab_rest_backend.py +0 -155
- clear_skies_gitlab-2.0.4/src/clearskies_gitlab/rest/gitlab_branch_rule.py +0 -21
- clear_skies_gitlab-2.0.4/src/clearskies_gitlab/rest/gitlab_cicd_variable.py +0 -20
- clear_skies_gitlab-2.0.4/src/clearskies_gitlab/rest/gitlab_member.py +0 -21
- clear_skies_gitlab-2.0.4/src/clearskies_gitlab/rest/models/gitlab_rest_advanced_search.py +0 -38
- clear_skies_gitlab-2.0.4/src/clearskies_gitlab/rest/models/gitlab_rest_advanced_search_blob.py +0 -23
- clear_skies_gitlab-2.0.4/src/clearskies_gitlab/rest/models/gitlab_rest_current_user.py +0 -46
- clear_skies_gitlab-2.0.4/src/clearskies_gitlab/rest/models/gitlab_rest_group.py +0 -48
- clear_skies_gitlab-2.0.4/src/clearskies_gitlab/rest/models/gitlab_rest_group_access_token.py +0 -34
- clear_skies_gitlab-2.0.4/src/clearskies_gitlab/rest/models/gitlab_rest_group_base.py +0 -104
- clear_skies_gitlab-2.0.4/src/clearskies_gitlab/rest/models/gitlab_rest_group_member.py +0 -29
- clear_skies_gitlab-2.0.4/src/clearskies_gitlab/rest/models/gitlab_rest_group_project.py +0 -16
- clear_skies_gitlab-2.0.4/src/clearskies_gitlab/rest/models/gitlab_rest_group_search.py +0 -20
- clear_skies_gitlab-2.0.4/src/clearskies_gitlab/rest/models/gitlab_rest_group_search_blob.py +0 -13
- clear_skies_gitlab-2.0.4/src/clearskies_gitlab/rest/models/gitlab_rest_group_subgroup.py +0 -63
- clear_skies_gitlab-2.0.4/src/clearskies_gitlab/rest/models/gitlab_rest_group_variable.py +0 -24
- clear_skies_gitlab-2.0.4/src/clearskies_gitlab/rest/models/gitlab_rest_namespace.py +0 -88
- clear_skies_gitlab-2.0.4/src/clearskies_gitlab/rest/models/gitlab_rest_project.py +0 -203
- clear_skies_gitlab-2.0.4/src/clearskies_gitlab/rest/models/gitlab_rest_project_approval_config.py +0 -34
- clear_skies_gitlab-2.0.4/src/clearskies_gitlab/rest/models/gitlab_rest_project_approval_rule.py +0 -42
- clear_skies_gitlab-2.0.4/src/clearskies_gitlab/rest/models/gitlab_rest_project_member.py +0 -29
- clear_skies_gitlab-2.0.4/src/clearskies_gitlab/rest/models/gitlab_rest_project_protected_branch.py +0 -35
- clear_skies_gitlab-2.0.4/src/clearskies_gitlab/rest/models/gitlab_rest_project_repository_commit.py +0 -54
- clear_skies_gitlab-2.0.4/src/clearskies_gitlab/rest/models/gitlab_rest_project_repository_commit_diff.py +0 -36
- clear_skies_gitlab-2.0.4/src/clearskies_gitlab/rest/models/gitlab_rest_project_repository_contributor.py +0 -34
- clear_skies_gitlab-2.0.4/src/clearskies_gitlab/rest/models/gitlab_rest_project_repository_file.py +0 -39
- clear_skies_gitlab-2.0.4/src/clearskies_gitlab/rest/models/gitlab_rest_project_repository_file_raw.py +0 -31
- clear_skies_gitlab-2.0.4/src/clearskies_gitlab/rest/models/gitlab_rest_project_variable.py +0 -26
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/.copier-answers.yml +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/.editorconfig +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/.github/workflows/create-version.yaml +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/.github/workflows/docs.yaml +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/.github/workflows/run-tests.yml +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/.github/workflows/tests-matrix.yaml +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/.github/workflows/tests.yaml +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/.gitignore +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/.pre-commit-config.yaml +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/.python-version +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/.vscode/settings.json +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/LICENSE +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/README.md +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/cliff.toml +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/local.py +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/ruff.toml +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/src/clearskies_gitlab/__init__.py +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/src/clearskies_gitlab/defaults/__init__.py +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/src/clearskies_gitlab/defaults/gitlab_graphql_client.py +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/src/clearskies_gitlab/exceptions/__init__.py +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/src/clearskies_gitlab/exceptions/gitlab_error.py +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/src/clearskies_gitlab/graphql/__init__.py +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/src/clearskies_gitlab/graphql/backends/__init__.py +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/src/clearskies_gitlab/graphql/backends/gitlab_graphql_backend.py +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/src/clearskies_gitlab/graphql/models/__init__.py +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/src/clearskies_gitlab/graphql/models/gitlab_container_repository.py +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/src/clearskies_gitlab/graphql/models/gitlab_container_repository_reference.py +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/src/clearskies_gitlab/graphql/models/gitlab_container_repository_tag.py +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/src/clearskies_gitlab/graphql/models/gitlab_container_repository_tag_reference.py +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/src/clearskies_gitlab/graphql/models/gitlab_group.py +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/src/clearskies_gitlab/graphql/models/gitlab_group_reference.py +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/src/clearskies_gitlab/graphql/models/gitlab_project.py +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/src/clearskies_gitlab/graphql/models/gitlab_project_reference.py +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/src/clearskies_gitlab/rest/__init__.py +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/src/clearskies_gitlab/rest/backends/__init__.py +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/src/clearskies_gitlab/rest/models/__init__.py +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/src/clearskies_gitlab/rest/models/gitlab_rest_group_access_token_reference.py +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/src/clearskies_gitlab/rest/models/gitlab_rest_group_member_reference.py +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/src/clearskies_gitlab/rest/models/gitlab_rest_group_project_reference.py +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/src/clearskies_gitlab/rest/models/gitlab_rest_group_reference.py +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/src/clearskies_gitlab/rest/models/gitlab_rest_group_subgroup_reference.py +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/src/clearskies_gitlab/rest/models/gitlab_rest_group_variable_reference.py +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/src/clearskies_gitlab/rest/models/gitlab_rest_project_approval_config_reference.py +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/src/clearskies_gitlab/rest/models/gitlab_rest_project_approval_rule_reference.py +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/src/clearskies_gitlab/rest/models/gitlab_rest_project_member_reference.py +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/src/clearskies_gitlab/rest/models/gitlab_rest_project_protected_branch_reference.py +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/src/clearskies_gitlab/rest/models/gitlab_rest_project_reference.py +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/src/clearskies_gitlab/rest/models/gitlab_rest_project_repository_contributor_reference.py +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/src/clearskies_gitlab/rest/models/gitlab_rest_project_repository_file_reference.py +0 -0
- {clear_skies_gitlab-2.0.4 → clear_skies_gitlab-2.0.5}/src/clearskies_gitlab/rest/models/gitlab_rest_project_variable_reference.py +0 -0
|
@@ -5,9 +5,16 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [2.0.5] - 2026-01-28
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
- Update all classes to have documentation
|
|
12
|
+
- Update to latest dependencies
|
|
13
|
+
|
|
8
14
|
## [2.0.4] - 2026-01-26
|
|
9
15
|
|
|
10
16
|
### Changed
|
|
17
|
+
- Bump version to v2.0.4 by @github-actions[bot]
|
|
11
18
|
- Update to latest copier version
|
|
12
19
|
- Update to latest copier version
|
|
13
20
|
- Update to latest copier version
|
|
@@ -45,6 +52,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
45
52
|
## New Contributors
|
|
46
53
|
* @github-actions[bot] made their first contribution
|
|
47
54
|
* @ made their first contribution
|
|
55
|
+
[2.0.5]: https://github.com/clearskies-py/gitlab/compare/v2.0.4..v2.0.5
|
|
48
56
|
[2.0.4]: https://github.com/clearskies-py/gitlab/compare/v2.0.3..v2.0.4
|
|
49
57
|
[2.0.3]: https://github.com/clearskies-py/gitlab/compare/v2.0.2..v2.0.3
|
|
50
58
|
[2.0.2]: https://github.com/clearskies-py/gitlab/compare/v2.0.1..v2.0.2
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: clear-skies-gitlab
|
|
3
|
-
Version: 2.0.
|
|
3
|
+
Version: 2.0.5
|
|
4
4
|
Summary: Gitlab module for Clearskies
|
|
5
5
|
Project-URL: Docs, https://https://clearskies.info/modules/clear-skies-gitlab
|
|
6
6
|
Project-URL: Repository, https://github.com/clearskies-py/gitlab
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import clearskies
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class GitlabDefaultAuth(clearskies.di.AdditionalConfigAutoImport):
|
|
5
|
+
"""
|
|
6
|
+
Dependency injection provider for GitLab authentication.
|
|
7
|
+
|
|
8
|
+
This class automatically provides GitLab authentication credentials to the
|
|
9
|
+
dependency injection container. It reads the authentication token from the
|
|
10
|
+
`GITLAB_AUTH_KEY` environment variable and configures a Bearer token
|
|
11
|
+
authentication handler.
|
|
12
|
+
|
|
13
|
+
The authentication is used by the GitlabRestBackend to authenticate API
|
|
14
|
+
requests to GitLab.
|
|
15
|
+
|
|
16
|
+
```python
|
|
17
|
+
# Set environment variable with your GitLab personal access token
|
|
18
|
+
# export GITLAB_AUTH_KEY=glpat-xxxxxxxxxxxxxxxxxxxx
|
|
19
|
+
|
|
20
|
+
from clearskies_gitlab.rest.backends import GitlabRestBackend
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class MyModel(clearskies.Model):
|
|
24
|
+
backend = GitlabRestBackend()
|
|
25
|
+
# Will automatically use the configured authentication
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
The token should be a GitLab Personal Access Token (PAT) or Project/Group
|
|
29
|
+
Access Token with appropriate scopes for the API operations you need to perform.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
def provide_gitlab_auth(self, environment: clearskies.Environment):
|
|
33
|
+
"""
|
|
34
|
+
Provide the GitLab authentication handler from environment.
|
|
35
|
+
|
|
36
|
+
Reads the `GITLAB_AUTH_KEY` environment variable and returns a
|
|
37
|
+
SecretBearer authentication handler configured with the `Bearer ` prefix
|
|
38
|
+
as required by the GitLab API.
|
|
39
|
+
"""
|
|
40
|
+
secret_key = environment.get("GITLAB_AUTH_KEY", True)
|
|
41
|
+
return clearskies.authentication.SecretBearer(secret_key=secret_key, header_prefix="Bearer ")
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import clearskies
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class GitlabDefaultHost(clearskies.di.AdditionalConfigAutoImport):
|
|
5
|
+
"""
|
|
6
|
+
Dependency injection provider for the GitLab host URL.
|
|
7
|
+
|
|
8
|
+
This class automatically provides the GitLab host URL to the dependency
|
|
9
|
+
injection container. It reads the host from the `GITLAB_HOST` environment
|
|
10
|
+
variable, falling back to `https://gitlab.com/` if not set.
|
|
11
|
+
|
|
12
|
+
This is used by the GitlabRestBackend and other GitLab-related classes
|
|
13
|
+
to determine which GitLab instance to connect to.
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
# Set environment variable for self-hosted GitLab
|
|
17
|
+
# export GITLAB_HOST=https://gitlab.mycompany.com/
|
|
18
|
+
|
|
19
|
+
# Or use the default gitlab.com
|
|
20
|
+
# (no environment variable needed)
|
|
21
|
+
|
|
22
|
+
from clearskies_gitlab.rest.backends import GitlabRestBackend
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class MyModel(clearskies.Model):
|
|
26
|
+
backend = GitlabRestBackend()
|
|
27
|
+
# Will automatically use the configured host
|
|
28
|
+
```
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
def provide_gitlab_host(self, environment: clearskies.Environment):
|
|
32
|
+
"""
|
|
33
|
+
Provide the GitLab host URL from environment or default.
|
|
34
|
+
|
|
35
|
+
Reads the `GITLAB_HOST` environment variable. If not set or empty,
|
|
36
|
+
returns the default GitLab.com URL.
|
|
37
|
+
"""
|
|
38
|
+
gitlab_host = environment.get("GITLAB_HOST", True)
|
|
39
|
+
return gitlab_host if gitlab_host else "https://gitlab.com/"
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING, Any
|
|
4
|
+
from urllib import parse
|
|
5
|
+
|
|
6
|
+
from clearskies import configs
|
|
7
|
+
from clearskies.backends import ApiBackend
|
|
8
|
+
from clearskies.decorators import parameters_to_properties
|
|
9
|
+
from clearskies.di import inject
|
|
10
|
+
from clearskies.query import Query
|
|
11
|
+
from clearskies.query.result import CountQueryResult
|
|
12
|
+
from requests.structures import CaseInsensitiveDict
|
|
13
|
+
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from clearskies.authentication import Authentication
|
|
16
|
+
from clearskies.query import Query
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class GitlabRestBackend(ApiBackend):
|
|
20
|
+
"""
|
|
21
|
+
Backend for interacting with the GitLab REST API.
|
|
22
|
+
|
|
23
|
+
This backend extends the clearskies ApiBackend to provide GitLab-specific functionality
|
|
24
|
+
for making REST API calls to GitLab.com or self-hosted GitLab instances. It handles
|
|
25
|
+
authentication, pagination, and response mapping automatically.
|
|
26
|
+
|
|
27
|
+
The backend uses dependency injection to obtain the GitLab host URL and authentication
|
|
28
|
+
credentials, making it easy to configure for different environments.
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
import clearskies
|
|
32
|
+
from clearskies_gitlab.rest.backends import GitlabRestBackend
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class MyGitlabModel(clearskies.Model):
|
|
36
|
+
backend = GitlabRestBackend()
|
|
37
|
+
id_column_name = "id"
|
|
38
|
+
|
|
39
|
+
id = clearskies.columns.Integer()
|
|
40
|
+
name = clearskies.columns.String()
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The backend automatically constructs the base URL using the configured GitLab host
|
|
44
|
+
and appends `/api/v4` for the REST API version.
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
"""
|
|
48
|
+
Whether this backend supports count operations.
|
|
49
|
+
|
|
50
|
+
GitLab REST API supports counting via the `x-total` response header,
|
|
51
|
+
so this is set to True.
|
|
52
|
+
"""
|
|
53
|
+
can_count = True
|
|
54
|
+
|
|
55
|
+
"""
|
|
56
|
+
The GitLab host URL injected from the dependency container.
|
|
57
|
+
|
|
58
|
+
This is typically set via the `GITLAB_HOST` environment variable or through
|
|
59
|
+
explicit configuration. Defaults to `https://gitlab.com/` if not specified.
|
|
60
|
+
"""
|
|
61
|
+
gitlab_host = inject.ByName("gitlab_host", cache=True) # type: ignore[assignment]
|
|
62
|
+
|
|
63
|
+
"""
|
|
64
|
+
The authentication handler injected from the dependency container.
|
|
65
|
+
|
|
66
|
+
This is typically configured via the `GITLAB_AUTH_KEY` environment variable
|
|
67
|
+
which provides a bearer token for API authentication.
|
|
68
|
+
"""
|
|
69
|
+
authentication = inject.ByName("gitlab_auth", cache=False) # type: ignore[assignment]
|
|
70
|
+
|
|
71
|
+
"""
|
|
72
|
+
The requests handler for making HTTP calls.
|
|
73
|
+
"""
|
|
74
|
+
requests = inject.Requests()
|
|
75
|
+
|
|
76
|
+
_auth_headers: dict[str, str] = {}
|
|
77
|
+
|
|
78
|
+
"""
|
|
79
|
+
A mapping from API response field names to model field names.
|
|
80
|
+
|
|
81
|
+
Use this to handle cases where the GitLab API returns fields with different
|
|
82
|
+
names than your model expects.
|
|
83
|
+
"""
|
|
84
|
+
api_to_model_map = configs.AnyDict(default={})
|
|
85
|
+
|
|
86
|
+
"""
|
|
87
|
+
The name of the query parameter used for pagination.
|
|
88
|
+
|
|
89
|
+
GitLab uses `page` for page-based pagination.
|
|
90
|
+
"""
|
|
91
|
+
pagination_parameter_name = configs.String(default="page")
|
|
92
|
+
|
|
93
|
+
@parameters_to_properties
|
|
94
|
+
def __init__(
|
|
95
|
+
self,
|
|
96
|
+
base_url: str | None = None,
|
|
97
|
+
authentication: Authentication | None = None,
|
|
98
|
+
model_casing: str = "snake_case",
|
|
99
|
+
api_casing: str = "snake_case",
|
|
100
|
+
api_to_model_map: dict[str, str | list[str]] = {},
|
|
101
|
+
pagination_parameter_name: str = "page",
|
|
102
|
+
pagination_parameter_type: str = "str",
|
|
103
|
+
limit_parameter_name: str = "per_page",
|
|
104
|
+
):
|
|
105
|
+
self.finalize_and_validate_configuration()
|
|
106
|
+
|
|
107
|
+
@property
|
|
108
|
+
def base_url(self) -> str:
|
|
109
|
+
"""
|
|
110
|
+
Construct the base URL for GitLab API requests.
|
|
111
|
+
|
|
112
|
+
Combines the configured GitLab host with the API version path (`/api/v4`).
|
|
113
|
+
The host URL is automatically trimmed of trailing slashes to ensure
|
|
114
|
+
proper URL construction.
|
|
115
|
+
"""
|
|
116
|
+
return f"{self.gitlab_host.rstrip('/')}/api/v4"
|
|
117
|
+
|
|
118
|
+
def count_method(self, query: Query) -> str:
|
|
119
|
+
"""
|
|
120
|
+
Return the HTTP method to use when requesting a record count.
|
|
121
|
+
|
|
122
|
+
GitLab supports HEAD requests for efficient counting without
|
|
123
|
+
returning the full response body.
|
|
124
|
+
"""
|
|
125
|
+
return "HEAD"
|
|
126
|
+
|
|
127
|
+
def count(self, query: Query) -> CountQueryResult:
|
|
128
|
+
"""
|
|
129
|
+
Return the count of records matching the query.
|
|
130
|
+
|
|
131
|
+
Makes a HEAD request to the GitLab API and extracts the total count
|
|
132
|
+
from the `x-total` response header. Returns a CountQueryResult object
|
|
133
|
+
as required by the clearskies backend interface.
|
|
134
|
+
"""
|
|
135
|
+
self.check_query(query)
|
|
136
|
+
(url, method, body, headers) = self.build_records_request(query)
|
|
137
|
+
response = self.execute_request(url, self.count_method(query), json=body, headers=headers)
|
|
138
|
+
count = self._map_count_response(response.headers)
|
|
139
|
+
return CountQueryResult(count=count)
|
|
140
|
+
|
|
141
|
+
def _map_count_response(self, headers: CaseInsensitiveDict[str]) -> int:
|
|
142
|
+
"""Extract the total record count from GitLab response headers."""
|
|
143
|
+
return int(headers.get("x-total", 0))
|
|
144
|
+
|
|
145
|
+
def conditions_to_request_parameters(
|
|
146
|
+
self, query: Query, used_routing_parameters: list[str]
|
|
147
|
+
) -> tuple[str, dict[str, str], dict[str, Any]]:
|
|
148
|
+
"""
|
|
149
|
+
Convert query conditions to GitLab API request parameters.
|
|
150
|
+
|
|
151
|
+
Transforms clearskies query conditions into URL parameters suitable for
|
|
152
|
+
the GitLab REST API. Only equality conditions are supported; other operators
|
|
153
|
+
will raise a ValueError.
|
|
154
|
+
|
|
155
|
+
If a condition targets the model's ID column, it will be URL-encoded and
|
|
156
|
+
returned as the route_id for path-based lookups.
|
|
157
|
+
"""
|
|
158
|
+
route_id = ""
|
|
159
|
+
|
|
160
|
+
url_parameters = {}
|
|
161
|
+
for condition in query.conditions:
|
|
162
|
+
if condition.column_name in used_routing_parameters:
|
|
163
|
+
continue
|
|
164
|
+
if condition.operator != "=":
|
|
165
|
+
raise ValueError(
|
|
166
|
+
f"I'm not very smart and only know how to search with the equals operator, but I received a condition of {condition.parsed}. If you need to support this, you'll have to extend the ApiBackend and overwrite the build_records_request method."
|
|
167
|
+
)
|
|
168
|
+
if condition.column_name == query.model_class.id_column_name:
|
|
169
|
+
route_id = parse.quote_plus(condition.values[0]).replace("+", "%20")
|
|
170
|
+
continue
|
|
171
|
+
url_parameters[condition.column_name] = condition.values[0]
|
|
172
|
+
|
|
173
|
+
return (route_id, url_parameters, {})
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from clearskies import Model
|
|
4
|
+
from clearskies.columns import Boolean, Datetime, Integer, Json, String
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class GitlabBranchRule(Model):
|
|
8
|
+
"""
|
|
9
|
+
Model representing a GitLab branch protection rule.
|
|
10
|
+
|
|
11
|
+
Branch rules in GitLab define protection settings for branches, controlling
|
|
12
|
+
who can push, merge, and unprotect branches. This model maps to the GitLab
|
|
13
|
+
REST API response for protected branches.
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
from clearskies_gitlab.rest import GitlabBranchRule
|
|
17
|
+
from clearskies_gitlab.rest.backends import GitlabRestBackend
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class ProjectBranchRule(GitlabBranchRule):
|
|
21
|
+
backend = GitlabRestBackend()
|
|
22
|
+
table_name = "projects/{project_id}/protected_branches"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# Fetch all protected branches for a project
|
|
26
|
+
rules = ProjectBranchRule.where(project_id="my-project").all()
|
|
27
|
+
for rule in rules:
|
|
28
|
+
print(f"Branch: {rule.name}, Protected: {rule.protected}")
|
|
29
|
+
```
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
"""
|
|
33
|
+
The unique identifier for the branch rule.
|
|
34
|
+
"""
|
|
35
|
+
id = Integer()
|
|
36
|
+
|
|
37
|
+
"""
|
|
38
|
+
The name or pattern of the protected branch (e.g., `main`, `release/*`).
|
|
39
|
+
"""
|
|
40
|
+
name = String()
|
|
41
|
+
|
|
42
|
+
"""
|
|
43
|
+
Whether the branch is protected.
|
|
44
|
+
"""
|
|
45
|
+
protected = Boolean()
|
|
46
|
+
|
|
47
|
+
"""
|
|
48
|
+
Whether developers are allowed to push to the branch.
|
|
49
|
+
"""
|
|
50
|
+
developers_can_push = Boolean()
|
|
51
|
+
|
|
52
|
+
"""
|
|
53
|
+
Whether developers are allowed to merge into the branch.
|
|
54
|
+
"""
|
|
55
|
+
developers_can_merge = Boolean()
|
|
56
|
+
|
|
57
|
+
"""
|
|
58
|
+
Whether the current user can push to the branch.
|
|
59
|
+
"""
|
|
60
|
+
can_push = Boolean()
|
|
61
|
+
|
|
62
|
+
"""
|
|
63
|
+
Whether this is the default branch of the repository.
|
|
64
|
+
"""
|
|
65
|
+
default = Boolean()
|
|
66
|
+
|
|
67
|
+
"""
|
|
68
|
+
The timestamp when the branch rule was created.
|
|
69
|
+
"""
|
|
70
|
+
created_at = Datetime()
|
|
71
|
+
|
|
72
|
+
"""
|
|
73
|
+
The timestamp when the branch rule was last updated.
|
|
74
|
+
"""
|
|
75
|
+
updated_at = Datetime()
|
|
76
|
+
|
|
77
|
+
"""
|
|
78
|
+
Whether code owner approval is required for merges to this branch.
|
|
79
|
+
"""
|
|
80
|
+
code_owner_approval_required = Boolean()
|
|
81
|
+
|
|
82
|
+
"""
|
|
83
|
+
JSON array of access levels that can unprotect the branch.
|
|
84
|
+
|
|
85
|
+
Each entry contains information about who can remove protection from this branch.
|
|
86
|
+
"""
|
|
87
|
+
unprotect_access_levels = Json()
|
|
88
|
+
|
|
89
|
+
"""
|
|
90
|
+
JSON array of access levels that can push to the branch.
|
|
91
|
+
|
|
92
|
+
Each entry contains information about who can push directly to this branch.
|
|
93
|
+
"""
|
|
94
|
+
push_access_levels = Json()
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from clearskies import Model
|
|
4
|
+
from clearskies.columns import Boolean, String
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class GitlabCICDVariable(Model):
|
|
8
|
+
"""
|
|
9
|
+
Model representing a GitLab CI/CD variable.
|
|
10
|
+
|
|
11
|
+
CI/CD variables in GitLab are used to store values that can be used in
|
|
12
|
+
CI/CD pipelines. They can be defined at the project, group, or instance level.
|
|
13
|
+
This model maps to the GitLab REST API response for CI/CD variables.
|
|
14
|
+
|
|
15
|
+
Note that the `key` field is used as the unique identifier (`id_column_name`)
|
|
16
|
+
since GitLab identifies variables by their key name.
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
from clearskies_gitlab.rest import GitlabCICDVariable
|
|
20
|
+
from clearskies_gitlab.rest.backends import GitlabRestBackend
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class ProjectVariable(GitlabCICDVariable):
|
|
24
|
+
backend = GitlabRestBackend()
|
|
25
|
+
table_name = "projects/{project_id}/variables"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# Fetch all CI/CD variables for a project
|
|
29
|
+
variables = ProjectVariable.where(project_id="my-project").all()
|
|
30
|
+
for var in variables:
|
|
31
|
+
print(f"Key: {var.key}, Protected: {var.protected}")
|
|
32
|
+
```
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
id_column_name = "key"
|
|
36
|
+
|
|
37
|
+
"""
|
|
38
|
+
The name of the variable, used as the unique identifier.
|
|
39
|
+
"""
|
|
40
|
+
key = String()
|
|
41
|
+
|
|
42
|
+
"""
|
|
43
|
+
The value stored in the variable.
|
|
44
|
+
|
|
45
|
+
This may be masked in API responses if the `masked` flag is set.
|
|
46
|
+
"""
|
|
47
|
+
value = String()
|
|
48
|
+
|
|
49
|
+
"""
|
|
50
|
+
A human-readable description of the variable's purpose.
|
|
51
|
+
"""
|
|
52
|
+
description = String()
|
|
53
|
+
|
|
54
|
+
"""
|
|
55
|
+
The environment scope for the variable.
|
|
56
|
+
|
|
57
|
+
Determines which environments the variable is available in.
|
|
58
|
+
Use `*` for all environments or specify a specific environment name.
|
|
59
|
+
"""
|
|
60
|
+
environment_scope = String()
|
|
61
|
+
|
|
62
|
+
"""
|
|
63
|
+
The type of variable.
|
|
64
|
+
|
|
65
|
+
Can be `env_var` for environment variables or `file` for file-type variables.
|
|
66
|
+
"""
|
|
67
|
+
variable_type = String()
|
|
68
|
+
|
|
69
|
+
"""
|
|
70
|
+
Whether the variable value is masked in job logs.
|
|
71
|
+
|
|
72
|
+
When true, the variable value will be hidden in CI/CD job output.
|
|
73
|
+
"""
|
|
74
|
+
masked = Boolean()
|
|
75
|
+
|
|
76
|
+
"""
|
|
77
|
+
Whether the variable is only available in protected branches/tags.
|
|
78
|
+
|
|
79
|
+
When true, the variable is only exposed to pipelines running on
|
|
80
|
+
protected branches or tags.
|
|
81
|
+
"""
|
|
82
|
+
protected = Boolean()
|
|
83
|
+
|
|
84
|
+
"""
|
|
85
|
+
Whether the variable is hidden from the UI.
|
|
86
|
+
|
|
87
|
+
Hidden variables cannot be viewed or edited through the GitLab interface.
|
|
88
|
+
"""
|
|
89
|
+
hidden = Boolean()
|
|
90
|
+
|
|
91
|
+
"""
|
|
92
|
+
Whether the variable value should be treated as raw (no variable expansion).
|
|
93
|
+
|
|
94
|
+
When true, the variable value is used as-is without expanding any
|
|
95
|
+
embedded variable references.
|
|
96
|
+
"""
|
|
97
|
+
raw = Boolean()
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from clearskies import Model
|
|
4
|
+
from clearskies.columns import Datetime, Email, Integer, Json, String
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class GitlabMember(Model):
|
|
8
|
+
"""
|
|
9
|
+
Base model representing a GitLab group or project member.
|
|
10
|
+
|
|
11
|
+
Members in GitLab represent users who have been granted access to a group
|
|
12
|
+
or project with a specific access level. This model maps to the GitLab
|
|
13
|
+
REST API response for membership endpoints.
|
|
14
|
+
|
|
15
|
+
Access levels in GitLab are represented as integers:
|
|
16
|
+
- 10: Guest
|
|
17
|
+
- 20: Reporter
|
|
18
|
+
- 30: Developer
|
|
19
|
+
- 40: Maintainer
|
|
20
|
+
- 50: Owner
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from clearskies_gitlab.rest import GitlabMember
|
|
24
|
+
from clearskies_gitlab.rest.backends import GitlabRestBackend
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class ProjectMember(GitlabMember):
|
|
28
|
+
backend = GitlabRestBackend()
|
|
29
|
+
table_name = "projects/{project_id}/members"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
# Fetch all members of a project
|
|
33
|
+
members = ProjectMember.where(project_id="my-project").all()
|
|
34
|
+
for member in members:
|
|
35
|
+
print(f"User: {member.username}, Access Level: {member.access_level}")
|
|
36
|
+
```
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
id_column_name = "id"
|
|
40
|
+
|
|
41
|
+
"""
|
|
42
|
+
The unique identifier for the member (user ID).
|
|
43
|
+
"""
|
|
44
|
+
id = Integer()
|
|
45
|
+
|
|
46
|
+
"""
|
|
47
|
+
The username of the member.
|
|
48
|
+
"""
|
|
49
|
+
username = String()
|
|
50
|
+
|
|
51
|
+
"""
|
|
52
|
+
The display name of the member.
|
|
53
|
+
"""
|
|
54
|
+
name = String()
|
|
55
|
+
|
|
56
|
+
"""
|
|
57
|
+
The current state of the user account.
|
|
58
|
+
|
|
59
|
+
Common values include `active`, `blocked`, or `deactivated`.
|
|
60
|
+
"""
|
|
61
|
+
state = String()
|
|
62
|
+
|
|
63
|
+
"""
|
|
64
|
+
URL to the member's avatar image.
|
|
65
|
+
"""
|
|
66
|
+
avatar_url = String()
|
|
67
|
+
|
|
68
|
+
"""
|
|
69
|
+
The access level granted to the member.
|
|
70
|
+
|
|
71
|
+
Integer values correspond to GitLab access levels:
|
|
72
|
+
10 (Guest), 20 (Reporter), 30 (Developer), 40 (Maintainer), 50 (Owner).
|
|
73
|
+
"""
|
|
74
|
+
access_level = Integer()
|
|
75
|
+
|
|
76
|
+
"""
|
|
77
|
+
The timestamp when the member was added.
|
|
78
|
+
"""
|
|
79
|
+
created_at = Datetime()
|
|
80
|
+
|
|
81
|
+
"""
|
|
82
|
+
JSON object containing information about who added this member.
|
|
83
|
+
|
|
84
|
+
Includes details like the user ID and username of the person who
|
|
85
|
+
granted membership.
|
|
86
|
+
"""
|
|
87
|
+
created_by = Json()
|
|
88
|
+
|
|
89
|
+
"""
|
|
90
|
+
The email address of the member.
|
|
91
|
+
"""
|
|
92
|
+
email = Email()
|
|
93
|
+
|
|
94
|
+
"""
|
|
95
|
+
JSON object containing SAML identity information for the member.
|
|
96
|
+
|
|
97
|
+
Only populated when SAML SSO is configured for the group.
|
|
98
|
+
Contains the extern_uid and provider information.
|
|
99
|
+
"""
|
|
100
|
+
group_saml_identity = Json()
|