Class: JiraMetrics

Inherits:
Thor
  • Object
show all
Defined in:
lib/jirametrics.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/jirametrics.rb', line 11

def self.exit_on_failure?
  true
end

.log_uncaught_exception(exception, file_system: nil) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/jirametrics.rb', line 104

def self.log_uncaught_exception exception, file_system: nil
  return unless exception && !exception.is_a?(SystemExit)

  begin
    file_system ||= Exporter.instance.file_system
    return if file_system.logfile == $stdout

    file_system.logfile.puts "#{exception.class}: #{exception.message}"
    exception.backtrace&.each { |line| file_system.logfile.puts "\t#{line}" }
  rescue StandardError
    # Exporter may not be initialized, or the logfile may already be closed
  end
end

Instance Method Details

#__print_versionObject



18
19
20
# File 'lib/jirametrics.rb', line 18

def __print_version
  puts Gem.loaded_specs['jirametrics'].version
end

#downloadObject



33
34
35
36
# File 'lib/jirametrics.rb', line 33

def download
  load_config options[:config]
  Exporter.instance.download(name_filter: options[:name] || '*')
end

#exportObject



25
26
27
28
# File 'lib/jirametrics.rb', line 25

def export
  load_config options[:config]
  Exporter.instance.export(name_filter: options[:name] || '*')
end

#goObject



41
42
43
44
45
46
47
# File 'lib/jirametrics.rb', line 41

def go
  load_config options[:config]
  Exporter.instance.download(name_filter: options[:name] || '*')

  load_config options[:config]
  Exporter.instance.export(name_filter: options[:name] || '*')
end

#info(key) ⇒ Object



51
52
53
54
# File 'lib/jirametrics.rb', line 51

def info key
  load_config options[:config]
  Exporter.instance.info(key, name_filter: options[:name] || '*')
end

#mcpObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/jirametrics.rb', line 59

def mcp
  # Redirect stdout to stderr for the entire startup phase so that any
  # incidental output (from config files, gem loading, etc.) does not
  # corrupt the JSON-RPC channel before the MCP transport takes over.
  original_stdout = $stdout.dup
  $stdout.reopen($stderr)

  load_config options[:config]
  require 'jirametrics/mcp_server'

  Exporter.instance.file_system.log_only = true

  projects = {}
  aggregates = {}
  Exporter.instance.each_project_config(name_filter: options[:name] || '*') do |project|
    project.evaluate_next_level
    project.run load_only: true
    projects[project.name || 'default'] = {
      issues: project.issues,
      today: project.time_range.end.to_date,
      end_time: project.time_range.end
    }
  rescue StandardError => e
    if e.message.start_with? 'This is an aggregated project'
      names = project.aggregate_project_names
      aggregates[project.name] = names if names.any?
      next
    end
    next if e.message.start_with? 'No data found'

    raise
  end

  $stdout.reopen(original_stdout)
  original_stdout.close
  McpServer.new(projects: projects, aggregates: aggregates, timezone_offset: Exporter.instance.timezone_offset).run
end

#stitch(stitch_file = 'stitcher.erb') ⇒ Object



99
100
101
102
# File 'lib/jirametrics.rb', line 99

def stitch stitch_file = 'stitcher.erb'
  load_config options[:config]
  Exporter.instance.stitch stitch_file
end