Module: CIJoe::Email

Defined in:
lib/cijoe/email.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.activateObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/cijoe/email.rb', line 5

def self.activate
  if valid_config?
    CIJoe::Build.class_eval do
      include CIJoe::Email
    end

    puts "Loaded Email notifier"
  else
    puts "Can't load Email notifier."
    puts "Please add the following to your project's .git/config:"
    puts "[email]"
    puts "\tto = [email protected]"
    puts "\tuser = horst"
    puts "\tpass = passw0rd"
    puts "\thost = mail.example.com"
    puts "\tauthtype = plain"
    puts "\tenabletls = 1"
  end
end

.configObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/cijoe/email.rb', line 25

def self.config
  @config ||= {
    :to        => Config.email.to.to_s, 
    :user      => Config.email.user.to_s,
    :pass      => Config.email.pass.to_s,
    :host      => Config.email.host.to_s,
    :auth_type => Config.email.authtype.to_s,
    :enable_tls => Config.email.enabletls.to_s
  }
end

.valid_config?Boolean

Returns:

  • (Boolean)


36
37
38
39
40
# File 'lib/cijoe/email.rb', line 36

def self.valid_config?
  %w( host user pass to auth_type ).all? do |key|
    !config[key.intern].empty?
  end
end

Instance Method Details

#mail_bodyObject



62
63
64
# File 'lib/cijoe/email.rb', line 62

def mail_body
  "The commit '#{commit.message}' (#{commit.url}) by #{commit.author} caused the build to fail."
end

#mail_configObject



52
53
54
55
56
57
58
59
60
# File 'lib/cijoe/email.rb', line 52

def mail_config
  config = MmMail::Transport::Config.new
  config.auth_user = Email.config[:user]
  config.auth_pass = Email.config[:pass]
  config.auth_type = Email.config[:auth_type].to_sym
  config.host = Email.config[:host]
  config.enable_tls = Email.config[:enable_tls] == "1" ? true : false
  config
end

#notifyObject



42
43
44
45
46
47
48
49
50
# File 'lib/cijoe/email.rb', line 42

def notify
  options = {
    :to => Email.config[:to],
    :from => Email.config[:to],
    :subject => "(#{project}) Build failed",
    :body => mail_body
  }
  MmMail.mail(options, mail_config) if failed?
end