Skip to content

Commit

Permalink
[#130] Apply repo workflow settings when creating a new repo.
Browse files Browse the repository at this point in the history
  • Loading branch information
netomi committed Oct 20, 2023
1 parent d30b44f commit f55f138
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

### Fixed

- Apply repository workflow settings when creating a new repository. ([#130](https://gitlab.eclipse.org/eclipsefdn/security/otterdog/-/issues/130))
- Added validation for the maximum number of supported `topics` defined for a repository. ([#129](https://gitlab.eclipse.org/eclipsefdn/security/otterdog/-/issues/129))
- Prevent `sync-template` operation to fail in some cases due to cached responses. ([#125](https://gitlab.eclipse.org/eclipsefdn/security/otterdog/-/issues/125))
- Made creating of repositories from a template more resilient to errors. ([#124](https://gitlab.eclipse.org/eclipsefdn/security/otterdog/-/issues/124))
Expand Down
24 changes: 20 additions & 4 deletions otterdog/models/repo_workflow_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ def generate_live_patch(
handler: LivePatchHandler,
) -> None:
assert isinstance(expected_object, RepositoryWorkflowSettings)

if current_object is None:
handler(LivePatch.of_addition(expected_object, parent_object, expected_object.apply_live_patch))
return

assert isinstance(current_object, RepositoryWorkflowSettings)

modified_workflow_settings: dict[str, Change[Any]] = expected_object.get_difference_from(current_object)
Expand All @@ -109,7 +114,18 @@ def apply_live_patch(cls, patch: LivePatch, org_id: str, provider: GitHubProvide
from .repository import Repository

assert isinstance(patch.parent_object, Repository)
assert patch.patch_type == LivePatchType.CHANGE
assert patch.changes is not None
github_settings = cls.changes_to_provider(org_id, patch.changes, provider)
provider.update_repo_workflow_settings(org_id, patch.parent_object.name, github_settings)

match patch.patch_type:
case LivePatchType.ADD:
assert isinstance(patch.expected_object, RepositoryWorkflowSettings)
provider.update_repo_workflow_settings(
org_id, patch.parent_object.name, patch.expected_object.to_provider_data(org_id, provider)
)

case LivePatchType.CHANGE:
assert patch.changes is not None
github_settings = cls.changes_to_provider(org_id, patch.changes, provider)
provider.update_repo_workflow_settings(org_id, patch.parent_object.name, github_settings)

case _:
raise RuntimeError(f"unexpected patch type '{patch.patch_type}'")
8 changes: 6 additions & 2 deletions otterdog/models/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,9 +679,13 @@ def generate_live_patch(

parent_repo = expected_object if current_object is None else current_object

if is_set_and_valid(expected_object.workflows) and current_object is not None:
if is_set_and_valid(expected_object.workflows):
RepositoryWorkflowSettings.generate_live_patch(
expected_object.workflows, current_object.workflows, parent_repo, context, handler
expected_object.workflows,
current_object.workflows if current_object is not None else None,
parent_repo,
context,
handler,
)

RepositoryWebhook.generate_live_patch_of_list(
Expand Down

0 comments on commit f55f138

Please sign in to comment.