@@ -78,6 +78,14 @@ def run_cmd!(args, cwd: nil, echo: true, retries: 0)
7878 raise
7979end
8080
81+ def output ( fh , msg )
82+ if fh
83+ fh . write ( "#{ msg } \n " )
84+ else
85+ log . info ( msg )
86+ end
87+ end
88+
8189# Command-line options
8290options = {
8391 skip_patterns : %w{ adhoc release } ,
@@ -121,6 +129,12 @@ def run_cmd!(args, cwd: nil, echo: true, retries: 0)
121129 "GitHub org name. [default: #{ options [ :org ] } ]" ,
122130 ) { |v | options [ :org ] = v }
123131
132+ opts . on (
133+ '-o FILE' ,
134+ '--output FILE' ,
135+ 'Write the output to FILE' ,
136+ ) { |v | options [ :output ] = v }
137+
124138 opts . on (
125139 '--repos REPO' ,
126140 Array ,
@@ -159,13 +173,19 @@ def run_cmd!(args, cwd: nil, echo: true, retries: 0)
159173options [ :repos ] . uniq!
160174options [ :make_prs_for ] . uniq!
161175
176+ if options [ :output ]
177+ fh = open ( options [ :output ] , 'w' )
178+ log . info ( "Generating report and writing to #{ options [ :output ] } " )
179+ end
180+
162181github_token = get_github_token! ( options )
163182
164183total_pipeline_count = 0
165184private_pipeline_count = 0
166185repos_with_private = 0
167186skipped_by_pattern = Hash . new ( 0 )
168187
188+ output ( fh , "Pipeline Visibility Report #{ Date . today } \n " )
169189if options [ :repos ] . empty?
170190 log . info ( "Fetching repos under '#{ options [ :org ] } '..." )
171191 page = 1
@@ -197,6 +217,8 @@ def run_cmd!(args, cwd: nil, echo: true, retries: 0)
197217 next
198218 end
199219
220+ print ( '.' ) if fh
221+
200222 content = get_expeditor_config ( options [ :org ] , repo , github_token )
201223 unless content
202224 log . debug ( "No expeditor config for #{ repo } " )
@@ -247,9 +269,9 @@ def run_cmd!(args, cwd: nil, echo: true, retries: 0)
247269 end
248270
249271 next if repo_missing_public . empty?
250- log . info ( "* #{ repo } " )
272+ output ( fh , "* #{ repo } " )
251273 repo_missing_public . each do |pname |
252- log . info ( " * #{ pname } " )
274+ output ( fh , " * #{ pname } " )
253275 end
254276 repos_with_private += 1
255277
@@ -302,18 +324,22 @@ def run_cmd!(args, cwd: nil, echo: true, retries: 0)
302324 percentage_private = (
303325 ( private_pipeline_count . to_f / total_pipeline_count . to_f ) * 100
304326 ) . round ( 2 )
305- log . info ( "\n Total percentage of private pipelines: #{ percentage_private } %" )
306- log . info (
327+ output ( fh , "\n Total percentage of private pipelines: #{ percentage_private } %" )
328+ output (
329+ fh ,
307330 " --> #{ private_pipeline_count } out of #{ total_pipeline_count } " +
308331 "across #{ repos_with_private } repos" ,
309332 )
310333
311334 if skipped_by_pattern . any?
312- log . info ( ' --> Skipped pipelines:' )
335+ output ( fh , ' --> Skipped pipelines:' )
313336 skipped_by_pattern . each do |pattern , count |
314- log . info ( " - #{ pattern } : #{ count } " )
337+ output ( fh , " - #{ pattern } : #{ count } " )
315338 end
316339 end
317340else
318- log . info ( 'No pipelines found (excluding skipped patterns).' )
341+ output ( fh , 'No pipelines found (excluding skipped patterns).' )
319342end
343+
344+ puts if fh
345+ fh . close if options [ :output ]
0 commit comments