lhj-tools 0.1.16 → 0.1.20

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: 17511d36f2ccbd99a885442c54373a7a032cc014552855a33b2c326dccf34688
4
- data.tar.gz: ba65a5faa5f83e351935bdb7a7f0b221bd8ea405f1788acd2c29e85d2d0d6fe6
3
+ metadata.gz: acfdd1c9835fbe98c0fb04ff0e7568fc8092afbb22561e80c8e7f4098be4a335
4
+ data.tar.gz: cd973dbfdc90b223f5b281ef3e5979c83b7955b05c85414dc2fa6e68a5e83aab
5
5
  SHA512:
6
- metadata.gz: 4396cb85f10adeb732be7038d061b3188536e4a47113d5426ee9e2c02a35f4271562a2c6655c3c8773ec7633a976c9f51310a9640fca0a37b79848749cc9cf7a
7
- data.tar.gz: b401b9f5e196b7ed835bce7bb363876203b3f987b6314517b5f168b15d20d25cf64082b7b18ab3c2c1c10bffd12fa45100678234975a07f4160c1b5bbd476ed3
6
+ metadata.gz: a265f292ec0d52c699c53f5be1a3c757a3beeb5b827fd98ea102d2c80941cfbdef005e5fd04080130deca32ee6010d402f5b23f5042c8223079ce86cea132b7c
7
+ data.tar.gz: d6a3dc3da4e9f486cc3c587938313dfdb0ead5cee8655c58ea142e8e021338dbb167803734373856617519ab3d88ad4e899c36190b5971757c24f13cbf27ecef
@@ -119,17 +119,17 @@ module Lhj
119
119
 
120
120
  # Optional initial environment Hash
121
121
  if args.first.kind_of?(Hash)
122
- command = args.shift.map { |k, v| "#{k}=#{v.shellescape}" }.join(" ") + " "
122
+ command = args.shift.map { |k, v| "#{k}=#{v.to_s}" }.join(" ") + " "
123
123
  end
124
124
 
125
125
  # Support [ "/usr/local/bin/foo", "foo" ], "-x", ...
126
126
  if args.first.kind_of?(Array)
127
- command += args.shift.first.shellescape + " " + args.shelljoin
127
+ command += args.shift.first.to_s + " " + args.join(' ')
128
128
  command.chomp!(" ")
129
129
  elsif args.count == 1 && args.first.kind_of?(String)
130
130
  command += args.first
131
131
  else
132
- command += args.shelljoin
132
+ command += args.join(' ')
133
133
  end
134
134
 
135
135
  command
@@ -0,0 +1 @@
1
+ 【代码分支:<%= @branch %>】【服务环境:<%= @env %>】-【最近更新日志】<%= @log %>
data/lib/lhj/command.rb CHANGED
@@ -1,7 +1,5 @@
1
1
  require 'claide'
2
2
  require "tty-spinner"
3
- require 'lhj/action/sh_helper'
4
- require 'lhj/ui/ui'
5
3
 
6
4
  module Lhj
7
5
  # command plugin
data/lib/lhj/config.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'pathname'
2
+
1
3
  module Lhj
2
4
  # config
3
5
  class Config
