lhj-tools 0.1.20 → 0.1.24

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: acfdd1c9835fbe98c0fb04ff0e7568fc8092afbb22561e80c8e7f4098be4a335
4
- data.tar.gz: cd973dbfdc90b223f5b281ef3e5979c83b7955b05c85414dc2fa6e68a5e83aab
3
+ metadata.gz: f8a3955d41955a54ce3ca861519c4333245dacd4c4b14477f73fc7061707c1f3
4
+ data.tar.gz: 630fc37529847a893022bd49226e2bd1bd44794f71618458d7e7620d3ad3f265
5
5
  SHA512:
6
- metadata.gz: a265f292ec0d52c699c53f5be1a3c757a3beeb5b827fd98ea102d2c80941cfbdef005e5fd04080130deca32ee6010d402f5b23f5042c8223079ce86cea132b7c
7
- data.tar.gz: d6a3dc3da4e9f486cc3c587938313dfdb0ead5cee8655c58ea142e8e021338dbb167803734373856617519ab3d88ad4e899c36190b5971757c24f13cbf27ecef
6
+ metadata.gz: 0e3c30af417e17bd237c0bc114ed48d8e9fd46e39263085ef1743398e702c510ee9bd5212eaa2e06446a659a33d47089fbdc865dfcf284307538b9b6edb5abc4
7
+ data.tar.gz: e0d7853fb9f18c5785fa570c3e23c212f29e5aa935fcf437224f0f9db24c03221e3ff88efa91c8a63eb6eac8057cba5bc4ef4a0d3c798057754482c50a2e6642
data/lib/lhj/env.rb ADDED
@@ -0,0 +1,9 @@
1
+ module Lhj
2
+ class Env
3
+ def self.truthy?(env)
4
+ return false unless ENV[env]
5
+ return false if ["no", "false", "off", "0"].include?(ENV[env].to_s)
6
+ return true
7
+ end
8
+ end
9
+ end
@@ -60,11 +60,11 @@ module Lhj
60
60
  return nil if last_git_commit_formatted_with('%an').nil?
61
61
 
62
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')
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
68
  }
69
69
  end
70
70
 
@@ -118,10 +118,15 @@ module Lhj
118
118
  # Returns the current git branch, or "HEAD" if it's not checked out to any branch
119
119
  # Can be replaced using the environment variable `GIT_BRANCH`
120
120
  def self.git_branch
121
- begin
122
- Actions.sh("git rev-parse --abbrev-ref HEAD", log: false).chomp
123
- rescue => err
124
- nil
121
+ env_name = SharedValues::GIT_BRANCH_ENV_VARS.find { |env_var| Lhj::Env.truthy?(env_var) }
122
+ ENV.fetch(env_name.to_s) do
123
+ # Rescues if not a git repo or no commits in a git repo
124
+ begin
125
+ Actions.sh("git rev-parse --abbrev-ref HEAD", log: false).chomp
126
+ rescue => err
127
+ UI.verbose("Error getting git branch: #{err.message}")
128
+ nil
129
+ end
125
130
  end
126
131
  end
127
132
 
@@ -1,3 +1,5 @@
1
+ require 'lhj/helper/team_member_config'
2
+
1
3
  module Lhj
2
4
  # log helper
3
5
  class LogHelper
@@ -16,7 +18,8 @@ module Lhj
16
18
  end
17
19
 
18
20
  def fetch_branch
19
- Lhj::Actions.git_branch || ''
21
+ name = Lhj::Actions.git_branch || ''
22
+ name.split('/').last
20
23
  end
21
24
 
22
25
  def fetch_env(env)
@@ -24,7 +27,7 @@ module Lhj
24
27
  when :release
25
28
  'release'
26
29
  when :gray
27
- 'release'
30
+ 'gray'
28
31
  else
29
32
  'uat'
30
33
  end
@@ -33,12 +36,25 @@ module Lhj
33
36
  def fetch_log
34
37
  from = last_commit_hash
35
38
  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
39
+ message = Lhj::Actions.git_log_between(' %an %ar - %s;', from, to, :exclude_merges, 'short', false)
40
+ handle_message(message)
41
+ end
42
+
43
+ def handle_message(m)
44
+ message = m
45
+ if !message.nil? && !message.empty?
46
+ message = message.gsub('seconds ', '秒')
47
+ message = message.gsub('minutes ', '分钟')
48
+ message = message.gsub('hours ', '小时')
49
+ message = message.gsub('days ', '天')
50
+ message = message.gsub('ago ', '前')
51
+ Lhj::TeamMemberConfig.config.each do |key, value|
52
+ message = message.gsub(key, value) if message =~ /#{key}/
53
+ end
54
+ else
55
+ message = '此次打包没代码更新'
56
+ end
57
+ message
42
58
  end
