Sha256: 882f600886d21f189852dfbb49a372aeea23499c69720a6be52e549aabee7c59

Contents?: true

Size: 1.68 KB

Versions: 1

Compression:

Stored size: 1.68 KB

Contents

require 'cocoapods'
require 'pathname'
require 'pp'
require 'tmpdir'
require 'json'

require 'rainbow'
require 'yaml'
require 'git'
require 'yk_command/analyze/dependency_result'
require 'wechat_work_webhook'
module YkCommand
  class WxBot < Thor



    no_commands do

      def initialize(config)

        webhook_url = config[:webhook_url]
        @project_url = config[:project_url]
        @project_cover_image_url = config[:project_cover_image_url]

        @wechat = WechatWorkWebhook.new(webhook_url)
      end

      def send_result_to_group(success_list, failed_list)
        time = Time.new
        time_s = "#{time.year}-#{time.month}-#{time.day} "
        @wechat.markdown("## #{time_s} 分析结果\n### 成功 #{success_list.length} 个 #{result_item_list_string(success_list, 'success')}\n### 失败 #{failed_list.length} 个 #{result_item_list_string(failed_list, 'failed')}")

      end

      def send_news_to_group
        require 'wechat_work_webhook'


        time = Time.new
        time_s = "#{time.year}-#{time.month}-#{time.day} "

        @wechat.news([{
                        "title" => "#{time_s}  依赖分析已完成",
                        "description" => "点击进入组件管理平台",
                        "url" => @project_url,
                        "picurl" => @project_cover_image_url
                      }])
      end

      def result_item_list_string(list, level)
        result = ''
        list.each do |name|
          if level == 'success'
            result += "\n- <font color=\"#0099ff\">#{name}</font> "
          else
            result += "\n- <font color=\"#DC143C\">#{name}</font> "
          end
        end
        result
      end
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
yk_command-0.5.1 lib/yk_command/bot/wx_bot.rb