@@ -0,0 +1,140 @@
1
+ module Lhj
2
+ module Actions
3
+ GIT_MERGE_COMMIT_FILTERING_OPTIONS = [:include_merges, :exclude_merges, :only_include_merges].freeze
4
+
5
+ module SharedValues
6
+ GIT_BRANCH_ENV_VARS = %w(GIT_BRANCH BRANCH_NAME TRAVIS_BRANCH BITRISE_GIT_BRANCH CI_BUILD_REF_NAME CI_COMMIT_REF_NAME WERCKER_GIT_BRANCH BUILDKITE_BRANCH APPCENTER_BRANCH).freeze
7
+ end
8
+
9
+ def self.git_log_between(pretty_format, from, to, merge_commit_filtering, date_format = nil, ancestry_path)
10
+ command = %w(git log)
11
+ command << "--pretty=#{pretty_format}"
12
+ command << "--date=#{date_format}" if date_format
13
+ command << '--ancestry-path' if ancestry_path
14
+ command << "#{from}...#{to}"
15
+ command << git_log_merge_commit_filtering_option(merge_commit_filtering)
16
+ # "*command" syntax expands "command" array into variable arguments, which
17
+ # will then be individually shell-escaped by Actions.sh.
18
+ Actions.sh(*command.compact, log: false).chomp
19
+ rescue
20
+ nil
21
+ end
22
+
23
+ def self.git_log_last_commits(pretty_format, commit_count, merge_commit_filtering, date_format = nil, ancestry_path)
24
+ command = %w(git log)
25
+ command << "--pretty=#{pretty_format}"
26
+ command << "--date=#{date_format}" if date_format
27
+ command << '--ancestry-path' if ancestry_path
28
+ command << '-n' << commit_count.to_s
29
+ command << git_log_merge_commit_filtering_option(merge_commit_filtering)
30
+ Actions.sh(*command.compact, log: false).chomp
31
+ rescue
32
+ nil
33
+ end
34
+
35
+ def self.last_git_tag_hash(tag_match_pattern = nil)
36
+ tag_pattern_param = tag_match_pattern ? "=#{tag_match_pattern}" : ''
37
+ Actions.sh('git', 'rev-list', "--tags#{tag_pattern_param}", '--max-count=1').chomp
38
+ rescue
39
+ nil
40
+ end
41
+
42
+ def self.last_git_tag_name(match_lightweight = true, tag_match_pattern = nil)
43
+ hash = last_git_tag_hash(tag_match_pattern)
44
+ # If hash is nil (command fails), "git describe" command below will still
45
+ # run and provide some output, although it's definitely not going to be
46
+ # anything reasonably expected. Bail out early.
47
+ return unless hash
48
+
49
+ command = %w(git describe)
50
+ command << '--tags' if match_lightweight
51
+ command << hash
52
+ command << '--match' if tag_match_pattern
53
+ command << tag_match_pattern if tag_match_pattern
54
+ Actions.sh(*command.compact, log: false).chomp
55
+ rescue
56
+ nil
57
+ end
58
+
59
+ def self.last_git_commit_dict
60
+ return nil if last_git_commit_formatted_with('%an').nil?
61
+
62
+ {
63
+ author: last_git_commit_formatted_with('%an'),
64
+ author_email: last_git_commit_formatted_with('%ae'),
65
+ message: last_git_commit_formatted_with('%B'),
66
+ commit_hash: last_git_commit_formatted_with('%H'),
67
+ abbreviated_commit_hash: last_git_commit_formatted_with('%h')
68
+ }
69
+ end
70
+
71
+ # Gets the last git commit information formatted into a String by the provided
72
+ # pretty format String. See the git-log documentation for valid format placeholders
73
+ def self.last_git_commit_formatted_with(pretty_format, date_format = nil)
74
+ command = %w(git log -1)
75
+ command << "--pretty=#{pretty_format}"
76
+ command << "--date=#{date_format}" if date_format
77
+ Actions.sh(*command.compact, log: false).chomp
78
+ rescue
79
+ nil
80
+ end
81
+
82
+ # @deprecated Use <tt>git_author_email</tt> instead
83
+ # Get the author email of the last git commit
84
+ # <b>DEPRECATED:</b> Use <tt>git_author_email</tt> instead.
85
+ def self.git_author
86
+ UI.deprecated('`git_author` is deprecated. Please use `git_author_email` instead.')
87
+ git_author_email
88
+ end
89
+
90
+ # Get the author email of the last git commit
91
+ def self.git_author_email
92
+ s = last_git_commit_formatted_with('%ae')
93
+ return s if s.to_s.length > 0
94
+ return nil
95
+ end
96
+
97
+ # Returns the unwrapped subject and body of the last commit
98
+ # <b>DEPRECATED:</b> Use <tt>last_git_commit_message</tt> instead.
99
+ def self.last_git_commit
100
+ last_git_commit_message
101
+ end
102
+
103
+ # Returns the unwrapped subject and body of the last commit
104
+ def self.last_git_commit_message
105
+ s = (last_git_commit_formatted_with('%B') || "").strip
106
+ return s if s.to_s.length > 0
107
+ nil
108
+ end
109
+
110
+ # Get the hash of the last commit
111
+ def self.last_git_commit_hash(short)
112
+ format_specifier = short ? '%h' : '%H'
113
+ string = last_git_commit_formatted_with(format_specifier).to_s
114
+ return string unless string.empty?
115
+ return nil
116
+ end
117
+
118
+ # Returns the current git branch, or "HEAD" if it's not checked out to any branch
119
+ # Can be replaced using the environment variable `GIT_BRANCH`
120
+ def self.git_branch
121
+ begin
122
+ Actions.sh("git rev-parse --abbrev-ref HEAD", log: false).chomp
123
+ rescue => err
124
+ nil
125
+ end
126
+ end
127
+
128
+ private_class_method
129
+ def self.git_log_merge_commit_filtering_option(merge_commit_filtering)
130
+ case merge_commit_filtering
131
+ when :exclude_merges
132
+ "--no-merges"
133
+ when :only_include_merges
134
+ "--merges"
135
+ when :include_merges
136
+ nil
137
+ end
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,68 @@
1
+ module Lhj
2
+ # log helper
3
+ class LogHelper
4
+ attr_reader :branch, :env, :log
5
+
6
+ def self.instance
7
+ @instance ||= new
8
+ end
9
+
10
+ def commit_log(env)
11
+ @branch = fetch_branch
12
+ @env = fetch_env(env)
13
+ @log = fetch_log
14
+ save_last_commit_hash
15
+ render_template
16
+ end
17
+
18
+ def fetch_branch
19
+ Lhj::Actions.git_branch || ''
20
+ end
21
+
22
+ def fetch_env(env)
23
+ case env
24
+ when :release
25
+ 'release'
26
+ when :gray
27
+ 'release'
28
+ else
29
+ 'uat'
30
+ end
31
+ end
32
+
33
+ def fetch_log
34
+ from = last_commit_hash
35
+ to = 'HEAD'
36
+ changelog = Lhj::Actions.git_log_between(' %an, %ar - %s;', from, to, :exclude_merges, 'short', false)
37
+ changelog ||= ''
38
+ changelog&.gsub("\n\n", "\n")
39
+ changelog = changelog.gsub('seconds ', '秒').gsub('minutes ', '分钟').gsub('hours ', '小时').gsub('days ', '天').gsub('ago ', '前')
40
+ changelog = '此次打包没代码更新' if changelog.empty?
41
+ changelog
42
+ end
43
+
44
+ def save_last_commit_hash
45
+ last_commit_hash = Lhj::Actions.last_git_commit_hash(true)
46
+ File.delete(last_commit_file) if File.exist?(last_commit_file)
47
+ File.write(last_commit_file, last_commit_hash)
48
+ end
49
+
50
+ def last_commit_hash
51
+ if File.exist?(last_commit_file)
52
+ File.read(last_commit_file)
53
+ else
54
+ 'HEAD~3'
55
+ end
56
+ end
57
+
58
+ def last_commit_file
59
+ File.join(Lhj::Config.instance.home_dir, ".#{@branch}_last_commit")
60
+ end
61
+
62
+ def render_template
63
+ temp_str = File.read(File.join(Lhj::Config.instance.home_dir, 'git.erb'))
64
+ Lhj::ErbFormatter::Service.new(self).render_template(temp_str)
65
+ end
66
+
67
+ end
68
+ end
@@ -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
@@ -36,6 +37,9 @@ module Lhj
36
37
  end
