Class: HtmlReportConfig

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

Instance Attribute Summary collapse

Class Method 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.



28
29
30
31
32
33
34
# File 'lib/jirametrics/html_report_config.rb', line 28

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



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

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

Class Method Details

.define_chart(name:, classname:, deprecated_warning: nil, deprecated_date: nil) ⇒ Object



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

def self.define_chart name:, classname:, deprecated_warning: nil, deprecated_date: nil
  lines = []
  lines << "def #{name} &block"
  lines << '  block = ->(_) {} unless block'
  if deprecated_warning
    lines << "  file_system.deprecated date: #{deprecated_date.inspect}, message: #{deprecated_warning.inspect}"
  end
  lines << "  execute_chart #{classname}.new(block)"
  lines << 'end'
  module_eval lines.join("\n"), __FILE__, __LINE__
end

Instance Method Details

#board_id(id) ⇒ Object



113
114
115
# File 'lib/jirametrics/html_report_config.rb', line 113

def board_id id
  @board_id = id
end

#boardsObject

For use by the user config



187
188
189
# File 'lib/jirametrics/html_report_config.rb', line 187

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


191
192
193
194
195
196
197
198
199
200
201
# File 'lib/jirametrics/html_report_config.rb', line 191

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



75
76
77
78
79
80
81
82
83
84
# File 'lib/jirametrics/html_report_config.rb', line 75

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



138
139
140
# File 'lib/jirametrics/html_report_config.rb', line 138

def dependency_chart &block
  execute_chart DependencyChart.new block
end

#discard_changes_before(status_becomes: nil, &block) ⇒ Object



203
204
205
206
207
208
209
# File 'lib/jirametrics/html_report_config.rb', line 203

def discard_changes_before status_becomes: nil, &block
  file_system.deprecated(
    date: '2025-01-09',
    message: 'discard_changes_before is now only supported at the project level'
  )
  file_config.project_config.discard_changes_before status_becomes: status_becomes, &block
end

#execute_chart(chart, &after_init_block) ⇒ Object



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/jirametrics/html_report_config.rb', line 147

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



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/jirametrics/html_report_config.rb', line 57

def execute_chart_per_board klass:, block:, board_id:
  all_boards = @file_config.project_config.all_boards
  ids = board_id ? [board_id] : issues.collect { |i| i.board.id }.uniq
  ids = ids.sort_by { |id| all_boards[id]&.name || '' }
  ids.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



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

def file_system
  @file_config.project_config.exporter.file_system
end

#find_board(id) ⇒ Object

For use by the user config



182
183
184
# File 'lib/jirametrics/html_report_config.rb', line 182

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

#find_board_idObject



173
174
175
# File 'lib/jirametrics/html_report_config.rb', line 173

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

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



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

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



87
88
89
# File 'lib/jirametrics/html_report_config.rb', line 87

def included_projects
  @file_config.project_config.aggregate_config.included_projects
end

#issuesObject



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

def issues
  @file_config.issues
end

#log(message) ⇒ Object



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

def log message
  file_system.log message
end

#random_colorObject



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

def random_color
  "##{Random.bytes(3).unpack1('H*')}"
end

#resolve_chart_class(class_name) ⇒ Object



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

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)


70
71
72
73
# File 'lib/jirametrics/html_report_config.rb', line 70

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



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/jirametrics/html_report_config.rb', line 91

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.



143
144
145
# File 'lib/jirametrics/html_report_config.rb', line 143

def settings
  @file_config.project_config.settings
end

#sprint_burndown(options = :points_and_counts) ⇒ Object



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

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

#timezone_offsetObject



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

def timezone_offset
  @file_config.project_config.exporter.timezone_offset
end