Skip to content

Commit

Permalink
Resolve UserWarning Log
Browse files Browse the repository at this point in the history
  • Loading branch information
mk-armah committed Jan 16, 2025
1 parent 8de5565 commit 2581e68
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 3 additions & 1 deletion integrations/gitlab/gitlab_integration/core/async_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
User,
GroupMember,
ProjectFile,
ProjectLabel,
)
from loguru import logger

Expand Down Expand Up @@ -44,14 +45,14 @@ async def fetch_single(
],
*args,
) -> Union[
RESTObject,
RESTObject,
ProjectPipelineJob,
ProjectPipeline,
Issue,
Project,
Group,
ProjectFile,
ProjectLabel,
]:
with ThreadPoolExecutor() as executor:
return await get_event_loop().run_in_executor(executor, fetch_func, *args)
Expand Down Expand Up @@ -92,6 +93,7 @@ async def fetch_batch(
List[RESTObject],
List[Dict[str, Any]],
GitlabList,
List[ProjectLabel],
]
]:
def fetch_page(
Expand Down
13 changes: 10 additions & 3 deletions integrations/gitlab/gitlab_integration/gitlab_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
ProjectFile,
ProjectPipeline,
ProjectPipelineJob,
ProjectLabel,
Hook,
)
from gitlab_integration.core.async_fetcher import AsyncFetcher
Expand Down Expand Up @@ -550,9 +551,15 @@ async def get_all_projects(self) -> typing.AsyncIterator[List[Project]]:
@classmethod
async def async_project_labels_wrapper(cls, project: Project) -> dict[str, Any]:
try:
labels = await anyio.to_thread.run_sync(project.labels.list)
serialized_labels = [label.attributes for label in labels]
return {"__labels": serialized_labels}
all_labels = [
label.attributes
async for labels_batch in AsyncFetcher.fetch_batch(
fetch_func=project.labels.list
)
for label in typing.cast(List[ProjectLabel], labels_batch)
]

return {"__labels": all_labels}
except Exception as e:
logger.warning(
f"Failed to get labels for project={project.path_with_namespace}. error={e}"
Expand Down

0 comments on commit 2581e68

Please sign in to comment.