43
59
 
44
60
  def save_last_commit_hash
@@ -56,7 +72,8 @@ module Lhj
56
72
  end
57
73
 
58
74
  def last_commit_file
59
- File.join(Lhj::Config.instance.home_dir, ".#{@branch}_last_commit")
75
+ branch_name = @branch.gsub(%r{/}, '')
76
+ File.join(Lhj::Config.instance.home_dir, ".#{@env}_#{branch_name}_last_commit")
60
77
  end
61
78
 
62
79
  def render_template
@@ -16,16 +16,37 @@ module Lhj
16
16
  @yaml ||= YAML.load_file(config_file)
17
17
  end
18
18
 
19
- def self.api_key
20
- config['api_key']
19
+ def self.api_key(env = :uat)
20
+ case env
21
+ when :release
22
+ 'release.....'
23
+ when :gray
24
+ 'gray.....'
25
+ else
26
+ config['api_key']
27
+ end
21
28
  end
22
29
 
23
- def self.user_key
24
- config['user_key']
30
+ def self.user_key(env = :uat)
31
+ case env
32
+ when :release
33
+ config['user_key']
34
+ when :gray
35
+ config['user_key']
36
+ else
37
+ config['user_key']
38
+ end
25
39
  end
26
40
 
27
- def self.password
28
- config['password']
41
+ def self.password(env = :uat)
42
+ case env
43
+ when :release
44
+ config['password']
45
+ when :gray
46
+ config['password']
47
+ else
48
+ config['password']
49
+ end
29
50
  end
30
51
  end
31
52
  end
@@ -13,10 +13,10 @@ module Lhj
13
13
 
14
14
  attr_reader :api_key, :user_key, :password, :result
15
15
 
16
- def initialize
17
- @api_key = Lhj::PgyerConfig.api_key
18
- @user_key = Lhj::PgyerConfig.user_key
19
- @password = Lhj::PgyerConfig.password
16
+ def initialize(env = :uat)
17
+ @api_key = Lhj::PgyerConfig.api_key(env)
18
+ @user_key = Lhj::PgyerConfig.user_key(env)
19
+ @password = Lhj::PgyerConfig.password(env)
20
20
  @result = { 'data' => {} }
21
21
  end
22
22
 
@@ -39,7 +39,7 @@ module Lhj
39
39
  def upload_file(file, des)
40
40
 
41
41
  update_description = @result[:update_description]
42
- update_description = "" if update_description.nil?
42
+ update_description = '' if update_description.nil?
43
43
  params = {
44
44
  '_api_key' => @api_key,
45
45
  'uKey' => @user_key,
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ require 'yaml'
3
+ require 'lhj/config'
4
+
5
+ module Lhj
6
+ # team member config
7
+ class TeamMemberConfig
8
+
9
+ CONFIG_NAME = 'team_member.yml'
10
+
11
+ def self.config_file
12
+ File.join(Lhj::Config.instance.home_dir, CONFIG_NAME)
13
+ end
14
+
15
+ def self.config
16
+ @yaml ||= YAML.load_file(config_file)
17
+ end
18
+
19
+ end
20
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lhj
4
4
  module Tools
5
- VERSION = "0.1.20"
5
+ VERSION = "0.1.24"
6
6
  end
7
7
  end
data/lib/lhj/tools.rb CHANGED
@@ -3,6 +3,7 @@ require_relative "tools/version"
3
3
  require 'colored'
4
4
 
5
5
  module Lhj
6
+ require 'lhj/env'
6
7
  require 'lhj/ui/ui'
7
8
  require 'lhj/config'
8
9
  require 'lhj/helper/pgyer_helper'
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.20
4
+ version: 0.1.24
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-11 00:00:00.000000000 Z
11
+ date: 2022-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: claide
@@ -326,6 +326,7 @@ files:
326
326
  - lib/lhj/command/yapi/formatters/template/pgyer.erb
327
327
  - lib/lhj/command/yapi/formatters/template/yapi.erb
328
328
  - lib/lhj/config.rb
329
+ - lib/lhj/env.rb
329
330
  - lib/lhj/helper/dingtalk_config.rb
330
331
  - lib/lhj/helper/dingtalk_helper.rb
331
332
  - lib/lhj/helper/git_helper.rb
@@ -337,6 +338,7 @@ files:
337
338
  - lib/lhj/helper/pgyer_helper.rb
338
339
  - lib/lhj/helper/tb_config.rb
339
340
  - lib/lhj/helper/tb_helper.rb
341
+ - lib/lhj/helper/team_member_config.rb
340
342
  - lib/lhj/helper/trans_helper.rb
341
343
  - lib/lhj/tools.rb
342
344
  - lib/lhj/tools/version.rb