Skip to content

Commit a663b1f

Browse files
committed
allow to ignore archived repositories from checking permissions
1 parent 1b13a61 commit a663b1f

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

gh_org_mgr/_gh_org.py

+16-6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class GHorg: # pylint: disable=too-many-instance-attributes
3030
current_teams: dict[Team.Team, dict] = field(default_factory=dict)
3131
configured_teams: dict[str, dict | None] = field(default_factory=dict)
3232
current_repos: dict[Repository.Repository, dict[Team.Team, str]] = field(default_factory=dict)
33+
archived_repos: list[Repository.Repository] = field(default_factory=list)
3334

3435
# --------------------------------------------------------------------------
3536
# Helper functions
@@ -307,12 +308,21 @@ def get_members_without_team(self) -> None:
307308
# --------------------------------------------------------------------------
308309
# Repos
309310
# --------------------------------------------------------------------------
310-
def _get_current_repos_and_perms(self) -> None:
311+
def _get_current_repos_and_perms(self, ignore_archived: bool) -> None:
311312
"""Get all repos, their current teams and their permissions"""
312313
for repo in list(self.org.get_repos()):
313-
self.current_repos[repo] = {}
314-
for team in list(repo.get_teams()):
315-
self.current_repos[repo][team] = team.permission
314+
# Check if repo is archived. If so, ignore it, if user requested so
315+
if ignore_archived and repo.archived:
316+
logging.debug(
317+
"Ignoring %s as it is archived and user requested to ignore such repos",
318+
repo.name,
319+
)
320+
self.archived_repos.append(repo)
321+
continue
322+
else:
323+
self.current_repos[repo] = {}
324+
for team in list(repo.get_teams()):
325+
self.current_repos[repo][team] = team.permission
316326

317327
def _create_perms_changelist_for_teams(
318328
self,
@@ -349,12 +359,12 @@ def _create_perms_changelist_for_teams(
349359

350360
return team_changelist
351361

352-
def sync_repo_permissions(self, dry: bool = False) -> None:
362+
def sync_repo_permissions(self, dry: bool = False, ignore_archived: bool = False) -> None:
353363
"""Synchronise the repository permissions of all teams"""
354364
logging.debug("Starting to sync repo/team permissions")
355365

356366
# Get all repos and their current permissions from GitHub
357-
self._get_current_repos_and_perms()
367+
self._get_current_repos_and_perms(ignore_archived)
358368

359369
# Find differences between configured permissions for a team's repo and the current state
360370
for team, repos in self._create_perms_changelist_for_teams().items():

gh_org_mgr/manage.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
)
2424
parser.add_argument("--debug", action="store_true", help="Get verbose logging output")
2525
parser.add_argument("--dry", action="store_true", help="Do not make any changes at GitHub")
26+
parser.add_argument(
27+
"-A",
28+
"--ignore-archived",
29+
action="store_true",
30+
help="Do not take any action in ignored repositories",
31+
)
2632
parser.add_argument("--version", action="version", version="GitHub Team Manager " + __version__)
2733

2834

@@ -59,7 +65,7 @@ def main():
5965
# Report about organisation members that do not belong to any team
6066
org.get_members_without_team()
6167
# Synchronise the permissions of teams for all repositories
62-
org.sync_repo_permissions(dry=args.dry)
68+
org.sync_repo_permissions(dry=args.dry, ignore_archived=args.ignore_archived)
6369

6470
# Debug output
6571
logging.debug("Final dataclass:\n%s", org.df2json())

0 commit comments

Comments
 (0)