77from logger import logger
88from menus .menu_base import MenuBase
99from providers .github_handler import GithubHandler
10- from release_block_pr_config import ReleaseBlockPrConfig
10+ from release_block_pr_config import ReleaseBlockPrConfig , RepositoryConfig
1111
12- release_block = "Release Blocked PR's "
12+ release_block = "Release Blocked Pull Requests "
1313
1414
1515class ReleaseBlockPrMenu (MenuBase ):
@@ -20,11 +20,21 @@ class ReleaseBlockPrMenu(MenuBase):
2020 def handle (self , answers ):
2121 if answers .get ("provider" ) in self .handlers :
2222 handler_class = self .handlers [answers ["provider" ]]
23- repositories_to_unblock : List [ReleaseBlockPrConfig ] = pydantic .parse_file_as (List [ReleaseBlockPrConfig ],
24- answers ["config_file" ])
25- for tokens_to_repositories in repositories_to_unblock :
26- handler = handler_class (tokens_to_repositories .token )
27- for repository in tokens_to_repositories .repositories :
23+ release_block_pr_configs : List [ReleaseBlockPrConfig ] = pydantic .parse_file_as (List [ReleaseBlockPrConfig ],
24+ answers ["config_file" ])
25+ for release_block_pr_config in release_block_pr_configs :
26+ handler = handler_class (release_block_pr_config .token )
27+ repositories : List [RepositoryConfig ] = []
28+ if release_block_pr_config .repositories is not None :
29+ repositories .extend (release_block_pr_config .repositories )
30+
31+ # Get all organizations repositories
32+ organization_names = [organization .organization_name for organization
33+ in release_block_pr_config .organizations ]
34+ repositories .extend (handler .get_organizations_repositories (organization_names ))
35+
36+ # Release branch protection from all repositories
37+ for repository in repositories :
2838 handler .release_branch_protection (repository .organization_name , repository .repository_name ,
2939 repository .branch , answers ["contexts" ])
3040 else :
@@ -38,7 +48,10 @@ def validate_config_file(config_file):
3848 if not os .path .isfile (config_file ):
3949 return "File does not exist"
4050 try :
41- pydantic .parse_file_as (List [ReleaseBlockPrConfig ], config_file )
51+ parsed_configs = pydantic .parse_file_as (List [ReleaseBlockPrConfig ], config_file )
52+ for parsed_config in parsed_configs :
53+ if len (parsed_config .organizations ) == 0 and len (parsed_config .repositories ) == 0 :
54+ return f"Invalid input, need at least one repository or organization"
4255 except Exception as e :
4356 return f"Invalid input, not in the expected format { e } "
4457 return True
0 commit comments