Skip to content

Commit

Permalink
[Gitlab] Fixed merge requests and issue resync methods to use an asyn…
Browse files Browse the repository at this point in the history
…c method of listing root groups (#917)
  • Loading branch information
Tankilevitch authored Aug 19, 2024
1 parent 654f554 commit 2790acb
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 17 deletions.
8 changes: 8 additions & 0 deletions integrations/gitlab/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

<!-- towncrier release notes start -->

0.1.107 (2024-08-19)
====================

### Bug Fixes

- Fixed merge requests and issue resync methods to use an async method of listing root groups to avoid blocking the event loop


0.1.106 (2024-08-19)
====================

Expand Down
19 changes: 19 additions & 0 deletions integrations/gitlab/gitlab_integration/gitlab_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,25 @@ async def get_all_groups(self) -> typing.AsyncIterator[List[Group]]:
)
yield groups

async def get_all_root_groups(self) -> typing.AsyncIterator[List[Group]]:
logger.info("fetching all root groups for the token")

def is_root_group(group: Group) -> bool:
return group.parent_id is None

async for groups_batch in AsyncFetcher.fetch_batch(
fetch_func=self.gitlab_client.groups.list,
validation_func=is_root_group,
pagination="offset",
order_by="id",
sort="asc",
):
groups: List[Group] = typing.cast(List[Group], groups_batch)
logger.info(
f"Queried {len(groups)} root groups {[group.path for group in groups]}"
)
yield groups

async def get_all_projects(self) -> typing.AsyncIterator[List[Project]]:
logger.info("fetching all projects for the token")
port_app_config: GitlabPortAppConfig = typing.cast(
Expand Down
28 changes: 18 additions & 10 deletions integrations/gitlab/gitlab_integration/ocean.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,21 +192,29 @@ async def resync_merge_requests(kind: str) -> ASYNC_GENERATOR_RESYNC_TYPE:
updated_after = datetime.now() - timedelta(days=14)

for service in get_cached_all_services():
for group in service.get_root_groups():
async for merge_request_batch in service.get_opened_merge_requests(group):
yield [merge_request.asdict() for merge_request in merge_request_batch]
async for merge_request_batch in service.get_closed_merge_requests(
group, updated_after
):
yield [merge_request.asdict() for merge_request in merge_request_batch]
async for groups_batch in service.get_all_root_groups():
for group in groups_batch:
async for merge_request_batch in service.get_opened_merge_requests(
group
):
yield [
merge_request.asdict() for merge_request in merge_request_batch
]
async for merge_request_batch in service.get_closed_merge_requests(
group, updated_after
):
yield [
merge_request.asdict() for merge_request in merge_request_batch
]


@ocean.on_resync(ObjectKind.ISSUE)
async def resync_issues(kind: str) -> ASYNC_GENERATOR_RESYNC_TYPE:
for service in get_cached_all_services():
for group in service.get_root_groups():
async for issues_batch in service.get_all_issues(group):
yield [issue.asdict() for issue in issues_batch]
async for groups_batch in service.get_all_root_groups():
for group in groups_batch:
async for issues_batch in service.get_all_issues(group):
yield [issue.asdict() for issue in issues_batch]


@ocean.on_resync(ObjectKind.JOB)
Expand Down
10 changes: 5 additions & 5 deletions integrations/gitlab/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions integrations/gitlab/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "gitlab"
version = "0.1.106"
version = "0.1.107"
description = "Gitlab integration for Port using Port-Ocean Framework"
authors = ["Yair Siman-Tov <[email protected]>"]

Expand All @@ -10,7 +10,7 @@ aiofiles = "^0.6.0"
python-gitlab = "^3.14.0"
pathlib = "^1.0.1"
jsonschema = "^4.17.3"
port_ocean = {version = "^0.9.13", extras = ["cli"]}
port_ocean = {version = "^0.9.14", extras = ["cli"]}

[tool.poetry.group.dev.dependencies]
pytest = "^7.2"
Expand Down

0 comments on commit 2790acb

Please sign in to comment.