Class: FlowdockBuildNotifier::FlowdockNotification

Inherits:
Object
  • Object
show all
Defined in:
lib/flowdock_build_notifier.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(build_id) ⇒ FlowdockNotification

Returns a new instance of FlowdockNotification.



13
14
15
16
# File 'lib/flowdock_build_notifier.rb', line 13

def initialize(build_id)
  @build_id = build_id
  @config = Configuration.load
end

Instance Attribute Details

#build_idObject (readonly)

Returns the value of attribute build_id.



11
12
13
# File 'lib/flowdock_build_notifier.rb', line 11

def build_id
  @build_id
end

#configObject (readonly)

Returns the value of attribute config.



11
12
13
# File 'lib/flowdock_build_notifier.rb', line 11

def config
  @config
end

Instance Method Details

#author_emailObject



41
42
43
# File 'lib/flowdock_build_notifier.rb', line 41

def author_email
  `git show --format=format:%ae`.split("\n").first
end

#buildObject



37
38
39
# File 'lib/flowdock_build_notifier.rb', line 37

def build
  @build ||= BuildMetadata.new(config: config).tap { || .fetch(build_id) }
end

#messageObject



33
34
35
# File 'lib/flowdock_build_notifier.rb', line 33

def message
  NotificationMessage.new(build)
end

#notifyObject



18
19
20
21
22
23
24
25
# File 'lib/flowdock_build_notifier.rb', line 18

def notify
  sender = FlowdockMessageSenderFactory
    .new(config: config)
    .create_sender(notify_email)

  sender.send_message(message)
  notify_all if ENV['FLOWDOCK_NOTIFY_ALL_ON_FAILURE'] && build.status == "FAILURE"
end

#notify_allObject



27
28
29
30
31
# File 'lib/flowdock_build_notifier.rb', line 27

def notify_all
  TeamRoomSender
    .new(config: config)
    .send_message("#{message} @all")
end

#notify_emailObject



45
46
47
48
# File 'lib/flowdock_build_notifier.rb', line 45

def notify_email
  return File.read('.flowdock_notify_email').strip if File.exists? '.flowdock_notify_email'
  author_email
end