Class: Lazylead::Screenshots

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

Overview

Check that ticket has screenshot(s). The screenshots should

1. present as attachments
2. has extension .jpg .jpeg .exif .tiff .tff .bmp .png .svg
3. mentioned in description with !<name>.<extension>|thumbnail! (read more https://bit.ly/3rusNgW)

Instance Attribute Summary

Attributes inherited from Requirement

#desc, #field, #score

Instance Method Summary collapse

Methods inherited from Requirement

#blank?, #non_blank?

Constructor Details

#initialize(minimum: 1, score: 2, ext: %w[.jpg .jpeg .exif .tiff .tff .bmp .png .svg])) ⇒ Screenshots

Returns a new instance of Screenshots.

Parameters:

  • minimum (defaults to: 1)

    The number of expected screenshots



37
38
39
40
41
# File 'lib/lazylead/task/accuracy/screenshots.rb', line 37

def initialize(minimum: 1, score: 2, ext: %w[.jpg .jpeg .exif .tiff .tff .bmp .png .svg])
  super "Internal reproducing results (screenshots)", score, "Description,Attachments"
  @minimum = minimum
  @ext = ext
end

Instance Method Details

#passed(issue) ⇒ Object



43
44
45
46
# File 'lib/lazylead/task/accuracy/screenshots.rb', line 43

def passed(issue)
  return false if issue.attachments.nil? || blank?(issue, "description")
  references(issue).count { |r| pictures(issue).any? { |file| r.include? file } } >= @minimum
end

#pictures(issue) ⇒ Object

Detect all pictures in ticket attachments and returns an array with file names.



58
59
60
61
62
# File 'lib/lazylead/task/accuracy/screenshots.rb', line 58

def pictures(issue)
  issue.attachments
       .select { |a| @ext.include? File.extname(a.filename).downcase }
       .map(&:filename)
end

#references(issue) ⇒ Object

Detect all references in ticket description to attachments (including web links).



49
50
51
52
53
54
55
# File 'lib/lazylead/task/accuracy/screenshots.rb', line 49

def references(issue)
  issue.description
       .to_enum(:scan, /!.+!/)
       .map { Regexp.last_match }
       .map(&:to_s)
       .grep_v(%r{(http|https)://.*/images/icons/link_attachment.*.gif})
end