Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Integration][GitLab] Fix few bugs #223

Merged
merged 8 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions integrations/gitlab/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

<!-- towncrier release notes start -->

0.1.26 (2023-11-07)
===================

### Bug Fixes

- Fixed a bug of not finding merge requests on hook event (#1)
Tankilevitch marked this conversation as resolved.
Show resolved Hide resolved
- Fixed a bug of sending binary data when `file://` is configured in `port.yml` (#2)
Tankilevitch marked this conversation as resolved.
Show resolved Hide resolved
- Fixed a bug of type validation that caused skipping merge requests on resync (#3)


0.1.25 (2023-11-03)
===================

Expand Down
4 changes: 2 additions & 2 deletions integrations/gitlab/gitlab_integration/core/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ def generate_entity_from_port_yaml(
gitlab_file = project.files.get(file_path=str(file_meta), ref=ref)

if file_meta.suffix == JSON_SUFFIX:
properties[key] = json.loads(gitlab_file.decode())
properties[key] = json.loads(gitlab_file.decode().decode("utf-8"))
else:
properties[key] = gitlab_file.decode()
properties[key] = gitlab_file.decode().decode("utf-8")
else:
properties[key] = value

Expand Down
11 changes: 1 addition & 10 deletions integrations/gitlab/gitlab_integration/core/paging.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,7 @@ async def fetch(
],
],
validation_func: Callable[
[
Union[
RESTObject,
ProjectPipelineJob,
Issue,
ProjectPipeline,
Dict[str, Any],
Project,
]
],
[Any],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you open a task on me to fix this typing?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure this is the correct typing though.

The paging shouldn't care what the validation function it gets; Each validation function should define whatever parameters it wants, Shouldn't it?

bool,
],
batch_size: int = int(os.environ.get("GITLAB_BATCH_SIZE", 100)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ async def _on_hook(
self, group_id: str, body: dict[str, Any], gitlab_project: Project
) -> None:
merge_requests = gitlab_project.mergerequests.get(
body["object_attributes"]["id"]
body["object_attributes"]["iid"]
)
await ocean.register_raw(ObjectKind.MERGE_REQUEST, [merge_requests.asdict()])
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ async def _on_hook(
{"before": entities_before, "after": entities_after},
UserAgentType.gitops,
)
return
Tankilevitch marked this conversation as resolved.
Show resolved Hide resolved
Tankilevitch marked this conversation as resolved.
Show resolved Hide resolved

await ocean.register_raw(ObjectKind.PROJECT, [gitlab_project.asdict()])
31 changes: 13 additions & 18 deletions integrations/gitlab/gitlab_integration/gitlab_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
Issue,
Group,
ProjectPipeline,
GroupMergeRequest,
ProjectPipelineJob,
)
from loguru import logger
Expand Down Expand Up @@ -124,33 +125,27 @@ def should_run_for_path(self, path: str) -> bool:

def should_run_for_project(
self,
project: typing.Union[RESTObject | dict[str, Any] | Project],
project: Project,
) -> bool:
if isinstance(project, Project):
return self.should_run_for_path(project.path_with_namespace)
return False
return self.should_run_for_path(project.path_with_namespace)

def should_run_for_merge_request(
self,
merge_request: typing.Union[RESTObject, dict[str, Any], Project, MergeRequest],
merge_request: typing.Union[MergeRequest, GroupMergeRequest],
) -> bool:
if type(merge_request) == MergeRequest:
project_path = merge_request.references.get("full").rstrip(
merge_request.references.get("short")
)
return self.should_run_for_path(project_path)
return False
project_path = merge_request.references.get("full").rstrip(
merge_request.references.get("short")
)
return self.should_run_for_path(project_path)

def should_run_for_issue(
self,
issue: typing.Union[RESTObject, dict[str, Any], Project, MergeRequest, Issue],
issue: Issue,
) -> bool:
if type(issue) == Issue:
project_path = issue.references.get("full").rstrip(
issue.references.get("short")
)
return self.should_run_for_path(project_path)
return False
project_path = issue.references.get("full").rstrip(
issue.references.get("short")
)
return self.should_run_for_path(project_path)

def get_root_groups(self) -> List[Group]:
groups = self.gitlab_client.groups.list(iterator=True)
Expand Down
2 changes: 1 addition & 1 deletion 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.25"
version = "0.1.26"
description = "Gitlab integration for Port using Port-Ocean Framework"
authors = ["Yair Siman-Tov <yair@getport.io>"]

Expand Down
Loading