Skip to content

Commit

Permalink
Revert "feat: Ability to configure repo Collaborators (teams + users) (
Browse files Browse the repository at this point in the history
…#232)" (#247)

This reverts commit 1bd6d38.
  • Loading branch information
andrewthetechie authored Jun 2, 2024
1 parent 1bd6d38 commit d9b33c3
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 391 deletions.
14 changes: 0 additions & 14 deletions examples/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,6 @@
# You can run Action from each repo, acting on that repo's settings.yml, or
# from a central repo, using a single settings.yml to control many repos.

# For users, it is the login id
# For teams, it is the slug id
# permission can be 'push','pull','triage','admin','maintain', or any custom role you have defined
# for either users or teams, set exists to false to remove their permissions
collaborators:
# - name: andrewthetechie
# type: user
# permission: admin
# exists: false
# - name: <org>/<team>
# type: team
# permission: admin
# exists: false

# Which method you choose is up to you. See README.md for more info and example
# Workflows to implement these strategies.
settings:
Expand Down
9 changes: 1 addition & 8 deletions repo_manager/gh/branch_protections.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from copy import deepcopy
from typing import Any

from actions_toolkit import core as actions_toolkit

from github.Consts import mediaTypeRequireMultipleApprovingReviews
from github.GithubException import GithubException
from github.GithubObject import NotSet
Expand Down Expand Up @@ -311,12 +309,7 @@ def check_repo_branch_protections(
diff_protections[config_bp.name] = ["Branch is not protected"]
continue

try:
this_protection = repo_bp.get_protection()
except Exception as exc:
actions_toolkit.info(f"Repo {repo.full_name} does not currently have any branch protections defined?")
actions_toolkit.info(f"error: {exc}")
continue
this_protection = repo_bp.get_protection()
if config_bp.protection.pr_options is not None:
diffs.append(
diff_option(
Expand Down
199 changes: 0 additions & 199 deletions repo_manager/gh/collaborators.py

This file was deleted.

21 changes: 6 additions & 15 deletions repo_manager/gh/settings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from typing import Any

from actions_toolkit import core as actions_toolkit

from github.Repository import Repository

from repo_manager.schemas.settings import Settings
Expand Down Expand Up @@ -68,21 +66,14 @@ def get_repo_value(setting_name: str, repo: Repository) -> Any | None:
for setting_name in settings.dict().keys():
repo_value = get_repo_value(setting_name, repo)
settings_value = getattr(settings, setting_name)
if setting_name in [
"allow_squash_merge",
"allow_merge_commit",
"allow_rebase_merge",
"delete_branch_on_merge",
"enable_automated_security_fixes",
"enable_vulnerability_alerts",
]:
if repo._requester.oauth_scopes is None:
continue
elif repo_value is None:
actions_toolkit.info(f"Unable to access {setting_name} with OAUTH of {repo._requester.oauth_scopes}")
# These don't seem to update if changed; may need to explore a different API call
if (setting_name == "enable_automated_security_fixes") | (setting_name == "enable_vulnerability_alerts"):
continue
# We don't want to flag description being different if the YAML is None
if settings_value is None:
if (setting_name == "description") & (not settings_value):
continue
elif (setting_name == "topics") & (settings_value is None):
settings_value = []
if repo_value != settings_value:
drift.append(f"{setting_name} -- Expected: '{settings_value}' Found: '{repo_value}'")
checked &= False if (settings_value is not None) else True
Expand Down
28 changes: 1 addition & 27 deletions repo_manager/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
from repo_manager.gh.secrets import check_repo_secrets
from repo_manager.gh.secrets import create_secret
from repo_manager.gh.secrets import delete_secret
from repo_manager.gh.collaborators import check_collaborators
from repo_manager.gh.collaborators import update_collaborators
from repo_manager.gh.settings import check_repo_settings
from repo_manager.gh.settings import update_settings
from repo_manager.schemas import load_config
Expand Down Expand Up @@ -59,7 +57,6 @@ def main(): # noqa: C901
"branch_protections",
config.branch_protections,
),
check_collaborators: ("collaborators", config.collaborators),
}.items():
check_name, to_check = to_check
if to_check is not None:
Expand All @@ -68,41 +65,18 @@ def main(): # noqa: C901
if this_diffs is not None:
diffs[check_name] = this_diffs

actions_toolkit.debug(json_diff := json.dumps(diffs))
actions_toolkit.debug(json_diff := json.dumps({}))
actions_toolkit.set_output("diff", json_diff)

if inputs["action"] == "check":
if not check_result:
actions_toolkit.info(inputs["repo_object"].full_name)
actions_toolkit.info(json.dumps(diffs))
actions_toolkit.set_output("result", "Check failed, diff detected")
actions_toolkit.set_failed("Diff detected")
actions_toolkit.set_output("result", "Check passed")
sys.exit(0)

if inputs["action"] == "apply":
errors = []
for update, to_update in {
# TODO: Implement these functions to reduce length and complexity of code
# update_settings: ("settings", config.settings),
# update_secrets: ("secrets", config.secrets),
# check_repo_labels: ("labels", config.labels),
# check_repo_branch_protections: (
# "branch_protections",
# config.branch_protections,
# ),
update_collaborators: ("collaborators", config.collaborators, diffs.get("collaborators", None)),
}.items():
update_name, to_update, categorical_diffs = to_update
if categorical_diffs is not None:
try:
application_errors = update(inputs["repo_object"], to_update, categorical_diffs)
if len(application_errors) > 0:
errors.append(application_errors)
else:
actions_toolkit.info(f"Synced {update_name}")
except Exception as exc:
errors.append({"type": f"{update_name}-update", "error": f"{exc}"})

# Because we cannot diff secrets, just apply it every time
if config.secrets is not None:
Expand Down
29 changes: 12 additions & 17 deletions repo_manager/schemas/__init__.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
import yaml
from pydantic import BaseModel, Field # pylint: disable=E0611
from pydantic import BaseModel # pylint: disable=E0611

from .branch_protection import BranchProtection
from .file import FileConfig
from .label import Label
from .secret import Secret
from .settings import Settings
from .collaborator import Collaborator
from pydantic import Field
from copy import copy


def empty_list():
this_list = list()
return copy(this_list)


class RepoManagerConfig(BaseModel):
settings: Settings | None
branch_protections: list[BranchProtection] | None = Field(
None, description="Branch protections in the repo to manage"
)
secrets: list[Secret] | None = Field(None, description="Secrets in the repo to manage")
labels: list[Label] | None = Field(None, description="Labels in the repo to manage")
files: list[FileConfig] | None = Field(None, description="Files in the repo to manage")
collaborators: list[Collaborator] | None = Field(None, description="Collaborators in the repo to manage")
branch_protections: list[BranchProtection] = Field(default_factory=empty_list)
secrets: list[Secret] = Field(default_factory=empty_list)
labels: list[Label] = Field(default_factory=empty_list)
files: list[FileConfig] = Field(default_factory=empty_list)

@property
def secrets_dict(self):
Expand All @@ -35,14 +38,6 @@ def branch_protections_dict(self):
else {}
)

@property
def collaborators_dict(self):
return (
{collaborator.name: collaborator for collaborator in self.collaborators}
if self.collaborators is not None
else {}
)


def load_config(filename: str) -> RepoManagerConfig:
"""Loads a yaml file into a RepoManagerconfig"""
Expand Down
Loading

0 comments on commit d9b33c3

Please sign in to comment.