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

various improvements #323

Merged
merged 4 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 24.4.0
rev: 24.4.2
hooks:
- id: black
23 changes: 18 additions & 5 deletions gazu/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def get_last_events(
after=None,
before=None,
only_files=False,
name=None,
client=default,
):
"""
Expand All @@ -46,6 +47,8 @@ def get_last_events(
params["after"] = validate_date_format(after)
if before is not None:
params["before"] = validate_date_format(before)
if name is not None:
params["name"] = name
return raw.get(path, params=params, client=client)


Expand Down Expand Up @@ -102,11 +105,13 @@ def get_model_list_diff(source_list, target_list, id_field="id"):
source_ids = {m[id_field]: True for m in source_list}
target_ids = {m[id_field]: True for m in target_list}
missing = [
model for model in source_list
model
for model in source_list
if not target_ids.get(model[id_field], False)
]
unexpected = [
model for model in target_list
model
for model in target_list
if not source_ids.get(model[id_field], False)
]
return (missing, unexpected)
Expand Down Expand Up @@ -452,7 +457,6 @@ def push_tasks(

default_status_id = normalize_model_parameter(default_status)["id"]
task_type_map = get_sync_task_type_id_map(client_source, client_target)
task_status_map = get_sync_task_status_id_map(client_source, client_target)
person_map = get_sync_person_id_map(client_source, client_target)

tasks = task_module.all_tasks_for_project(
Expand Down Expand Up @@ -530,7 +534,13 @@ def push_task_comments(


def push_task_comment(
task_status_map, person_map, task, comment, client_source, client_target
task_status_map,
person_map,
task,
comment,
client_source,
client_target,
author_id=None,
):
"""
Create a new comment into target api for each comment in source task
Expand Down Expand Up @@ -588,7 +598,10 @@ def push_task_comment(
)

task_status = {"id": task_status_map[comment["task_status_id"]]}
author_id = person_map[comment["person_id"]]
if author_id is not None:
author_id = author_id
else:
author_id = person_map[comment["person_id"]]
person = {"id": author_id}

comment_target = task_module.add_comment(
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ test =
requests_mock

lint =
black==24.4.0; python_version >= '3.8'
black==24.4.2; python_version >= '3.8'
pre-commit==3.7.0; python_version >= '3.9'

[bdist_wheel]
Expand Down
32 changes: 17 additions & 15 deletions tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,30 @@ def test_get_model_list_diff(self):
]
target_list = [
{"id": "asset-2", "name": "Asset 2"},
{"id": "asset-4", "name": "Asset 4"}
{"id": "asset-4", "name": "Asset 4"},
]
missing, unexpected = gazu.sync.get_model_list_diff(
source_list, target_list
)
self.assertEqual(missing, [
{"id": "asset-1", "name": "Asset 1"},
{"id": "asset-3", "name": "Asset 3"}
])
self.assertEqual(unexpected, [
{"id": "asset-4", "name": "Asset 4"}
])
self.assertEqual(
missing,
[
{"id": "asset-1", "name": "Asset 1"},
{"id": "asset-3", "name": "Asset 3"},
],
)
self.assertEqual(unexpected, [{"id": "asset-4", "name": "Asset 4"}])
missing, unexpected = gazu.sync.get_model_list_diff(
source_list, target_list, id_field="name"
)
self.assertEqual(missing, [
{"id": "asset-1", "name": "Asset 1"},
{"id": "asset-3", "name": "Asset 3"}
])
self.assertEqual(unexpected, [
{"id": "asset-4", "name": "Asset 4"}
])
self.assertEqual(
missing,
[
{"id": "asset-1", "name": "Asset 1"},
{"id": "asset-3", "name": "Asset 3"},
],
)
self.assertEqual(unexpected, [{"id": "asset-4", "name": "Asset 4"}])
source_list = []
target_list = []
(missing, unexpected) = gazu.sync.get_model_list_diff(
Expand Down
Loading