Sha256: 5a662350eb0e8cd67a2067752edfd75d9ed62400bc349eb3ff1fa46e0dc48586

Contents?: true

Size: 1010 Bytes

Versions: 36

Compression:

Stored size: 1010 Bytes

Contents

require 'lhj/helper/dingtalk_config'
require 'json'

module Lhj
  # pgyer upload
  class Dingtalk

    def self.post_message(title, message)
      robot_url = Lhj::DingTalkConfig.dingtalk_robot
      http_body = { 'msgtype' => 'markdown', 'markdown' => { 'title' => title, 'text' => message } }.to_json
      http_post(robot_url, http_body)
      post_branch_message(http_body)
    end

    def self.post_branch_message(http_body)
      branch_name = fetch_branch
      branch_map = Lhj::DingTalkConfig.git_branch
      branch_robot_key = branch_map[branch_name] if branch_map && branch_name
      branch_robot_url = Lhj::DingTalkConfig.config[branch_robot_key] if branch_robot_key
      http_post(branch_robot_url, http_body) if branch_robot_url
    end

    def self.http_post(robot_url, http_body)
      Net::HTTP.post(URI(robot_url), http_body, 'Content-Type' => 'application/json')
    end

    def self.fetch_branch
      name = Lhj::Actions.git_branch || ''
      name.split('/').last
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
lhj-tools-0.1.65 lib/lhj/helper/dingtalk_helper.rb
lhj-tools-0.1.64 lib/lhj/helper/dingtalk_helper.rb
lhj-tools-0.1.63 lib/lhj/helper/dingtalk_helper.rb
lhj-tools-0.1.62 lib/lhj/helper/dingtalk_helper.rb
lhj-tools-0.1.61 lib/lhj/helper/dingtalk_helper.rb
lhj-tools-0.1.60 lib/lhj/helper/dingtalk_helper.rb
lhj-tools-0.1.59 lib/lhj/helper/dingtalk_helper.rb
lhj-tools-0.1.57 lib/lhj/helper/dingtalk_helper.rb
lhj-tools-0.1.56 lib/lhj/helper/dingtalk_helper.rb
lhj-tools-0.1.55 lib/lhj/helper/dingtalk_helper.rb
lhj-tools-0.1.54 lib/lhj/helper/dingtalk_helper.rb
lhj-tools-0.1.53 lib/lhj/helper/dingtalk_helper.rb
lhj-tools-0.1.52 lib/lhj/helper/dingtalk_helper.rb
lhj-tools-0.1.51 lib/lhj/helper/dingtalk_helper.rb
lhj-tools-0.1.50 lib/lhj/helper/dingtalk_helper.rb
lhj-tools-0.1.49 lib/lhj/helper/dingtalk_helper.rb
lhj-tools-0.1.48 lib/lhj/helper/dingtalk_helper.rb
lhj-tools-0.1.47 lib/lhj/helper/dingtalk_helper.rb
lhj-tools-0.1.45 lib/lhj/helper/dingtalk_helper.rb
lhj-tools-0.1.44 lib/lhj/helper/dingtalk_helper.rb