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 "Screenshots", score, "Description,Attachments"
  @minimum = minimum
  @ext = ext
end

Instance Method Details

#passed(issue) ⇒ Object



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

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

#pictures(issue) ⇒ Object

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



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

def pictures(issue)
  @pictures ||= 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).



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

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