Skip to content

Commit d9b33c3

Browse files
Revert "feat: Ability to configure repo Collaborators (teams + users) (#232)" (#247)
This reverts commit 1bd6d38.
1 parent 1bd6d38 commit d9b33c3

File tree

8 files changed

+33
-391
lines changed

8 files changed

+33
-391
lines changed

examples/settings.yml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,6 @@
66
# You can run Action from each repo, acting on that repo's settings.yml, or
77
# from a central repo, using a single settings.yml to control many repos.
88

9-
# For users, it is the login id
10-
# For teams, it is the slug id
11-
# permission can be 'push','pull','triage','admin','maintain', or any custom role you have defined
12-
# for either users or teams, set exists to false to remove their permissions
13-
collaborators:
14-
# - name: andrewthetechie
15-
# type: user
16-
# permission: admin
17-
# exists: false
18-
# - name: <org>/<team>
19-
# type: team
20-
# permission: admin
21-
# exists: false
22-
239
# Which method you choose is up to you. See README.md for more info and example
2410
# Workflows to implement these strategies.
2511
settings:

repo_manager/gh/branch_protections.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
from copy import deepcopy
22
from typing import Any
33

4-
from actions_toolkit import core as actions_toolkit
5-
64
from github.Consts import mediaTypeRequireMultipleApprovingReviews
75
from github.GithubException import GithubException
86
from github.GithubObject import NotSet
@@ -311,12 +309,7 @@ def check_repo_branch_protections(
311309
diff_protections[config_bp.name] = ["Branch is not protected"]
312310
continue
313311

314-
try:
315-
this_protection = repo_bp.get_protection()
316-
except Exception as exc:
317-
actions_toolkit.info(f"Repo {repo.full_name} does not currently have any branch protections defined?")
318-
actions_toolkit.info(f"error: {exc}")
319-
continue
312+
this_protection = repo_bp.get_protection()
320313
if config_bp.protection.pr_options is not None:
321314
diffs.append(
322315
diff_option(

repo_manager/gh/collaborators.py

Lines changed: 0 additions & 199 deletions
This file was deleted.

repo_manager/gh/settings.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from typing import Any
22

3-
from actions_toolkit import core as actions_toolkit
4-
53
from github.Repository import Repository
64

75
from repo_manager.schemas.settings import Settings
@@ -68,21 +66,14 @@ def get_repo_value(setting_name: str, repo: Repository) -> Any | None:
6866
for setting_name in settings.dict().keys():
6967
repo_value = get_repo_value(setting_name, repo)
7068
settings_value = getattr(settings, setting_name)
71-
if setting_name in [
72-
"allow_squash_merge",
73-
"allow_merge_commit",
74-
"allow_rebase_merge",
75-
"delete_branch_on_merge",
76-
"enable_automated_security_fixes",
77-
"enable_vulnerability_alerts",
78-
]:
79-
if repo._requester.oauth_scopes is None:
80-
continue
81-
elif repo_value is None:
82-
actions_toolkit.info(f"Unable to access {setting_name} with OAUTH of {repo._requester.oauth_scopes}")
69+
# These don't seem to update if changed; may need to explore a different API call
70+
if (setting_name == "enable_automated_security_fixes") | (setting_name == "enable_vulnerability_alerts"):
71+
continue
8372
# We don't want to flag description being different if the YAML is None
84-
if settings_value is None:
73+
if (setting_name == "description") & (not settings_value):
8574
continue
75+
elif (setting_name == "topics") & (settings_value is None):
76+
settings_value = []
8677
if repo_value != settings_value:
8778
drift.append(f"{setting_name} -- Expected: '{settings_value}' Found: '{repo_value}'")
8879
checked &= False if (settings_value is not None) else True

repo_manager/main.py

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
from repo_manager.gh.secrets import check_repo_secrets
1515
from repo_manager.gh.secrets import create_secret
1616
from repo_manager.gh.secrets import delete_secret
17-
from repo_manager.gh.collaborators import check_collaborators
18-
from repo_manager.gh.collaborators import update_collaborators
1917
from repo_manager.gh.settings import check_repo_settings
2018
from repo_manager.gh.settings import update_settings
2119
from repo_manager.schemas import load_config
@@ -59,7 +57,6 @@ def main(): # noqa: C901
5957
"branch_protections",
6058
config.branch_protections,
6159
),
62-
check_collaborators: ("collaborators", config.collaborators),
6360
}.items():
6461
check_name, to_check = to_check
6562
if to_check is not None:
@@ -68,41 +65,18 @@ def main(): # noqa: C901
6865
if this_diffs is not None:
6966
diffs[check_name] = this_diffs
7067

71-
actions_toolkit.debug(json_diff := json.dumps(diffs))
68+
actions_toolkit.debug(json_diff := json.dumps({}))
7269
actions_toolkit.set_output("diff", json_diff)
7370

7471
if inputs["action"] == "check":
7572
if not check_result:
76-
actions_toolkit.info(inputs["repo_object"].full_name)
77-
actions_toolkit.info(json.dumps(diffs))
7873
actions_toolkit.set_output("result", "Check failed, diff detected")
7974
actions_toolkit.set_failed("Diff detected")
8075
actions_toolkit.set_output("result", "Check passed")
8176
sys.exit(0)
8277

8378
if inputs["action"] == "apply":
8479
errors = []
85-
for update, to_update in {
86-
# TODO: Implement these functions to reduce length and complexity of code
87-
# update_settings: ("settings", config.settings),
88-
# update_secrets: ("secrets", config.secrets),
89-
# check_repo_labels: ("labels", config.labels),
90-
# check_repo_branch_protections: (
91-
# "branch_protections",
92-
# config.branch_protections,
93-
# ),
94-
update_collaborators: ("collaborators", config.collaborators, diffs.get("collaborators", None)),
95-
}.items():
96-
update_name, to_update, categorical_diffs = to_update
97-
if categorical_diffs is not None:
98-
try:
99-
application_errors = update(inputs["repo_object"], to_update, categorical_diffs)
100-
if len(application_errors) > 0:
101-
errors.append(application_errors)
102-
else:
103-
actions_toolkit.info(f"Synced {update_name}")
104-
except Exception as exc:
105-
errors.append({"type": f"{update_name}-update", "error": f"{exc}"})
10680

10781
# Because we cannot diff secrets, just apply it every time
10882
if config.secrets is not None:

repo_manager/schemas/__init__.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
import yaml
2-
from pydantic import BaseModel, Field # pylint: disable=E0611
2+
from pydantic import BaseModel # pylint: disable=E0611
33

44
from .branch_protection import BranchProtection
55
from .file import FileConfig
66
from .label import Label
77
from .secret import Secret
88
from .settings import Settings
9-
from .collaborator import Collaborator
9+
from pydantic import Field
10+
from copy import copy
11+
12+
13+
def empty_list():
14+
this_list = list()
15+
return copy(this_list)
1016

1117

1218
class RepoManagerConfig(BaseModel):
1319
settings: Settings | None
14-
branch_protections: list[BranchProtection] | None = Field(
15-
None, description="Branch protections in the repo to manage"
16-
)
17-
secrets: list[Secret] | None = Field(None, description="Secrets in the repo to manage")
18-
labels: list[Label] | None = Field(None, description="Labels in the repo to manage")
19-
files: list[FileConfig] | None = Field(None, description="Files in the repo to manage")
20-
collaborators: list[Collaborator] | None = Field(None, description="Collaborators in the repo to manage")
20+
branch_protections: list[BranchProtection] = Field(default_factory=empty_list)
21+
secrets: list[Secret] = Field(default_factory=empty_list)
22+
labels: list[Label] = Field(default_factory=empty_list)
23+
files: list[FileConfig] = Field(default_factory=empty_list)
2124

2225
@property
2326
def secrets_dict(self):
@@ -35,14 +38,6 @@ def branch_protections_dict(self):
3538
else {}
3639
)
3740

38-
@property
39-
def collaborators_dict(self):
40-
return (
41-
{collaborator.name: collaborator for collaborator in self.collaborators}
42-
if self.collaborators is not None
43-
else {}
44-
)
45-
4641

4742
def load_config(filename: str) -> RepoManagerConfig:
4843
"""Loads a yaml file into a RepoManagerconfig"""

0 commit comments

Comments
 (0)