19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/github/pulse/cli.rb', line 19
def analyze(repo_path = ".")
token = options[:token] || ENV["GITHUB_TOKEN"]
analyzer = Analyzer.new(
repo_path: repo_path,
github_repo: options[:repo],
token: token,
since: options[:since],
until: options[:until],
small_threshold: options[:small_threshold],
medium_threshold: options[:medium_threshold]
)
puts "Analyzing repository activity..."
report = analyzer.analyze
output_file = options[:output]
if options[:format] == "html"
require_relative "html_reporter"
reporter = HtmlReporter.new(report)
output = reporter.generate
output_file = output_file.sub(/\.json$/, '.html') unless output_file.end_with?('.html')
else
reporter = Reporter.new(report)
output = reporter.generate(format: options[:format].to_sym)
end
File.write(output_file, output)
puts "Report saved to #{output_file}"
if options[:format] == "pretty"
puts "\n" + output
elsif options[:format] == "html"
puts "Open #{output_file} in your browser to view the interactive report"
case RUBY_PLATFORM
when /darwin/
system("open", output_file)
when /linux/
system("xdg-open", output_file)
when /win32|mingw/
system("start", output_file)
end
end
rescue StandardError => e
say "Error: #{e.message}", :red
exit 1
end
|