@@ -381,9 +381,10 @@ class Configuration(NamedTuple):
381
381
default_repo_settings : Repository
382
382
repos_by_id : Dict [int , Repository ]
383
383
repos_by_name : Dict [str , Repository ]
384
+ fname : Optional [str ]
384
385
385
386
@staticmethod
386
- def from_toml_dict (data : Dict [str , Any ]) -> Configuration :
387
+ def from_toml_dict (data : Dict [str , Any ], fname : Optional [ str ] ) -> Configuration :
387
388
org = Organization .from_toml_dict (data ["organization" ])
388
389
members = {OrganizationMember .from_toml_dict (m ) for m in data ["member" ]}
389
390
teams = {Team .from_toml_dict (m ) for m in data ["team" ]}
@@ -408,13 +409,14 @@ def from_toml_dict(data: Dict[str, Any]) -> Configuration:
408
409
default_repo_settings = default_repo_settings ,
409
410
repos_by_id = repos_by_id ,
410
411
repos_by_name = repos_by_name ,
412
+ fname = fname ,
411
413
)
412
414
413
415
@staticmethod
414
416
def from_toml_file (fname : str ) -> Configuration :
415
417
with open (fname , "rb" ) as f :
416
418
data = tomllib .load (f )
417
- return Configuration .from_toml_dict (data )
419
+ return Configuration .from_toml_dict (data , fname )
418
420
419
421
def get_repository_target (self , actual : Repository ) -> Repository :
420
422
"""
@@ -955,48 +957,55 @@ def print_team_members_diff(
955
957
return has_diff
956
958
957
959
958
- def has_changes (target : Configuration , client : GithubClient ) -> bool :
959
- has_changes = False
960
- org_name = target .organization .name
961
-
962
- actual_repos = set (client .get_organization_repositories (org_name ))
960
+ def diff_repos (target : Configuration , client : GithubClient ) -> bool :
961
+ actual_repos = set (client .get_organization_repositories (target .organization .name ))
963
962
target_repos = set (target .repos_by_id .values ()) | {
964
963
target .get_repository_target (r ) for r in actual_repos
965
964
}
966
965
repos_diff = Diff .new (target = target_repos , actual = actual_repos )
967
- has_changes |= repos_diff .print_diff (
968
- f"The following repositories are specified in { target_fname } but not present on GitHub:" ,
966
+
967
+ return repos_diff .print_diff (
968
+ f"The following repositories are specified in { target .fname } but not present on GitHub:" ,
969
969
# Even though we generate the targets form the actuals using the default
970
970
# settings, it can happen that we match on repository name but not id
971
971
# (when the id in the config file is wrong). Then the repo will be
972
972
# missing from the targets.
973
- f"The following repositories are not specified in { target_fname } but present on GitHub:" ,
974
- f"The following repositories on GitHub need to be changed to match { target_fname } :" ,
973
+ f"The following repositories are not specified in { target . fname } but present on GitHub:" ,
974
+ f"The following repositories on GitHub need to be changed to match { target . fname } :" ,
975
975
)
976
976
977
- current_org = client .get_organization (org_name )
978
- if current_org != target .organization :
979
- has_changes = True
977
+
978
+ def diff_org (target : Configuration , client : GithubClient ) -> bool :
979
+ current_org = client .get_organization (target .organization .name )
980
+ has_change = current_org != target .organization
981
+ if has_change :
980
982
print ("The organization-level settings need to be changed as follows:\n " )
981
983
print_simple_diff (
982
984
actual = current_org .format_toml (),
983
985
target = target .organization .format_toml (),
984
986
)
987
+ return has_change
988
+
985
989
986
- current_members = set (client .get_organization_members (org_name ))
990
+ def diff_members (target : Configuration , client : GithubClient ) -> bool :
991
+ current_members = set (client .get_organization_members (target .organization .name ))
987
992
members_diff = Diff .new (target = target .members , actual = current_members )
988
- has_changes |= members_diff .print_diff (
989
- f"The following members are specified in { target_fname } but not a member of the GitHub organization:" ,
990
- f"The following members are not specified in { target_fname } but are a member of the GitHub organization:" ,
991
- f"The following members on GitHub need to be changed to match { target_fname } :" ,
993
+ return members_diff .print_diff (
994
+ f"The following members are specified in { target . fname } but not a member of the GitHub organization:" ,
995
+ f"The following members are not specified in { target . fname } but are a member of the GitHub organization:" ,
996
+ f"The following members on GitHub need to be changed to match { target . fname } :" ,
992
997
)
993
998
994
- current_teams = set (client .get_organization_teams (org_name ))
999
+
1000
+ def diff_teams (target : Configuration , client : GithubClient ) -> bool :
1001
+ has_changes = False
1002
+
1003
+ current_teams = set (client .get_organization_teams (target .organization .name ))
995
1004
teams_diff = Diff .new (target = target .teams , actual = current_teams )
996
1005
has_changes |= teams_diff .print_diff (
997
- f"The following teams specified in { target_fname } are not present on GitHub:" ,
998
- f"The following teams are not specified in { target_fname } but are present on GitHub:" ,
999
- f"The following teams on GitHub need to be changed to match { target_fname } :" ,
1006
+ f"The following teams specified in { target . fname } are not present on GitHub:" ,
1007
+ f"The following teams are not specified in { target . fname } but are present on GitHub:" ,
1008
+ f"The following teams on GitHub need to be changed to match { target . fname } :" ,
1000
1009
)
1001
1010
1002
1011
# For all the teams which we want to exist, and which do actually exist,
@@ -1009,16 +1018,26 @@ def has_changes(target: Configuration, client: GithubClient) -> bool:
1009
1018
for team in existing_desired_teams :
1010
1019
has_changes |= print_team_members_diff (
1011
1020
team_name = team .name ,
1012
- target_fname = target_fname ,
1021
+ target_fname = target . fname ,
1013
1022
target_members = {
1014
1023
m for m in target .team_memberships if m .team_name == team .name
1015
1024
},
1016
- actual_members = set (client .get_team_members (org_name , team )),
1025
+ actual_members = set (client .get_team_members (target . organization . name , team )),
1017
1026
)
1018
1027
1019
1028
return has_changes
1020
1029
1021
1030
1031
+ def has_changes (target : Configuration , client : GithubClient ) -> bool :
1032
+ has_changes = False
1033
+ has_changes |= diff_repos (target , client )
1034
+ has_changes |= diff_org (target , client )
1035
+ has_changes |= diff_members (target , client )
1036
+ has_changes |= diff_teams (target , client )
1037
+
1038
+ return has_changes
1039
+
1040
+
1022
1041
def main () -> None :
1023
1042
if "--help" in sys .argv :
1024
1043
print (__doc__ )
0 commit comments