Skip to content

Commit 2fec007

Browse files
committed
add type to third notifiers
1 parent 4530698 commit 2fec007

8 files changed

+50
-38
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ fir.im-cli 可以通过指令查看, 上传, iOS/Android 应用.
1717

1818

1919
# 最近更新
20+
- (2.0.14) 第三方通知加入了 app 类型, 第三方报错将忽略异常继续运行
2021
- (2.0.13) 修正了企业微信通知的bug
2122
- (2.0.12) 修复因为钉钉机器人不再支持base64导致无法显示二维码,另外开始支持钉钉加签方式的鉴权, 参数为 --dingtalk_secret
2223
- (2.0.11) 兼容了 ruby 3.0

fir-cli.gemspec

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
2727
/_/ /___/_/ |_| \____/_____/___/
2828
2929
## 更新记录
30+
- (2.0.14) 第三方通知加入了 app 类型, 第三方报错将不再直接报出异常
3031
- (2.0.13) 修复了无法跳过企业微信通知逻辑的bug
3132
- (2.0.12) 修复因为钉钉机器人不再支持base64导致无法显示二维码,另外开始支持钉钉加签方式的鉴权, 参数为 --dingtalk_secret
3233
- (2.0.11) 兼容了 ruby 3.0 版本, 增加了环境变量FEISHU_TIMEOUT,可以多给飞书一些超时时间

lib/fir/util/dingtalk_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def send_msg
2020
return if options[:dingtalk_access_token].blank?
2121

2222
api_domain = @app_info[:api_url]
23-
title = "#{@app_info[:name]}-#{@app_info[:version]}(Build #{@app_info[:build]})"
23+
title = "#{@app_info[:name]}-#{@app_info[:version]}(Build #{@app_info[:build]}) #{@app_info[:type]}"
2424
payload = {
2525
"msgtype": 'markdown',
2626
"markdown": {

lib/fir/util/feishu_helper.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ def initialize(app_info, options, qrcode_path, download_url)
1010
@feishu_access_token = @options[:feishu_access_token]
1111
@qrcode_path = qrcode_path
1212
@download_url = download_url
13-
@title = "#{@app_info[:name]}-#{@app_info[:version]}(Build #{@app_info[:build]})"
13+
14+
@title = "#{@app_info[:name]}-#{@app_info[:version]}(Build #{@app_info[:build]}) #{@app_info[:type]}"
1415
end
1516

1617
def send_msg

lib/fir/util/publish.rb

+3-31
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
# require 'byebug'
44

5+
require_relative './third_notifier_module'
56
require_relative './qiniu_uploader'
67
require_relative './ali_uploader'
78
require_relative '../util/feishu_helper'
89
require_relative '../util/dingtalk_helper'
910

1011
module FIR
1112
module Publish
13+
include FIR::ThirdNotifierModule
1214
def publish(*args, options)
1315
initialize_publish_options(args, options)
1416
logger_info_publishing_message
@@ -30,9 +32,7 @@ def publish(*args, options)
3032

3133
qrcode_path = build_qrcode download_url
3234

33-
dingtalk_notifier(download_url, qrcode_path)
34-
feishu_notifier(download_url, qrcode_path)
35-
wxwork_notifier(download_url)
35+
notify_to_thirds(download_url, qrcode_path)
3636

3737
upload_mapping_file_with_publish
3838

@@ -195,34 +195,6 @@ def force_pin_release(release_id)
195195
api_token: @token
196196
end
197197

198-
def dingtalk_notifier(download_url, qrcode_path)
199-
DingtalkHelper.new(@app_info, options, qrcode_path, download_url).send_msg
200-
end
201-
202-
def feishu_notifier(download_url, qrcode_path)
203-
FeishuHelper.new(@app_info, options, qrcode_path, download_url).send_msg
204-
end
205-
206-
def wxwork_notifier(download_url)
207-
return if options[:wxwork_webhook].blank? && options[:wxwork_access_token].blank?
208-
209-
webhook_url = options[:wxwork_webhook]
210-
webhook_url ||= "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=#{options[:wxwork_access_token]}"
211-
212-
title = "#{@app_info[:name]}-#{@app_info[:version]}(Build #{@app_info[:build]})"
213-
payload = {
214-
"msgtype": 'news',
215-
"news": {
216-
"articles": [{
217-
"title": "#{title} uploaded",
218-
"description": "#{title} uploaded at #{Time.now}\nurl: #{download_url}\n#{options[:wxwork_custom_message]}\n",
219-
"url": download_url,
220-
"picurl": options[:wxwork_pic_url]
221-
}]
222-
}
223-
}
224-
DefaultRest.post(webhook_url, payload)
225-
end
226198

227199
def initialize_publish_options(args, options)
228200
@options = options

lib/fir/util/third_notifier_module.rb

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
module FIR
2+
module ThirdNotifierModule
3+
def notify_to_thirds(download_url, qrcode_path)
4+
dingtalk_notifier(download_url, qrcode_path)
5+
feishu_notifier(download_url, qrcode_path)
6+
wxwork_notifier(download_url)
7+
rescue => e
8+
logger.warn "third notifiers error #{e.message}"
9+
end
10+
11+
def dingtalk_notifier(download_url, qrcode_path)
12+
DingtalkHelper.new(@app_info, options, qrcode_path, download_url).send_msg
13+
end
14+
15+
def feishu_notifier(download_url, qrcode_path)
16+
FeishuHelper.new(@app_info, options, qrcode_path, download_url).send_msg
17+
end
18+
19+
def wxwork_notifier(download_url)
20+
return if options[:wxwork_webhook].blank? && options[:wxwork_access_token].blank?
21+
22+
webhook_url = options[:wxwork_webhook]
23+
webhook_url ||= "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=#{options[:wxwork_access_token]}"
24+
25+
title = "#{@app_info[:name]}-#{@app_info[:version]}(Build #{@app_info[:build]}) #{@app_info[:type]}"
26+
payload = {
27+
"msgtype": 'news',
28+
"news": {
29+
"articles": [{
30+
"title": "#{title} uploaded",
31+
"description": "#{title} uploaded at #{Time.now}\nurl: #{download_url}\n#{options[:wxwork_custom_message]}\n",
32+
"url": download_url,
33+
"picurl": options[:wxwork_pic_url]
34+
}]
35+
}
36+
}
37+
DefaultRest.post(webhook_url, payload)
38+
end
39+
end
40+
end

lib/fir/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# encoding: utf-8
22

33
module FIR
4-
VERSION = '2.0.13'
4+
VERSION = '2.0.14'
55
end

test/test_helper.rb

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
# encoding: utf-8
22

33
# CodeClimate::TestReporter.start
4-
require 'codeclimate-test-reporter'
5-
require 'simplecov'
6-
SimpleCov.start
74

85

96
require 'minitest/autorun'
@@ -80,7 +77,7 @@ def default_distribution_name
8077

8178
# 跑完测试之后再发结果到Codelimate
8279
# 测试CODECLIMATE_REPO_TOKEN: c454b9a54151b3ed3e18949279aec49d6a25bf507706815f99a919f1c01679ed
83-
Minitest.after_run do
80+
Minitest.after_run do
8481
COVERAGE_FILE = "coverage/.resultset.json".freeze
8582
if (repo_token = ENV["CODECLIMATE_REPO_TOKEN"]) && !repo_token.empty?
8683
if File.exist?(COVERAGE_FILE)

0 commit comments

Comments
 (0)