lhj-tools 0.1.19 → 0.1.23

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: 705ada7bc27d0f1e46aa928ae8693dce2954ddb140159aac417f95347a5df1ae
4
- data.tar.gz: 8163156750c3e67b6b846d99438d0832ebddf8683849fff31a6ec91d42434ec3
3
+ metadata.gz: fdb58f24fe8dec97319d3dc8e8bbadffe0c05d79ec2ce4092e1e8b6eeabed65a
4
+ data.tar.gz: 3fe9ae37c1087b85b5aa7d6fbdf7e4017665843a148c040c2fc3a58bbcd4c382
5
5
  SHA512:
6
- metadata.gz: bc564c14c9b145457d14bb439fd6fd5d7455e4d6fbc46bc27e9017f87b94a37a508452c0b46d3cb4600419a47f131b136cf62a97148a6549b406cae1a16af4c8
7
- data.tar.gz: b4c03b76aaa34b4e1c6e01d058ccf59f2eb269705c05be7fc6b4fc4dbb7ffed0a148453b165092da58deeb4b0092c84488766fe9c71138110958179073b521ed
6
+ metadata.gz: 125b3650d4d7195b5a07569df7678f976094591292c4d9e5d961e4ccef588f29c6f62e4f7ddaebcdafb558d2f287b00170a0606f72b34b0fedfa0dd2979996e5
7
+ data.tar.gz: 95cf649f1f6cf458822bc7d7a9143be7bcc8b24f4da4dfdcc7a10e291d58d4e85d24bfff6e3a84f1178e68e547e04fca744d45480cf02da43a1e54c3b0237292
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
 
@@ -24,7 +24,7 @@ module Lhj
24
24
  when :release
25
25
  'release'
26
26
  when :gray
27
- 'release'
27
+ 'gray'
28
28
  else
29
29
  'uat'
30
30
  end
@@ -36,7 +36,9 @@ module Lhj
36
36
  changelog = Lhj::Actions.git_log_between(' %an, %ar - %s;', from, to, :exclude_merges, 'short', false)
37
37
  changelog ||= ''
38
38
  changelog&.gsub("\n\n", "\n")
39
- changelog.gsub('seconds ', '秒').gsub('minutes ', '分钟').gsub('hours ', '小时').gsub('days ', '天').gsub('ago ', '前')
39
+ changelog = changelog.gsub('seconds ', '秒').gsub('minutes ', '分钟').gsub('hours ', '小时').gsub('days ', '天').gsub('ago ', '前')
40
+ changelog = '此次打包没代码更新' if changelog.empty?
41
+ changelog
40
42
  end
41
43
 
42
44
  def save_last_commit_hash
@@ -54,7 +56,8 @@ module Lhj
54
56
  end
55
57
 
56
58
  def last_commit_file
57
- File.join(Lhj::Config.instance.home_dir, ".#{@branch}_last_commit")
59
+ file_name = @branch.gsub(%r{/}, '')
60
+ File.join(Lhj::Config.instance.home_dir, ".#{file_name}_last_commit")
58
61
  end
59
62
 
60
63
  def render_template
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lhj
4
4
  module Tools
5
- VERSION = "0.1.19"
5
+ VERSION = "0.1.23"
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.19
4
+ version: 0.1.23
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