Sha256: 9d86488c0671dd42ea3a18e6df691af49c3428731a9758c1a6ef18f60272a0ec

Contents?: true

Size: 1.6 KB

Versions: 1

Compression:

Stored size: 1.6 KB

Contents

require 'irc_client'

module Travis
  module Notifications
    class Irc
      EVENTS = 'build:finished'

      def notify(event, build, *args)
        send_irc_notifications(build) if build.send_irc_notifications?
      end

      protected
        def send_irc_notifications(build)
          # Notifications to the same host are grouped so that they can be sent with a single connection
          build.irc_channels.each do |server, channels|
            host, port = *server
            send_notifications(host, port, channels, build)
          end
        end

        def send_notifications(host, port, channels, build)
          commit = build.commit
          build_url = self.build_url(build)

          irc(host, nick, :port => port) do |irc|
            channels.each do |channel|
              join(channel)
              say "[travis-ci] #{build.repository.slug}##{build.number} (#{commit.branch} - #{commit.commit[0, 7]} : #{commit.author_name}): #{build.human_status_message}"
              say "[travis-ci] Change view : #{commit.compare_url}"
              say "[travis-ci] Build details : #{build_url}"
              leave
            end
          end
        end

        def irc(host, nick, options, &block)
          IrcClient.new(host, nick, options).tap do |irc|
            irc.run(&block) if block_given?
            irc.quit
          end
        end

        def nick
          Travis.config.irc.try(:nick) || 'travis-ci'
        end

        def build_url(build)
          [Travis.config.host, build.repository.owner_name, build.repository.name, 'builds', build.id].join('/')
        end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
travis-core-0.0.1 lib/travis/notifications/irc.rb