Class: HtmlReportConfig

Inherits:
HtmlGenerator show all
Includes:
SelfOrIssueDispatcher
Defined in:
lib/jirametrics/html_report_config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from HtmlGenerator

#create_html, #load_css

Constructor Details

#initialize(file_config:, block:) ⇒ HtmlReportConfig

Returns a new instance of HtmlReportConfig.



11
12
13
14
15
16
17
# File 'lib/jirametrics/html_report_config.rb', line 11

def initialize file_config:, block:
  super()
  @file_config = file_config
  @block = block
  @sections = [] # Where we store the chunks of text that will be assembled into the HTML
  @charts = [] # Where we store all the charts we executed so we can assert against them.
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *_args, board_id: nil, **_kwargs, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/jirametrics/html_report_config.rb', line 19

def method_missing name, *_args, board_id: nil, **_kwargs, &block
  class_name = name.to_s.split('_').map(&:capitalize).join
  klass = resolve_chart_class(class_name)
  return super if klass.nil?

  block ||= ->(_) {}

  if klass.instance_method(:board_id=).owner == klass
    execute_chart_per_board klass: klass, block: block, board_id: board_id
  else
    execute_chart klass.new(block)
  end
end

Instance Attribute Details

#chartsObject (readonly)

Returns the value of attribute charts.



9
10
11
# File 'lib/jirametrics/html_report_config.rb', line 9

def charts
  @charts
end

#file_configObject (readonly)

Returns the value of attribute file_config.



9
10
11
# File 'lib/jirametrics/html_report_config.rb', line 9

def file_config
  @file_config
end

#sectionsObject (readonly)

Returns the value of attribute sections.



9
10
11
# File 'lib/jirametrics/html_report_config.rb', line 9

def sections
  @sections
end

Instance Method Details

#board_id(id) ⇒ Object



101
102
103
# File 'lib/jirametrics/html_report_config.rb', line 101

def board_id id
  @board_id = id
end

#board_ids(board_id) ⇒ Object

The boards to draw this chart for, sorted by name: just the requested one, or every board the issues touch.



52
53
54
55
56
# File 'lib/jirametrics/html_report_config.rb', line 52

def board_ids board_id
  all_boards = @file_config.project_config.all_boards
  ids = board_id ? [board_id] : issues.collect { |issue| issue.board.id }.uniq
  ids.sort_by { |id| all_boards[id]&.name || '' }
end

#boardsObject

For use by the user config



176
177
178
# File 'lib/jirametrics/html_report_config.rb', line 176

def boards
  @file_config.project_config.board_configs.collect(&:id).collect { |id| find_board id }
end


180
181
182
183
184
185
186
187
188
189
190
# File 'lib/jirametrics/html_report_config.rb', line 180

def create_footer now: DateTime.now
  now = now.new_offset(timezone_offset)
  version = Gem.loaded_specs['jirametrics']&.version || 'Next'

  <<~HTML
    <section id="footer">
      Report generated on <b>#{now.strftime('%Y-%b-%d')}</b> at <b>#{now.strftime('%I:%M:%S%P %Z')}</b>
      with <a href="https://jirametrics.org">JiraMetrics</a> <b>v#{version}</b>
    </section>
  HTML
end

#cycletime(label = nil, &block) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/jirametrics/html_report_config.rb', line 63

def cycletime label = nil, &block
  @file_config.project_config.all_boards.each_value do |board|
    raise 'Multiple cycletimes not supported' if board.cycletime

    board.cycletime = CycleTimeConfig.new(
      possible_statuses: file_config.project_config, label: label, block: block,
      file_system: file_system, settings: settings
    )
  end
end

#dependency_chart(&block) ⇒ Object



127
128
129
# File 'lib/jirametrics/html_report_config.rb', line 127

def dependency_chart &block
  execute_chart DependencyChart.new block
end

#execute_chart(chart, &after_init_block) ⇒ Object



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/jirametrics/html_report_config.rb', line 136

