Class: Danger::DangerDeviceGrid

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

Overview

A danger plugin: github.com/danger/danger

Instance Method Summary collapse

Instance Method Details

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

Parameters:

  • public_key: (defaults to: nil)

    The key for the Appetize.io

  • languages: (defaults to: nil)

    Array of languages you want to see (e.g. [en, de])

  • devices: (defaults to: nil)

    Array of deviecs you want to see (e.g. [“iphone4s”, “ipadair”])

  • prefix_command: (defaults to: nil)

    Prefix the ‘fastlane run appetize_viewing_url_generator` command with something this can be used to use `bundle exec`



11
12
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
64
65
66
# File 'lib/device_grid/plugin.rb', line 11

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 iphone7 iphone6splus iphone7plus ipadair)
  languages ||= ["en"]

  prefix_command ||= ""

  # To use the local fastlane instead of bundle
  prefix_command = "./bin/" if FastlaneCore::Helper.test?

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

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

    devices.each do |current_device|
      html << "<td>"

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

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

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