Class: Lazylead::Stacktrace

Inherits:
Requirement show all
Defined in:
lib/lazylead/task/accuracy/stacktrace.rb

Overview

Java stacktrace or Oracle errors in #noformat section

Instance Attribute Summary

Attributes inherited from Requirement

#desc, #field, #score

Instance Method Summary collapse

Methods inherited from Requirement

#blank?, #non_blank?

Constructor Details

#initialize(score = 3) ⇒ Stacktrace

Returns a new instance of Stacktrace.



30
31
32
33
# File 'lib/lazylead/task/accuracy/stacktrace.rb', line 30

def initialize(score = 3)
  super "Stacktrace/errors in *\\{noformat\\}* for JIRA indexing", score,
        "Description"
end

Instance Method Details

#code(desc) ⇒ Object

Detect all code:* blocks and give all text snippets in array

Parameters:

  • desc

    The jira ticket description



58
59
60
61
62
63
64
65
66
67
# File 'lib/lazylead/task/accuracy/stacktrace.rb', line 58

def code(desc)
  return [] unless desc.match?(/{(c|C)(o|O)(d|D)(e|E)(:\S+)?}/)
  words = desc.gsub(/{(c|C)(o|O)(d|D)(e|E)/, " {code")
              .gsub("}", "} ")
              .gsub("Caused by:", "Caused_by:")
              .split
              .map(&:strip)
              .reject(&:blank?)
  pairs(words, "{code").map { |s| words[s.first..s.last].join("\n") }
end

#frames(description) ⇒ Object

Detect all #noformat, #code frames in ticket description



41
42
43
# File 'lib/lazylead/task/accuracy/stacktrace.rb', line 41

def frames(description)
  noformat(description).concat(code(description))
end

#java?(frame) ⇒ Boolean

Returns true if frame has few lines with java stack frames.

Returns:

  • (Boolean)

    true if frame has few lines with java stack frames



89
90
91
92
93
94
95
# File 'lib/lazylead/task/accuracy/stacktrace.rb', line 89

def java?(frame)
  allowed = ["at", "Caused by:", "Caused_by:"]
  frame.match?(/\s\S+\.\S+Exception:\s/) ||
    frame.split("\n")
         .map(&:strip)
         .count { |l| allowed.any? { |a| l.start_with? a } } > 3
end

#noformat(desc) ⇒ Object

Detect all noformat blocks and give all text snippets in array

Parameters:

  • desc

    The jira ticket description



47
48
49
50
51
52
53
54
# File 'lib/lazylead/task/accuracy/stacktrace.rb', line 47

def noformat(desc)
  return [] unless desc.match?(/{(n|N)(o|O)(f|F)(o|O)(r|R)(m|M)(a|A)(t|T)}/)
  desc.enum_for(:scan, /(?=\{(n|N)(o|O)(f|F)(o|O)(r|R)(m|M)(a|A)(t|T)})/)
      .map { Regexp.last_match.offset(0).first }
      .each_slice(2).map do |f|
    desc[f.first, f.last - f.first + "{noformat}".size]
  end
end

#oracle?(frame) ⇒ Boolean

Returns true if frame has Oracle error.

Returns:

  • (Boolean)

    true if frame has Oracle error

See Also:



99
100
101
# File 'lib/lazylead/task/accuracy/stacktrace.rb', line 99

def oracle?(frame)
  frame.match?(/\WORA-\d{5}:/)
end

#pairs(words, text) ⇒ Object

Detect indexes of pairs which are starting from particular text

Parameters:

  • words

    is array of words

  • text

    is a label for pairs

    paris(, “tag”) => [[1, 4]] paris(, “tag”) => [[1, 4]] # non closed



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/lazylead/task/accuracy/stacktrace.rb', line 76

def pairs(words, text)
  snippets = [[]]
  words.each_with_index do |e, i|
    next unless e.start_with? text
    pair = snippets.last
    pair << i if pair.size.zero? || pair.size == 1
    snippets[-1] = pair
    snippets << [] if pair.size == 2
  end
  snippets.select { |s| s.size == 2 }
end

#passed(issue) ⇒ Object



35
36
37
38
# File 'lib/lazylead/task/accuracy/stacktrace.rb', line 35

def passed(issue)
  return false if issue.description.nil?
  frames(issue.description).any? { |f| oracle?(f) || java?(f) }
end