Class: InfoDumper

Inherits:
Object show all
Defined in:
lib/jirametrics/experimental/info.rb

Instance Method Summary collapse

Constructor Details

#initializeInfoDumper

Returns a new instance of InfoDumper.



7
8
9
# File 'lib/jirametrics/experimental/info.rb', line 7

def initialize
  @target_dir = 'target/'
end

Instance Method Details

#compact_text(text, max = 60) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/jirametrics/experimental/info.rb', line 64

def compact_text text, max = 60
  return nil if text.nil?

  text = text.gsub(/\s+/, ' ').strip
  text = "#{text[0..max]}..." if text.length > max
  text
end

#dump(issue) ⇒ Object



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
# File 'lib/jirametrics/experimental/info.rb', line 32

def dump issue
  puts "#{issue.key} (#{issue.type}): #{compact_text issue.summary, 200}"

  assignee = issue.raw['fields']['assignee']
  puts "  [assignee] #{assignee['name'].inspect} <#{assignee['emailAddress']}>" unless assignee.nil?

  issue.raw['fields']['issuelinks'].each do |link|
    puts "  [link] #{link['type']['outward']} #{link['outwardIssue']['key']}" if link['outwardIssue']
    puts "  [link] #{link['type']['inward']} #{link['inwardIssue']['key']}" if link['inwardIssue']
  end
  issue.changes.each do |change|
    value = change.value
    old_value = change.old_value

    # Description fields get pretty verbose so reduce the clutter
    if change.field == 'description' || change.field == 'summary'
      value = compact_text value
      old_value = compact_text old_value
    end

    author = change.author
    author = "(#{author})" if author
    message = "  [change] #{change.time} [#{change.field}] "
    message << "#{compact_text(old_value).inspect} -> " unless old_value.nil? || old_value.empty?
    message << compact_text(value).inspect
    message << " #{author}" if author
    message << ' <<artificial entry>>' if change.artificial?
    puts message
  end
  puts ''
end

#find_file_prefixesObject



24
25
26
27
28
29
30
# File 'lib/jirametrics/experimental/info.rb', line 24

def find_file_prefixes
  prefixes = []
  Dir.foreach @target_dir do |file|
    prefixes << $1 if file =~ /^(.+)_issues$/
  end
  prefixes
end

#run(key) ⇒ Object



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

def run key
  find_file_prefixes.each do |prefix|
    path = "#{@target_dir}#{prefix}_issues/#{key}.json"
    path = "#{@target_dir}#{prefix}_issues"
    Dir.foreach path do |file|
      if file =~ /^#{key}.+\.json$/
        issue = Issue.new raw: JSON.parse(File.read(File.join(path, file))), board: nil
        dump issue
      end
    end
  end
end