lhj-tools 0.2.28 → 0.2.30
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lhj/command/jenkins/jenkins_build.rb +34 -8
- data/lib/lhj/command/sync_dingding_user.rb +102 -0
- data/lib/lhj/command.rb +1 -0
- data/lib/lhj/helper/dingtalk_helper.rb +26 -0
- data/lib/lhj/helper/ios_robot_config.rb +4 -0
- data/lib/lhj/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae6bcde0c99a1c742822422b22d335bb35e625ca22c130e723b629d8f6c12f69
|
4
|
+
data.tar.gz: 220c7ccb8444a7abe26d2b21932ac693a8bda79878a1f93372329affc3deb388
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd3bddad4d8039ad9b23ed3f93e231b475b73e7b989782a92235f069861d889214b458fb232a5915feef3984b0ed219217b0f7857be0d3cee89d16a19e1e6bad
|
7
|
+
data.tar.gz: 9ff1a4b6b2d89c31b14d5a1a7ff99d1c7f1c97085f7374eb169da3953a791053cb7af962efa90594d2ed138f6c03b6b0237bcc94bf8583a6e19ce5a28134889a
|
@@ -30,15 +30,41 @@ module Lhj
|
|
30
30
|
super
|
31
31
|
end
|
32
32
|
|
33
|
+
def add_device(udid, name)
|
34
|
+
post_data = {
|
35
|
+
'data' => {
|
36
|
+
'attributes' => {
|
37
|
+
'name' => name,
|
38
|
+
'platform' => 'IOS',
|
39
|
+
'udid' => udid
|
40
|
+
},
|
41
|
+
'type' => 'devices'
|
42
|
+
}
|
43
|
+
}
|
44
|
+
res = Lhj::ConnectAPI.post('https://api.appstoreconnect.apple.com/v1/devices', post_data)
|
45
|
+
puts res.body
|
46
|
+
end
|
47
|
+
|
33
48
|
def handle
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
49
|
+
file = File.join(Lhj::Config.instance.home_dir, 'all_device.txt')
|
50
|
+
File.open(file, 'r+') do |f|
|
51
|
+
f.each_line do |line|
|
52
|
+
ma = line.match(/(?<device>[^\s]*)(\s*)(?<name>.*)/)
|
53
|
+
device = ma[:device]
|
54
|
+
name = ma[:name].gsub(/(\S*)\s(\S*)\s(.*)/, '\\1-\\2-\\3')
|
55
|
+
name = name.gsub(/\s/, '')
|
56
|
+
add_device(device, name)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# api = Lhj::YapiHelper.new(project_id: 694, interface_id: 70595, model_name: 'Order', model_pre: 'AA')
|
61
|
+
# api.process
|
62
|
+
# file_list = api.save_to_file
|
63
|
+
# key = Lhj::IOSRobotConfig.app_key
|
64
|
+
# secret = Lhj::IOSRobotConfig.app_secret
|
65
|
+
# conversation_id = 'cid31Wevlrdq9L4Q0WugLb0tw=='
|
66
|
+
# user_ids = []
|
67
|
+
# file_list.each { |f| Lhj::Dingtalk.upload_file_and_notify(key, secret, f, conversation_id, user_ids) }
|
42
68
|
|
43
69
|
#
|
44
70
|
#
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'lhj/config'
|
2
|
+
require 'highline'
|
3
|
+
|
4
|
+
module Lhj
|
5
|
+
class Command
|
6
|
+
# sync code to pod
|
7
|
+
class SyncDingdingUser < Command
|
8
|
+
self.summary = '同步dingding_user'
|
9
|
+
|
10
|
+
def handle
|
11
|
+
sync_data
|
12
|
+
end
|
13
|
+
|
14
|
+
def sync_data
|
15
|
+
key = Lhj::IOSRobotConfig.app_key
|
16
|
+
secret = Lhj::IOSRobotConfig.app_secret
|
17
|
+
token = Lhj::Dingtalk.get_token(key, secret)
|
18
|
+
handle_dept(token, nil)
|
19
|
+
end
|
20
|
+
|
21
|
+
def handle_dept(token, dept_id)
|
22
|
+
dept_array = fetch_department(token, dept_id)
|
23
|
+
dept_array.each do |d|
|
24
|
+
dept_json = { 'dept_id' => d['dept_id'], 'name' => d['name'], 'parent_id' => d['parent_id'] }.to_json
|
25
|
+
save_dept(dept_json)
|
26
|
+
user_ids = fetch_user_ids(token, d['dept_id'])
|
27
|
+
user_ids.each do |id|
|
28
|
+
user = fetch_user_info(token, id)
|
29
|
+
user_json = { 'avatar' => user['avatar'],
|
30
|
+
'dept_id' => d['dept_id'],
|
31
|
+
'email' => user['email'],
|
32
|
+
'job_number' => user['job_number'],
|
33
|
+
'mobile' => user['mobile'],
|
34
|
+
'name' => user['name'],
|
35
|
+
'telephone' => user['telephone'],
|
36
|
+
'title' => user['title'],
|
37
|
+
'unionid' => user['unionid'],
|
38
|
+
'userid' => user['userid'],
|
39
|
+
'work_place' => user['work_place'] }.to_json
|
40
|
+
save_user(user_json)
|
41
|
+
end
|
42
|
+
handle_dept(token, d['dept_id'])
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def fetch_department(token, dept_id)
|
47
|
+
url = URI("https://oapi.dingtalk.com/topapi/v2/department/listsub?access_token=#{token}")
|
48
|
+
https = Net::HTTP.new(url.host, url.port)
|
49
|
+
https.use_ssl = true
|
50
|
+
request = Net::HTTP::Post.new(url)
|
51
|
+
request['Content-Type'] = 'application/json'
|
52
|
+
request.body = { 'dept_id' => dept_id }.to_json if dept_id
|
53
|
+
response = https.request(request)
|
54
|
+
res_json = JSON.parse(response.body)
|
55
|
+
res_json['result']
|
56
|
+
end
|
57
|
+
|
58
|
+
def fetch_user_ids(token, dept_id)
|
59
|
+
url = URI("https://oapi.dingtalk.com/topapi/user/listid?access_token=#{token}")
|
60
|
+
https = Net::HTTP.new(url.host, url.port)
|
61
|
+
https.use_ssl = true
|
62
|
+
request = Net::HTTP::Post.new(url)
|
63
|
+
request['Content-Type'] = 'application/json'
|
64
|
+
request.body = { 'dept_id' => dept_id }.to_json if dept_id
|
65
|
+
response = https.request(request)
|
66
|
+
res_json = JSON.parse(response.body)
|
67
|
+
res_json['result']['userid_list']
|
68
|
+
end
|
69
|
+
|
70
|
+
def fetch_user_info(token, user_id)
|
71
|
+
url = URI("https://oapi.dingtalk.com/topapi/v2/user/get?access_token=#{token}")
|
72
|
+
https = Net::HTTP.new(url.host, url.port)
|
73
|
+
https.use_ssl = true
|
74
|
+
request = Net::HTTP::Post.new(url)
|
75
|
+
request['Content-Type'] = 'application/json'
|
76
|
+
request.body = { 'userid' => user_id }.to_json
|
77
|
+
response = https.request(request)
|
78
|
+
res_json = JSON.parse(response.body)
|
79
|
+
res_json['result']
|
80
|
+
end
|
81
|
+
|
82
|
+
def save_dept(json)
|
83
|
+
url = URI("#{Lhj::IOSRobotConfig.base_url}/dept/create")
|
84
|
+
http = Net::HTTP.new(url.host, url.port)
|
85
|
+
request = Net::HTTP::Post.new(url)
|
86
|
+
request['Content-Type'] = 'application/json'
|
87
|
+
request.body = json
|
88
|
+
http.request(request)
|
89
|
+
end
|
90
|
+
|
91
|
+
def save_user(json)
|
92
|
+
url = URI("#{Lhj::IOSRobotConfig.base_url}/user/create")
|
93
|
+
http = Net::HTTP.new(url.host, url.port)
|
94
|
+
request = Net::HTTP::Post.new(url)
|
95
|
+
request['Content-Type'] = 'application/json'
|
96
|
+
request.body = json
|
97
|
+
http.request(request)
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
data/lib/lhj/command.rb
CHANGED
@@ -241,5 +241,31 @@ module Lhj
|
|
241
241
|
send_group_message(token, msg_body) if msg_body
|
242
242
|
end
|
243
243
|
|
244
|
+
def self.update_file_with_api(conversation_id, upload_file, user_ids)
|
245
|
+
key = Lhj::IOSRobotConfig.app_key
|
246
|
+
secret = Lhj::IOSRobotConfig.app_secret
|
247
|
+
upload_file_and_notify(key, secret, upload_file, conversation_id, user_ids)
|
248
|
+
end
|
249
|
+
|
250
|
+
def self.send_markdown_message_with_api(conversation_id, title, markdown, user_ids)
|
251
|
+
key = Lhj::IOSRobotConfig.app_key
|
252
|
+
secret = Lhj::IOSRobotConfig.app_secret
|
253
|
+
token = get_token(key, secret)
|
254
|
+
msg_key = 'sampleMarkdown'
|
255
|
+
msg_param = sample_markdown_param(title, markdown)
|
256
|
+
msg_body = group_message_body(key, conversation_id, user_ids, msg_key, msg_param)
|
257
|
+
send_group_message(token, msg_body)
|
258
|
+
end
|
259
|
+
|
260
|
+
def self.send_text_message_with_api(conversation_id, content, user_ids)
|
261
|
+
key = Lhj::IOSRobotConfig.app_key
|
262
|
+
secret = Lhj::IOSRobotConfig.app_secret
|
263
|
+
token = get_token(key, secret)
|
264
|
+
msg_key = 'sampleText'
|
265
|
+
msg_param = sample_text_param(content)
|
266
|
+
msg_body = group_message_body(key, conversation_id, user_ids, msg_key, msg_param)
|
267
|
+
send_group_message(token, msg_body)
|
268
|
+
end
|
269
|
+
|
244
270
|
end
|
245
271
|
end
|
data/lib/lhj/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lhj-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.30
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- lihaijian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: xcodeproj
|
@@ -371,6 +371,7 @@ files:
|
|
371
371
|
- lib/lhj/command/refactor_rename.rb
|
372
372
|
- lib/lhj/command/rename_image.rb
|
373
373
|
- lib/lhj/command/reverse_import.rb
|
374
|
+
- lib/lhj/command/sync_dingding_user.rb
|
374
375
|
- lib/lhj/command/sync_pod_code.rb
|
375
376
|
- lib/lhj/command/sync_pod_repo.rb
|
376
377
|
- lib/lhj/command/sync_pod_version.rb
|