lhj-tools 0.1.21 → 0.1.22

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: 5d54687e0ef1aa1c34630063f84c35e517de500cedf0f33f28029e0c7f025d59
4
- data.tar.gz: eb96a26b4f8ade67457eee980d7f5c0f0c0dc0c3bc881b970898fb8e5c864cca
3
+ metadata.gz: 5d0b9e563d0ebfe15b800560545a987a274f9787522297f7721b2012ff132594
4
+ data.tar.gz: 61655a300019b6dc713a71053482ba03c5ac2bee09ccc4be8c3926217a38dada
5
5
  SHA512:
6
- metadata.gz: b281d02e9d3aa94b134dd1f11b7073c5e340d618c512e136eb53a94e14e151a716b68d4bc9117194688624d3c8bdf4d1604d17fa175b9f2b29fb09951f0a31bf
7
- data.tar.gz: 12b78a7a8bab022741a0f756858dab5230de0d0f9bf7f09d4e1f4c765096b150e53a8ead7df8c0052d9de68758510d12fcade268bfa0e3d8ecae642ff746f0a5
6
+ metadata.gz: 8e56808aae097aa5aaab4204aae1ea2bce2306c0aa8607be0d0ec57046c44c98576aa3d1a4c8313792f0764e37dfa0c7dd6d70f02a084fd7ea4eb3ef79ecd82d
7
+ data.tar.gz: 88c51758d568b44ad2ea8bcd4bae0572ade581ee87a146100afa9cfce6f53665dd2bd9a864e531f4b50b9d3b8af2c89236d2c406a142ac1dd1935b61339d08fa
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
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lhj
4
4
  module Tools
5
- VERSION = "0.1.21"
5
+ VERSION = "0.1.22"
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,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.21
4
+ version: 0.1.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - lihaijian
@@ -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