def execute_chart chart, &after_init_block
  project_config = @file_config.project_config

  chart.file_system = file_system
  chart.issues = issues
  chart.time_range = project_config.time_range
  chart.timezone_offset = timezone_offset
  chart.settings = settings
  chart.atlassian_document_format = project_config.atlassian_document_format

  chart.all_boards = project_config.all_boards
  chart.board_id = find_board_id
  chart.holiday_dates = project_config.exporter.holiday_dates
  chart.fix_versions = project_config.fix_versions

  time_range = @file_config.project_config.time_range
  chart.date_range = time_range.begin.to_date..time_range.end.to_date
  chart.aggregated_project = project_config.aggregated_project?

  after_init_block&.call chart

  @charts << chart
  chart.before_run
  html chart.run
end

#execute_chart_per_board(klass:, block:, board_id:) ⇒ Object



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

def execute_chart_per_board klass:, block:, board_id:
  board_ids(board_id).each_with_index do |id, index|
    execute_chart(klass.new(block)) do |chart|
      chart.board_id = id
      # We're showing the description only on the first one in order to reduce noise on the report
      chart.description_text nil unless index.zero?
    end
  end
end

#file_systemObject



93
94
95
# File 'lib/jirametrics/html_report_config.rb', line 93

def file_system
  @file_config.project_config.exporter.file_system
end

#find_board(id) ⇒ Object

For use by the user config



171
172
173
# File 'lib/jirametrics/html_report_config.rb', line 171

def find_board id
  @file_config.project_config.all_boards[id]
end

#find_board_idObject



162
163
164
# File 'lib/jirametrics/html_report_config.rb', line 162

def find_board_id
  @board_id || @file_config.project_config.guess_board_id
end

#html(string, type: :body) ⇒ Object



114
115
116
117
118
119
# File 'lib/jirametrics/html_report_config.rb', line 114

def html string, type: :body
  allowed_types = %i[body header]
  raise "Unexpected type: #{type} allowed_types: #{allowed_types.inspect}" unless allowed_types.include? type

  @sections << [string, type]
end

#included_projectsObject

Mostly this is its own method so it can be called from the config



75
76
77
# File 'lib/jirametrics/html_report_config.rb', line 75

def included_projects
  @file_config.project_config.aggregate_config.included_projects
end

#issuesObject



166
167
168
# File 'lib/jirametrics/html_report_config.rb', line 166

def issues
  @file_config.issues
end

#log(message) ⇒ Object



97
98
99
# File 'lib/jirametrics/html_report_config.rb', line 97

def log message
  file_system.log message
end

#random_colorObject



109
110
111
112
# File 'lib/jirametrics/html_report_config.rb', line 109

def random_color
  @palette_index = (@palette_index || -1) + 1
  ChartBase::OKABE_ITO_PALETTE[@palette_index % ChartBase::OKABE_ITO_PALETTE.size]
end

#resolve_chart_class(class_name) ⇒ Object



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

def resolve_chart_class class_name
  klass = Object.const_get(class_name)
  klass < ChartBase ? klass : nil
rescue NameError
  nil
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
61
# File 'lib/jirametrics/html_report_config.rb', line 58

def respond_to_missing? name, include_private = false
  class_name = name.to_s.split('_').map(&:capitalize).join
  !resolve_chart_class(class_name).nil? || super
end

#runObject



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/jirametrics/html_report_config.rb', line 79

def run
  instance_eval(&@block)

  # The quality report has to be generated last because otherwise cycletime won't have been
  # set. Then we have to rotate it to the first position so it's at the top of the report.
  execute_chart DataQualityReport.new(file_config.project_config.discarded_changes_data)
  @sections.rotate!(-1)

  html create_footer

  create_html output_filename: @file_config.output_filename, settings: settings,
              project_name: @file_config.project_config.name
end

#settingsObject

have an explicit method here so that index.erb can call 'settings' just as any other erb can.



132
133
134
# File 'lib/jirametrics/html_report_config.rb', line 132

def settings
  @file_config.project_config.settings
end

#sprint_burndown(options = :points_and_counts) ⇒ Object



121
122
123
124
125
# File 'lib/jirametrics/html_report_config.rb', line 121

def sprint_burndown options = :points_and_counts
  execute_chart SprintBurndown.new do |chart|
    chart.options = options
  end
end

#timezone_offsetObject



105
106
107
# File 'lib/jirametrics/html_report_config.rb', line 105

def timezone_offset
  @file_config.project_config.exporter.timezone_offset
end