Class: Danger::Dangerfile::DSL::DeviceGrid

Inherits:
Plugin
  • Object
show all
Defined in:
lib/fastlane/actions/device_grid/device_grid.rb

Overview

A danger plugin: github.com/danger/danger

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.descriptionObject



96
97
98
99
100
# File 'lib/fastlane/actions/device_grid/device_grid.rb', line 96

def self.description
  [
    "Render a grid of devices"
  ].join(" ")
end

Instance Method Details

#beautiful_device_name(str) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/fastlane/actions/device_grid/device_grid.rb', line 65

def beautiful_device_name(str)
  return {
    iphone4s: "iPhone 4s",
    iphone5s: "iPhone 5s",
    iphone6s: "iPhone 6s",
    iphone6splus: "iPhone 6s Plus",
    ipadair: "iPad Air",
    iphone6: "iPhone 6",
    iphone6plus: "iPhone 6 Plus",
    ipadair2: "iPad Air 2",
    nexus5: "Nexus 5",
    nexus7: "Nexus 7",
    nexus9: "Nexus 9"
  }[str.to_sym] || str.to_s
end

#run(public_key: nil, languages: nil, devices: nil, prefix_command: nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
63
# File 'lib/fastlane/actions/device_grid/device_grid.rb', line 13

def run(public_key: nil, languages: nil, devices: nil, prefix_command: nil)
  # since we fetch the URL from the output we don't need colors
  # this will only be changed in the danger sub-process
  fastlane_colors_env = "FASTLANE_DISABLE_COLORS"
  fastlane_colors_were_disabled = ENV.key?(fastlane_colors_env)
  ENV[fastlane_colors_env] = "true"

  devices ||= %w(iphone4s iphone5s iphone6s iphone6splus ipadair)
  languages ||= ["en"]
  prefix_command = "bundle exec" if File.exist?("Gemfile")
  prefix_command ||= ""

  deep_link_matches = pr_body.match(/:link:\s(.*)/) # :link: emoji
  deep_link = deep_link_matches[1] if deep_link_matches

  markdown("<table>")
  languages.each do |current_language|
    markdown("<tr>")
      markdown("<td>")
        markdown("<b>#{current_language[0..1]}</b>")
      markdown("</td>")

      devices.each do |current_device|
        markdown("<td>")

        params = {
          public_key: public_key,
          language: current_language,
          device: current_device
        }
        params[:launch_url] = deep_link if deep_link
        params_str = params.collect { |k, v| "#{k}:\"#{v}\"" }.join(" ")
        url = `#{prefix_command} fastlane run appetize_viewing_url_generator #{params_str}`
        url = url.match(%r{Result:.*(https\:\/\/.*)})[1].strip

        markdown("<a href='#{url}'>")
          markdown("<p align='center'>")
            markdown("<img height='130' src='#{url_for_device(current_device)}' />")
            markdown("<br />")
            markdown(beautiful_device_name(current_device))
          markdown("</p>")
        markdown("</a>")

        markdown("</td>")
      end
    markdown("</tr>")
  end
  markdown("</table>")
ensure
  ENV.delete(fastlane_colors_env) unless fastlane_colors_were_disabled
end

#url_for_device(str) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/fastlane/actions/device_grid/device_grid.rb', line 81

def url_for_device(str)
  str = str.to_sym
  host = "https://raw.githubusercontent.com/fastlane/fastlane/#{Fastlane::VERSION}/fastlane/lib/fastlane/actions/device_grid/assets/"
  return {
    iphone4s: host + "iphone4s.png",
    iphone5s: host + "iphone5s.png",
    iphone6: host + "iphone6s.png",
    iphone6s: host + "iphone6s.png",
    iphone6plus: host + "iphone6splus.png",
    iphone6splus: host + "iphone6splus.png",
    ipadair: host + "ipadair.png",
    ipadair2: host + "ipadair.png"
  }[str] || ""
end