Class: Fastlane::Actions::GmailNotifyAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/gmail_notify/actions/gmail_notify_action.rb

Class Method Summary collapse

Class Method Details

.authorsObject



60
61
62
# File 'lib/fastlane/plugin/gmail_notify/actions/gmail_notify_action.rb', line 60

def self.authors
  ["Antony Leons"]
end

.available_optionsObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/fastlane/plugin/gmail_notify/actions/gmail_notify_action.rb', line 73

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :smtp_email,
                                 env_name: "GMAIL_NOTIFY_SENDER_EMAIL",
                                 description: "Gmail account to login with",
                                 optional: false,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :smtp_password,
                                 env_name: "GMAIL_NOTIFY_SENDER_PASSWORD",
                                 description: "Password of Gmail account to login with",
                                 optional: false,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :recipients,
                                 env_name: "GMAIL_NOTIFY_RECIPIENTS",
                                 description: "Recipients of email",
                                 optional: false,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :cc,
                                 env_name: "GMAIL_NOTIFY_CC",
                                 description: "CC of email",
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :subject,
                                 env_name: "GMAIL_NOTIFY_SUBJECT",
                                 description: "Subject of email",
                                 optional: false,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :template_file,
                                 env_name: "GMAIL_NOTIFY_TEMPLATE_FILE",
                                 description: "Path of template file",
                                 optional: false,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :lint_report,
                                 env_name: "GMAIL_NOTIFY_LINT_REPORT_FILE",
                                 description: "Path of lint report file",
                                 optional: false,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :placeholders,
                                 env_name: "GMAIL_NOTIFY_TEMPLATE_PLACEHOLDERS",
                                 description: "Placeholders for email template",
                                 optional: false,
                                 type: Hash)
  ]
end

.descriptionObject



56
57
58
# File 'lib/fastlane/plugin/gmail_notify/actions/gmail_notify_action.rb', line 56

def self.description
  "Sends a mail using SMTP"
end

.detailsObject



68
69
70
71
# File 'lib/fastlane/plugin/gmail_notify/actions/gmail_notify_action.rb', line 68

def self.details
  # Optional:
  "This plugin sends a mail using SMTP"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


118
119
120
121
122
123
124
# File 'lib/fastlane/plugin/gmail_notify/actions/gmail_notify_action.rb', line 118

def self.is_supported?(platform)
  # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
  # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
  #
  # [:ios, :mac, :android].include?(platform)
  true
end

.return_valueObject



64
65
66
# File 'lib/fastlane/plugin/gmail_notify/actions/gmail_notify_action.rb', line 64

def self.return_value
  # If your method provides a return value, you can describe here what it does
end

.run(params) ⇒ Object



8
9
10
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
# File 'lib/fastlane/plugin/gmail_notify/actions/gmail_notify_action.rb', line 8

def self.run(params)
  UI.message("The gmail_notify plugin is working!")

  require 'pony'
  require 'erb'

  body = ERB.new(File.read(params[:template_file]), trim_mode: nil).result_with_hash(params[:placeholders])

  begin
    retries ||= 0

    Pony.mail({
    to: params[:recipients],
    cc: params[:cc],
    subject: params[:subject],
    html_body: body,
    attachments: { "lintReport.html" => File.read(params[:lint_report]) },
    body_part_header: { content_disposition: "inline" },
    via: :smtp,
    via_options: {
      address: "smtp.gmail.com",
      port: "587",
      enable_starttls_auto: true,
      user_name: params[:smtp_email],
      password: params[:smtp_password],
      authentication: :plain, # :plain, :login, :cram_md5, no auth by default
      domain: "localhost.localdomain" # the HELO domain provided by the client to the server
    }
  })
  rescue Net::ReadTimeout
    if (retries += 1) < 5
      puts("retrying ##{retries}")
      sleep(5)
      retry
    else
      raise
    end
  end
end

.test(params) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/fastlane/plugin/gmail_notify/actions/gmail_notify_action.rb', line 48

def self.test(params)
  UI.message("The gmail_notify plugin is working!")

  body = ERB.new(File.read(params[:template_file]), trim_mode: nil).result_with_hash(params[:placeholders])

  puts(body)
end