lhj-tools 0.1.17 → 0.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d279af86ce6121812a429c8a66a5ed03aedbcd73920ced2ebe44626faf93874b
4
- data.tar.gz: 9ac889862bddcf8a55fc8798baf6c7e4a5f8a88d4bdd22d3a14f7212b8826331
3
+ metadata.gz: d246c747ed42f7359b79c279b864539a2d318b744f68994a015960d9abff5d20
4
+ data.tar.gz: 58f16be0521a715eb2c8d16928f3f7818009272b1150e58fbad3ee56ca62388b
5
5
  SHA512:
6
- metadata.gz: f4b04462de1a18640901b53f7ead9047ed7f2013e2cdc52682369bbd6a176426886d9f314b0caa6efcbb047ef41502a68751ba61459f263060c12ac8bfc9a983
7
- data.tar.gz: d4f4c30604e837e07c374e491f9416db1f41bada18a62c6090c993a606953826a1f16051e8a9e32fd053e8ee29cc6f1db1b76cd22775520ce5cc25afd3d96bd8
6
+ metadata.gz: 8e71dbbe12bd70a4a42323d30ef9c40cee0c7cab5834273ca1359241df01fd3875a63a06419a398e91625184e93cb62893567fc5ecdbbb9f021acb95536eef62
7
+ data.tar.gz: 5f6514ecff7d90d4e4e0d5132abde517fdcd8bb36dc800fcd9eda7ea74e5da5ac0be6f1b04cd97321fc62974a3bc27079b2eaaaad0d55e9ba041294953b2d2f2
@@ -3,6 +3,7 @@ require 'faraday_middleware'
3
3
  require 'lhj/helper/pgyer_config'
4
4
  require 'lhj/command/yapi/formatters/service'
5
5
  require 'lhj/config'
6
+ require_relative 'tb_config'
6
7
 
7
8
  module Lhj
8
9
  # pgyer upload
@@ -48,7 +49,10 @@ module Lhj
48
49
  puts 'begin upload'
49
50
  response = http_client.post API_HOST, params
50
51
  @result = response.body
51
- puts ''
52
+ puts @result
53
+ if @result['data'] && @result['data']['appUpdateDescription']
54
+ @result['data']['appUpdateDescription'] = Lhj::TbHelper.trans_tb(@result['data']['appUpdateDescription'])
55
+ end
52
56
  rescue Faraday::TimeoutError
53
57
  puts 'upload fail'
54
58
  end
@@ -1,7 +1,54 @@
1
1
  require 'lhj/helper/tb_config'
2
+ require 'jwt'
3
+ require 'net/http'
4
+ require 'uri'
5
+ require 'json'
2
6
 
3
7
  module Lhj
4
- # pgyer upload
5
- class Tb
8
+ # tb upload
9
+ class TbHelper
10
+
11
+ SEARCH_API_URL = 'https://open.teambition.com/api/task/tqlsearch'.freeze
12
+
13
+ def self.trans_tb(note)
14
+ str = note
15
+ if /#.+#/ =~ note
16
+ note.scan(/#[^#]+#/) do |m|
17
+ res_body = req_with_task(m.match(/\d+/)[0])
18
+ if res_body['code'].to_i == 200
19
+ url_str = "[#{res_body['result'][0]['content']}](https://www.teambition.com/task/#{res_body['result'][0]['taskId']})"
20
+ str = str.gsub(m, url_str)
21
+ end
22
+ end
23
+ end
24
+ str
25
+ end
26
+
27
+ def self.req_with_task(id)
28
+ now = Time.now.to_i
29
+ payload = {
30
+ _appId: Lhj::TBConfig.tb_app_id,
31
+ iat: now,
32
+ exp: now + 3600
33
+ }
34
+ token = JWT.encode(payload, Lhj::TBConfig.tb_app_key)
35
+
36
+ url = URI(SEARCH_API_URL)
37
+ https = Net::HTTP.new(url.host, url.port)
38
+ https.use_ssl = true
39
+
40
+ request = Net::HTTP::Post.new(url)
41
+ request['authorization'] = "Bearer #{token}"
42
+ request['x-tenant-id'] = Lhj::TBConfig.tb_tenant_id
43
+ request['x-tenant-type'] = 'organization'
44
+ request['Content-Type'] = 'application/json'
45
+ req_body = {
46
+ "tql": "projectId=#{Lhj::TBConfig.projectId} AND uniqueId=#{id}"
47
+ }
48
+ request.body = JSON.dump(req_body)
49
+
50
+ response = https.request(request)
51
+ JSON.parse(response.read_body)
52
+ end
6
53
  end
7
54
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lhj
4
4
  module Tools
5
- VERSION = "0.1.17"
5
+ VERSION = "0.1.18"
6
6
  end
7
7
  end
data/lib/lhj/tools.rb CHANGED
@@ -6,6 +6,7 @@ module Lhj
6
6
  require 'lhj/config'
7
7
  require 'lhj/helper/pgyer_helper'
8
8
  require 'lhj/helper/dingtalk_helper'
9
+ require 'lhj/helper/tb_helper'
9
10
 
10
11
  class Error < StandardError; end
11
12
 
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.1.17
4
+ version: 0.1.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - lihaijian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-10 00:00:00.000000000 Z
11
+ date: 2022-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: claide
@@ -262,6 +262,26 @@ dependencies:
262
262
  - - "<"
263
263
  - !ruby/object:Gem::Version
264
264
  version: 3.0.0
265
+ - !ruby/object:Gem::Dependency
266
+ name: jwt
267
+ requirement: !ruby/object:Gem::Requirement
268
+ requirements:
269
+ - - ">="
270
+ - !ruby/object:Gem::Version
271
+ version: 2.1.0
272
+ - - "<"
273
+ - !ruby/object:Gem::Version
274
+ version: '3'
275
+ type: :runtime
276
+ prerelease: false
277
+ version_requirements: !ruby/object:Gem::Requirement
278
+ requirements:
279
+ - - ">="
280
+ - !ruby/object:Gem::Version
281
+ version: 2.1.0
282
+ - - "<"
283
+ - !ruby/object:Gem::Version
284
+ version: '3'
265
285
  description: lhj tools.
266
286
  email:
267
287
  - sanan.li@qq.com