Skip to content

Commit 3685595

Browse files
fix: updated changelog, added example for team_permissions, added patch
1 parent 3cf249a commit 3685595

4 files changed

Lines changed: 24 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Added
66

7+
- Add team_permissions support to repository ([#623](https://github.com/eclipse-csi/otterdog/pull/612))
78
- Add tests for workflow validation settings ([#633](https://github.com/eclipse-csi/otterdog/pull/633))
89
- Add support for `OTTERDOG_CONFIG_ROOT` environment variable ([#632](https://github.com/eclipse-csi/otterdog/pull/632))
910

examples/template/otterdog-defaults.libsonnet

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ local newRepo(name) = {
109109
branch_protection_rules: [],
110110

111111
# rulesets
112-
rulesets: []
112+
rulesets: [],
113+
114+
# team permissions
115+
team_permissions: {},
113116
};
114117

115118
# Function to extend an existing repo with the same name.

otterdog/models/github_organization.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
from otterdog.models.repo_workflow_settings import RepositoryWorkflowSettings
4747
from otterdog.models.repository import Repository
4848
from otterdog.models.team import Team
49-
from otterdog.utils import IndentingPrinter, associate_by_key, debug_times, jsonnet_evaluate_file
49+
from otterdog.utils import IndentingPrinter, associate_by_key, debug_times, is_set_and_present, jsonnet_evaluate_file
5050

5151
if TYPE_CHECKING:
5252
from collections.abc import AsyncIterator, Callable, Iterator
@@ -672,7 +672,7 @@ async def _process_single_repo(
672672
repo_name: str,
673673
jsonnet_config: JsonnetConfig,
674674
teams: dict[str, Any],
675-
repo_permissions: dict[str, list[dict[str, Any]]],
675+
repo_permissions: dict[str, list[dict[str, Any]]] | None,
676676
app_installations: dict[str, str],
677677
) -> tuple[str, Repository]:
678678
rest_api = gh_client.rest_api
@@ -683,8 +683,11 @@ async def _process_single_repo(
683683

684684
github_repo_workflow_data = await rest_api.repo.get_workflow_settings(github_id, repo_name)
685685
repo.workflows = RepositoryWorkflowSettings.from_provider_data(github_id, github_repo_workflow_data)
686-
repo_permission = repo_permissions.get(repo_name, [])
687-
repo.set_team_permissions({entry["name"]: entry["permission"] for entry in repo_permission})
686+
if repo_permissions is not None:
687+
repo_permission = repo_permissions.get(repo_name, [])
688+
repo.set_team_permissions({entry["name"]: entry["permission"] for entry in repo_permission})
689+
else:
690+
repo.unset_team_permissions()
688691

689692
if jsonnet_config.default_branch_protection_rule_config is not None:
690693
# get branch protection rules of the repo
@@ -803,7 +806,12 @@ async def _load_repos_from_provider(
803806
repo_names = fnmatch.filter(repo_names, repo_filter)
804807

805808
teams = {str(team["id"]): f"{github_id}/{team['slug']}" for team in await provider.get_org_teams(github_id)}
806-
repo_permissions = build_repo_permissions(await provider.get_team_permissions(github_id))
809+
810+
default_org_repo = Repository.from_model_data(jsonnet_config.default_repo_config)
811+
if is_set_and_present(default_org_repo.team_permissions):
812+
repo_permissions = build_repo_permissions(await provider.get_team_permissions(github_id))
813+
else:
814+
repo_permissions = None
807815

808816
# limit the number of repos that are processed concurrently to avoid hitting secondary rate limits
809817
sem = asyncio.Semaphore(50 if concurrency is None else concurrency)

otterdog/models/repository.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
UNSET,
2929
Change,
3030
IndentingPrinter,
31+
_Unset,
3132
associate_by_key,
3233
is_set_and_present,
3334
is_set_and_valid,
@@ -107,7 +108,7 @@ class Repository(ModelObject):
107108
fork_default_branch_only: bool = dataclasses.field(metadata={"model_only": True})
108109

109110
workflows: RepositoryWorkflowSettings = dataclasses.field(metadata={"embedded_model": True})
110-
team_permissions: dict[str, str] | None
111+
team_permissions: dict[str, str] | None | _Unset
111112

112113
# model only fields
113114
aliases: list[str] = dataclasses.field(metadata={"model_only": True}, default_factory=list)
@@ -264,6 +265,9 @@ def set_team_permissions(self, permissions: dict[str, str]) -> None:
264265
team: self._valid_team_permissions.get(perm, perm) for team, perm in permissions.items()
265266
}
266267

268+
def unset_team_permissions(self) -> None:
269+
self.team_permissions = UNSET
270+
267271
def coerce_from_org_settings(self, org_settings: OrganizationSettings, for_patch: bool = False) -> Repository:
268272
copy = dataclasses.replace(self)
269273

@@ -473,7 +477,7 @@ def validate(self, context: ValidationContext, parent_object: Any) -> None:
473477
f"{self.get_model_header()} defines an unknown custom property with key '{k}'.",
474478
)
475479

476-
if is_set_and_present(self.team_permissions):
480+
if is_set_and_present(self.team_permissions) and isinstance(self.team_permissions, dict):
477481
for k, v in self.team_permissions.items():
478482
if v not in self._valid_team_permissions:
479483
context.add_failure(

0 commit comments

Comments
 (0)