37
38
 
38
39
  def upload_file(file, des)
40
+
41
+ update_description = @result[:update_description]
42
+ update_description = "" if update_description.nil?
39
43
  params = {
40
44
  '_api_key' => @api_key,
41
45
  'uKey' => @user_key,
@@ -48,7 +52,10 @@ module Lhj
48
52
  puts 'begin upload'
49
53
  response = http_client.post API_HOST, params
50
54
  @result = response.body
51
- puts ''
55
+ puts @result
56
+ if @result['data'] && @result['data']['appUpdateDescription']
57
+ @result['data']['appUpdateDescription'] = Lhj::TbHelper.trans_tb(@result['data']['appUpdateDescription'])
58
+ end
52
59
  rescue Faraday::TimeoutError
53
60
  puts 'upload fail'
54
61
  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.16"
5
+ VERSION = "0.1.20"
6
6
  end
7
7
  end
data/lib/lhj/tools.rb CHANGED
@@ -3,9 +3,14 @@ require_relative "tools/version"
3
3
  require 'colored'
4
4
 
5
5
  module Lhj
6
+ require 'lhj/ui/ui'
6
7
  require 'lhj/config'
7
8
  require 'lhj/helper/pgyer_helper'
8
9
  require 'lhj/helper/dingtalk_helper'
10
+ require 'lhj/helper/tb_helper'
11
+ require 'lhj/action/sh_helper'
12
+ require 'lhj/helper/git_helper'
13
+ require 'lhj/helper/log_helper'
9
14
 
10
15
  class Error < StandardError; end
11
16
 
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.16
4
+ version: 0.1.20
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
@@ -301,13 +321,16 @@ files:
301
321
  - lib/lhj/command/yapi/formatters/base.rb
302
322
  - lib/lhj/command/yapi/formatters/command_context.rb
303
323
  - lib/lhj/command/yapi/formatters/service.rb
324
+ - lib/lhj/command/yapi/formatters/template/git.erb
304
325
  - lib/lhj/command/yapi/formatters/template/model.erb
305
326
  - lib/lhj/command/yapi/formatters/template/pgyer.erb
306
327
  - lib/lhj/command/yapi/formatters/template/yapi.erb
307
328
  - lib/lhj/config.rb
308
329
  - lib/lhj/helper/dingtalk_config.rb
309
330
  - lib/lhj/helper/dingtalk_helper.rb
331
+ - lib/lhj/helper/git_helper.rb
310
332
  - lib/lhj/helper/local_config.rb
333
+ - lib/lhj/helper/log_helper.rb
311
334
  - lib/lhj/helper/oss_config.rb
312
335
  - lib/lhj/helper/oss_helper.rb
313
336
  - lib/lhj/helper/pgyer_config.rb