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

Allow to ignore archived repositories #23

Merged
merged 1 commit into from
Jul 11, 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
16 changes: 13 additions & 3 deletions gh_org_mgr/_gh_org.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class GHorg: # pylint: disable=too-many-instance-attributes
current_teams: dict[Team.Team, dict] = field(default_factory=dict)
configured_teams: dict[str, dict | None] = field(default_factory=dict)
current_repos: dict[Repository.Repository, dict[Team.Team, str]] = field(default_factory=dict)
archived_repos: list[Repository.Repository] = field(default_factory=list)

# --------------------------------------------------------------------------
# Helper functions
Expand Down Expand Up @@ -307,9 +308,18 @@ def get_members_without_team(self) -> None:
# --------------------------------------------------------------------------
# Repos
# --------------------------------------------------------------------------
def _get_current_repos_and_perms(self) -> None:
def _get_current_repos_and_perms(self, ignore_archived: bool) -> None:
"""Get all repos, their current teams and their permissions"""
for repo in list(self.org.get_repos()):
# Check if repo is archived. If so, ignore it, if user requested so
if ignore_archived and repo.archived:
logging.debug(
"Ignoring %s as it is archived and user requested to ignore such repos",
repo.name,
)
self.archived_repos.append(repo)
continue

self.current_repos[repo] = {}
for team in list(repo.get_teams()):
self.current_repos[repo][team] = team.permission
Expand Down Expand Up @@ -349,12 +359,12 @@ def _create_perms_changelist_for_teams(

return team_changelist

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

# Get all repos and their current permissions from GitHub
self._get_current_repos_and_perms()
self._get_current_repos_and_perms(ignore_archived)

# Find differences between configured permissions for a team's repo and the current state
for team, repos in self._create_perms_changelist_for_teams().items():
Expand Down
8 changes: 7 additions & 1 deletion gh_org_mgr/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
)
parser.add_argument("--debug", action="store_true", help="Get verbose logging output")
parser.add_argument("--dry", action="store_true", help="Do not make any changes at GitHub")
parser.add_argument(
"-A",
"--ignore-archived",
action="store_true",
help="Do not take any action in ignored repositories",
)
parser.add_argument("--version", action="version", version="GitHub Team Manager " + __version__)


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

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