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
24
25
26
# File 'lib/cijoe/email.rb', line 5

def self.activate

  # If the user supplied a valid email configuration, make the Build module
  # include this Email module
  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



28
29
30
31
32
33
34
35
36
37
# File 'lib/cijoe/email.rb', line 28

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)


39
40
41
42
43
# File 'lib/cijoe/email.rb', line 39

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

Instance Method Details

#mail_configObject



65
66
67
68
69
70
71
72
73
# File 'lib/cijoe/email.rb', line 65

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

#notify_failObject



45
46
47
48
49
50
51
52
53
# File 'lib/cijoe/email.rb', line 45

def notify_fail
  fail_options = {
    :to => Email.config[:to],
    :from => Email.config[:to],
    :subject => "(#{project}) Build failed",
    :body => "The commit '#{commit.message}' (#{commit.url}) by #{commit.author} caused the build to fail.\n\nFail log:\n\n#{faillog}"
  }
  MmMail.mail(fail_options, mail_config)
end

#notify_recoverObject



55
56
57
58
59
60
61
62
63
# File 'lib/cijoe/email.rb', line 55

def notify_recover
  recover_options = {
    :to => Email.config[:to],
    :from => Email.config[:to],
    :subject => "(#{project}) Build recovered",
    :body => "The commit '#{commit.message}' (#{commit.url}) by #{commit.author} fixed the build."
  }
  MmMail.mail(recover_options, mail_config)
end