lhj-tools 0.1.17 → 0.1.21

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d279af86ce6121812a429c8a66a5ed03aedbcd73920ced2ebe44626faf93874b
4
- data.tar.gz: 9ac889862bddcf8a55fc8798baf6c7e4a5f8a88d4bdd22d3a14f7212b8826331
3
+ metadata.gz: 5d54687e0ef1aa1c34630063f84c35e517de500cedf0f33f28029e0c7f025d59
4
+ data.tar.gz: eb96a26b4f8ade67457eee980d7f5c0f0c0dc0c3bc881b970898fb8e5c864cca
5
5
  SHA512:
6
- metadata.gz: f4b04462de1a18640901b53f7ead9047ed7f2013e2cdc52682369bbd6a176426886d9f314b0caa6efcbb047ef41502a68751ba61459f263060c12ac8bfc9a983
7
- data.tar.gz: d4f4c30604e837e07c374e491f9416db1f41bada18a62c6090c993a606953826a1f16051e8a9e32fd053e8ee29cc6f1db1b76cd22775520ce5cc25afd3d96bd8
6
+ metadata.gz: b281d02e9d3aa94b134dd1f11b7073c5e340d618c512e136eb53a94e14e151a716b68d4bc9117194688624d3c8bdf4d1604d17fa175b9f2b29fb09951f0a31bf
7
+ data.tar.gz: 12b78a7a8bab022741a0f756858dab5230de0d0f9bf7f09d4e1f4c765096b150e53a8ead7df8c0052d9de68758510d12fcade268bfa0e3d8ecae642ff746f0a5
@@ -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
@@ -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
+ 'gray'
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.17"
5
+ VERSION = "0.1.21"
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.17
4
+ version: 0.1.21
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