Sha256: c1436c7ec1e4fbebb7a7b60d8767a92653d15544a149e8e6394706dede9cac12

Contents?: true

Size: 922 Bytes

Versions: 1

Compression:

Stored size: 922 Bytes

Contents

require 'active_record'
require 'travis/github_api'

class Repository
  module ServiceHook
    def service_hook
      @service_hook ||= ServiceHook.new(self)
    end

    class ServiceHook
      attr_reader :repository

      def initialize(repository)
        @repository = repository
      end

      def set(active, user)
        active ? activate(user) : deactivate(user)
        repository.update_attributes!(:active => active)
      end

      protected

        def activate(user)
          Travis::GithubApi.add_service_hook(repository.owner_name, repository.name, user.github_oauth_token,
            :token  => user.tokens.first.token,
            :user   => user.login,
            :domain => Travis.config.domain
          )
        end

        def deactivate(user)
          Travis::GithubApi.remove_service_hook(repository.owner_name, repository.name, user.github_oauth_token)
        end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
travis-core-0.0.1 lib/travis/model/repository/service_hook.rb