Class: Lhj::Dingtalk

Inherits:
Object
  • Object
show all
Defined in:
lib/lhj/helper/dingtalk_helper.rb

Overview

pgyer upload

Class Method Summary collapse

Class Method Details

.fetch_branchObject



27
28
29
30
# File 'lib/lhj/helper/dingtalk_helper.rb', line 27

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

.http_post(robot_url, http_body) ⇒ Object



23
24
25
# File 'lib/lhj/helper/dingtalk_helper.rb', line 23

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

.post_branch_message(http_body) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/lhj/helper/dingtalk_helper.rb', line 15

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

.post_message(title, message) ⇒ Object



8
9
10
11
12
13
# File 'lib/lhj/helper/dingtalk_helper.rb', line 8

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