Skip to content

Commit

Permalink
Added support for latest fields in gitlab api.
Browse files Browse the repository at this point in the history
  • Loading branch information
Knucklessg1 committed Oct 21, 2024
1 parent f408412 commit cdc1f4b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
2 changes: 2 additions & 0 deletions gitlab_api/gitlab_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2147,11 +2147,13 @@ def get_nested_projects_by_group(
if project.group_id is None:
raise MissingParameterError
project_group = self.get_group(group_id=project.group_id)
print(f"\n\nPROJECT GROUP: {project_group}\n\n")
if project_group.data:
all_groups.append(project_group.data)
groups = self.get_group_descendant_groups(group_id=project.group_id)
if groups.data:
all_groups.extend(groups.data)
print(f"ALL GROUPS: {all_groups}")
for group in all_groups:
pages_response = self.get_total_projects_in_group(
group_id=project.group_id, per_page=project.per_page
Expand Down
9 changes: 8 additions & 1 deletion gitlab_api/gitlab_db_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ def __ne__(self, other):
BaseDBModel.metadata,
Column("project_id", Integer, ForeignKey("projects.id")),
Column("group_id", Integer, ForeignKey("groups.id")),
Column("id", Integer, primary_key=True, autoincrement=True)
Column("id", Integer, primary_key=True, autoincrement=True),
)


Expand Down Expand Up @@ -1805,6 +1805,13 @@ def __ne__(self, other):
operations_access_level: Mapped[str] = mapped_column(String, nullable=True)
ci_dockerfile: Mapped[str] = mapped_column(String, nullable=True)
public: Mapped[bool] = mapped_column(Boolean, nullable=True)
ci_id_token_sub_claim_components = mapped_column(ARRAY(String), nullable=True)
ci_pipeline_variables_minimum_override_role: Mapped[str] = mapped_column(
String, nullable=True
)
ci_push_repository_for_job_token_allowed: Mapped[bool] = mapped_column(
Boolean, nullable=True
)

tag_list_id: Mapped[int] = mapped_column(
Integer, ForeignKey(column="tags.id"), nullable=True
Expand Down
18 changes: 13 additions & 5 deletions gitlab_api/gitlab_response_models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/python
# coding: utf-8
import logging

from typing import Union, List, Dict, Optional, Any
from pydantic import (
Expand Down Expand Up @@ -1682,6 +1681,15 @@ class Meta:
public: Optional[bool] = Field(
default=None, description="Whether project is allowed to be public."
)
ci_id_token_sub_claim_components: Optional[List[str]] = Field(
default=None, description="CI ID Token Sub Claim Components"
)
ci_pipeline_variables_minimum_override_role: Optional[str] = Field(
default=None, description="CI Pipeline Variables minimum override role"
)
ci_push_repository_for_job_token_allowed: Optional[bool] = Field(
default=None, description="CI Push repository for Job token allowed"
)

@field_validator("tag_list", mode="before")
def validate_tags(cls, v):
Expand Down Expand Up @@ -3603,21 +3611,21 @@ def determine_model_type(cls, value):
model(**item) if isinstance(item, dict) else item
for item in value
]
logging.debug(f"{model_name} Validation Success: {temp_value}")
print(f"{model_name} Validation Success: {temp_value}")
return temp_value
except Exception as e:
logging.debug(
print(
f"\n\n\n {model_name} Validation Failed: {value}\nError: {e}"
)
return value
elif isinstance(value, dict):
for model_name, model in single_models.items():
try:
temp_value = model(**value)
logging.debug(f"{model_name} Model Validation Success: {value}")
print(f"{model_name} Model Validation Success: {value}")
return temp_value
except Exception as e:
logging.debug(
print(
f"\n\n\n {model_name} Dict Validation Failed for - {value}\nError: {e}"
)
return value
10 changes: 4 additions & 6 deletions test/test_gitlab_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@ def test_get_nested_projects():
# Get nested projects
group_id = 2
projects = client.get_nested_projects_by_group(group_id=group_id, per_page=3)
assert projects.data.base_type == "Projects"
assert isinstance(projects.data.projects, list)
assert len(projects.data.projects) > 3
assert len(projects.data) > 0
assert isinstance(projects.data, list)
group_id = 6
projects = client.get_nested_projects_by_group(group_id=group_id, per_page=3)
assert projects.data.base_type == "Projects"
assert isinstance(projects.data.projects, list)
assert len(projects.data.projects) > 3
assert len(projects.data) > 0
assert isinstance(projects.data, list)


@pytest.mark.skipif(
Expand Down

0 comments on commit cdc1f4b

Please sign in to comment.