55from typing import Optional , List , Set , Dict , Union , Any
66
77import click
8+ import coloredlogs
89import yaml
910from github import Github , Workflow
11+ from github .Organization import Organization
12+ from github .PaginatedList import PaginatedList
1013
11- logging .basicConfig (level = logging .WARNING )
12- logging .getLogger ('github.Requester' ).setLevel (logging .WARNING )
14+ from gha_cli .scanner import Org , print_orgs_as_csvs
15+
16+ coloredlogs .install (level = 'INFO' )
1317logger = logging .getLogger ()
1418
1519ActionVersion = namedtuple ('ActionVersion' , ['name' , 'current' , 'latest' ])
@@ -186,6 +190,8 @@ def _get_workflow_file_content(self, repo_name: str, workflow_path: str) -> Unio
186190
187191
188192@click .group (invoke_without_command = True )
193+ @click .option ('-v' , '--verbose' , count = True ,
194+ help = "Increase verbosity, can be used multiple times to increase verbosity" )
189195@click .option (
190196 '--repo' , default = '.' , show_default = True , type = str ,
191197 help = 'Repository to analyze, can be a local directory or a {OWNER}/{REPO} format' , )
@@ -196,7 +202,11 @@ def _get_workflow_file_content(self, repo_name: str, workflow_path: str) -> Unio
196202 '--compare-exact-versions' , is_flag = True , default = False ,
197203 help = "Compare versions using all semantic and not only major versions, e.g., v1 will be upgraded to v1.2.3" , )
198204@click .pass_context
199- def cli (ctx , repo : str , github_token : Optional [str ], compare_exact_versions : bool ):
205+ def cli (ctx , verbose : int , repo : str , github_token : Optional [str ], compare_exact_versions : bool ):
206+ if verbose == 1 :
207+ coloredlogs .install (level = 'INFO' )
208+ if verbose > 1 :
209+ coloredlogs .install (level = 'DEBUG' )
200210 ctx .ensure_object (dict )
201211 global FLAG_COMPARE_EXACT_VERSION
202212 FLAG_COMPARE_EXACT_VERSION = compare_exact_versions
@@ -259,5 +269,24 @@ def list_workflows(ctx):
259269 click .echo (f'{ path } - { name } ' )
260270
261271
272+ @cli .command (help = 'Analyze organizations' )
273+ @click .option ('-x' , '--exclude' , multiple = True , default = [], help = 'Exclude orgs' )
274+ @click .pass_context
275+ def analyze_orgs (ctx , exclude : Set [str ] = None ):
276+ gh_client : Github = ctx .obj ['gh' ].client
277+ exclude = exclude or {}
278+ exclude = set (exclude )
279+ current_user = gh_client .get_user ()
280+ gh_orgs : PaginatedList [Organization ] = current_user .get_orgs ()
281+ logging .info (f'Analyzing { gh_orgs .totalCount } organizations' )
282+ orgs : List [Org ] = []
283+ for gh_org in gh_orgs :
284+ if gh_org .login in exclude :
285+ continue
286+ org = Org .from_github_org (gh_org )
287+ orgs .append (org )
288+ print_orgs_as_csvs (orgs )
289+
290+
262291if __name__ == '__main__' :
263292 cli (obj = {})
0 commit comments