lhj-tools 0.1.18 → 0.1.19

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: d246c747ed42f7359b79c279b864539a2d318b744f68994a015960d9abff5d20
4
- data.tar.gz: 58f16be0521a715eb2c8d16928f3f7818009272b1150e58fbad3ee56ca62388b
3
+ metadata.gz: 705ada7bc27d0f1e46aa928ae8693dce2954ddb140159aac417f95347a5df1ae
4
+ data.tar.gz: 8163156750c3e67b6b846d99438d0832ebddf8683849fff31a6ec91d42434ec3
5
5
  SHA512:
6
- metadata.gz: 8e71dbbe12bd70a4a42323d30ef9c40cee0c7cab5834273ca1359241df01fd3875a63a06419a398e91625184e93cb62893567fc5ecdbbb9f021acb95536eef62
7
- data.tar.gz: 5f6514ecff7d90d4e4e0d5132abde517fdcd8bb36dc800fcd9eda7ea74e5da5ac0be6f1b04cd97321fc62974a3bc27079b2eaaaad0d55e9ba041294953b2d2f2
6
+ metadata.gz: bc564c14c9b145457d14bb439fd6fd5d7455e4d6fbc46bc27e9017f87b94a37a508452c0b46d3cb4600419a47f131b136cf62a97148a6549b406cae1a16af4c8
7
+ data.tar.gz: b4c03b76aaa34b4e1c6e01d058ccf59f2eb269705c05be7fc6b4fc4dbb7ffed0a148453b165092da58deeb4b0092c84488766fe9c71138110958179073b521ed
@@ -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,66 @@
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.gsub('seconds ', '秒').gsub('minutes ', '分钟').gsub('hours ', '小时').gsub('days ', '天').gsub('ago ', '前')
40
+ end
41
+
42
+ def save_last_commit_hash
43
+ last_commit_hash = Lhj::Actions.last_git_commit_hash(true)
44
+ File.delete(last_commit_file) if File.exist?(last_commit_file)
45
+ File.write(last_commit_file, last_commit_hash)
46
+ end
47
+
48
+ def last_commit_hash
49
+ if File.exist?(last_commit_file)
50
+ File.read(last_commit_file)
51
+ else
52
+ 'HEAD~3'
53
+ end
54
+ end
55
+
56
+ def last_commit_file
57
+ File.join(Lhj::Config.instance.home_dir, ".#{@branch}_last_commit")
58
+ end
59
+
60
+ def render_template
61
+ temp_str = File.read(File.join(Lhj::Config.instance.home_dir, 'git.erb'))
62
+ Lhj::ErbFormatter::Service.new(self).render_template(temp_str)
63
+ end
64
+
65
+ end
66
+ end
@@ -37,6 +37,9 @@ module Lhj
37
37
  end
38
38
 
39
39
  def upload_file(file, des)
40
+
41
+ update_description = @result[:update_description]
42
+ update_description = "" if update_description.nil?
40
43
  params = {
41
44
  '_api_key' => @api_key,
42
45
  'uKey' => @user_key,
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lhj
4
4
  module Tools
5
- VERSION = "0.1.18"
5
+ VERSION = "0.1.19"
6
6
  end
7
7
  end
data/lib/lhj/tools.rb CHANGED
@@ -3,10 +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'
9
10
  require 'lhj/helper/tb_helper'
11
+ require 'lhj/action/sh_helper'
12
+ require 'lhj/helper/git_helper'
13
+ require 'lhj/helper/log_helper'
10
14
 
11
15
  class Error < StandardError; end
12
16
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhj-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.18
4
+ version: 0.1.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - lihaijian
@@ -321,13 +321,16 @@ files:
321
321
  - lib/lhj/command/yapi/formatters/base.rb
322
322
  - lib/lhj/command/yapi/formatters/command_context.rb
323
323
  - lib/lhj/command/yapi/formatters/service.rb
324
+ - lib/lhj/command/yapi/formatters/template/git.erb
324
325
  - lib/lhj/command/yapi/formatters/template/model.erb
325
326
  - lib/lhj/command/yapi/formatters/template/pgyer.erb
326
327
  - lib/lhj/command/yapi/formatters/template/yapi.erb
327
328
  - lib/lhj/config.rb
328
329
  - lib/lhj/helper/dingtalk_config.rb
329
330
  - lib/lhj/helper/dingtalk_helper.rb
331
+ - lib/lhj/helper/git_helper.rb
330
332
  - lib/lhj/helper/local_config.rb
333
+ - lib/lhj/helper/log_helper.rb
331
334
  - lib/lhj/helper/oss_config.rb
332
335
  - lib/lhj/helper/oss_helper.rb
333
336
  - lib/lhj/helper/pgyer_config.rb