Sha256: d8efb33fed03d552cd8250e173254d55b3a83a74647edfafdffc376bcacb3362

Contents?: true

Size: 1.78 KB

Versions: 14

Compression:

Stored size: 1.78 KB

Contents

require 'open-uri'
require 'yajl'
require 'cgi'

module Cinch
  module Plugins
    class Redmine
      include Cinch::Plugin

      timer 60, method: :check_redmine

      set :plugin_name, 'redmine'
      set :help, <<EOT
Redmine plugins checks the new issues in the specified redmine instance
EOT

      def check_redmine
        @issues ||= Array.new
        api_key = @bot.config.options['cogconf']['redmine']['api_key']
        redmine_url = "%s/issues.json?project_id=%s&limit=20" % [
          @bot.config.options['cogconf']['redmine']['url'],
          @bot.config.options['cogconf']['redmine']['project']
        ]
        res = Yajl::Parser.parse(open(redmine_url, "X-Redmine-API-Key" => api_key))
        subjs = Hash[ res['issues'].map { |i| [ i['id'], i['subject'] ] } ]
        issues = subjs.keys
        newones = Array.new
        if @issues.count == 0
          @issues = issues
        else
          issues.each { |i| newones << i unless @issues.include? i  }
          if newones.count > 0
            newones.each do |i|
              @issues.push i
              @bot.config.options['cogconf']['main']['channels'].each do |channel|
                Channel(channel).msg "[%s] >>> %s - %s/issues/%s" % [
                  @bot.config.options['cogconf']['redmine']['project'],
                  subjs[i],
                  @bot.config.options['cogconf']['redmine']['url'],
                  i
                ]
              end
            end
            @issues = @issues[0..500]
          end
        end
        # puts "redmine: done #{newones.count} new issues, #{@issues.count} cached"
      rescue Exception => e
        puts "*** #{e.class}\n"
        puts e.to_s
        puts e.backtrace
      end

      def new(bot)
        @bot = bot
        @issues = Array.new
      end

    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
cogbot-0.1.14 plugins/redmine.rb
cogbot-0.1.13 plugins/redmine.rb
cogbot-0.1.12 plugins/redmine.rb
cogbot-0.1.11 plugins/redmine.rb
cogbot-0.1.10 plugins/redmine.rb
cogbot-0.1.9 plugins/redmine.rb
cogbot-0.1.7 plugins/redmine.rb
cogbot-0.1.6 plugins/redmine.rb
cogbot-0.1.5 plugins/redmine.rb
cogbot-0.1.4 plugins/redmine.rb
cogbot-0.1.3 plugins/redmine.rb
cogbot-0.1.2 plugins/redmine.rb
cogbot-0.1.1 plugins/redmine.rb
cogbot-0.1.0 plugins/redmine.rb