Class: Lhj::LogHelper
- Inherits:
-
Object
- Object
- Lhj::LogHelper
- Defined in:
- lib/lhj/helper/log_helper.rb
Overview
log helper
Instance Attribute Summary collapse
-
#branch ⇒ Object
readonly
Returns the value of attribute branch.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#feature ⇒ Object
readonly
Returns the value of attribute feature.
-
#log ⇒ Object
readonly
Returns the value of attribute log.
Class Method Summary collapse
Instance Method Summary collapse
- #commit_log(env) ⇒ Object
- #current_branch(path) ⇒ Object
- #fetch_branch ⇒ Object
- #fetch_env(env) ⇒ Object
- #fetch_feature ⇒ Object
- #fetch_log ⇒ Object
- #handle_message(m) ⇒ Object
- #last_commit_file ⇒ Object
- #last_commit_hash ⇒ Object
- #render_with_template(template_name = 'git') ⇒ Object
- #save_last_commit_hash ⇒ Object
Instance Attribute Details
#branch ⇒ Object (readonly)
Returns the value of attribute branch.
7 8 9 |
# File 'lib/lhj/helper/log_helper.rb', line 7 def branch @branch end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
7 8 9 |
# File 'lib/lhj/helper/log_helper.rb', line 7 def env @env end |
#feature ⇒ Object (readonly)
Returns the value of attribute feature.
7 8 9 |
# File 'lib/lhj/helper/log_helper.rb', line 7 def feature @feature end |
#log ⇒ Object (readonly)
Returns the value of attribute log.
7 8 9 |
# File 'lib/lhj/helper/log_helper.rb', line 7 def log @log end |
Class Method Details
.instance ⇒ Object
9 10 11 |
# File 'lib/lhj/helper/log_helper.rb', line 9 def self.instance @instance ||= new end |
Instance Method Details
#commit_log(env) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/lhj/helper/log_helper.rb', line 13 def commit_log(env) @branch = fetch_branch @env = fetch_env(env) @log = fetch_log @feature = fetch_feature save_last_commit_hash render_with_template('git_commit_log') end |
#current_branch(path) ⇒ Object
27 28 29 30 |
# File 'lib/lhj/helper/log_helper.rb', line 27 def current_branch(path) name = Lhj::Actions.git_branch || '' name.split('/').last end |
#fetch_branch ⇒ Object
22 23 24 25 |
# File 'lib/lhj/helper/log_helper.rb', line 22 def fetch_branch name = Lhj::Actions.git_branch || '' name.split('/').last end |
#fetch_env(env) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/lhj/helper/log_helper.rb', line 36 def fetch_env(env) result = nil case env when :release result = 'release' when :gray result = 'gray' when :uat result = 'uat' end result end |
#fetch_feature ⇒ Object
32 33 34 |
# File 'lib/lhj/helper/log_helper.rb', line 32 def fetch_feature Lhj::GitBranchFeatureConfig.feature(@branch) end |
#fetch_log ⇒ Object
49 50 51 52 53 54 |
# File 'lib/lhj/helper/log_helper.rb', line 49 def fetch_log from = last_commit_hash to = 'HEAD' = Lhj::Actions.git_log_between(' %an %ar - %s;', from, to, :exclude_merges, 'short', false) () end |
#handle_message(m) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/lhj/helper/log_helper.rb', line 56 def (m) = m if !.nil? && !.empty? = .gsub('seconds ', '秒') = .gsub('minutes ', '分钟') = .gsub('hours ', '小时') = .gsub('weeks ', '周') = .gsub('days ', '天') = .gsub('ago ', '前') Lhj::TeamMemberConfig.config.each do |key, value| = .gsub(key, value) if =~ /#{key}/ end else = '此次打包没代码更新' end end |
#last_commit_file ⇒ Object
88 89 90 91 |
# File 'lib/lhj/helper/log_helper.rb', line 88 def last_commit_file branch_name = @branch.gsub(%r{/}, '') File.join(Lhj::Config.instance.home_dir, ".#{@env}_#{branch_name}_last_commit") end |
#last_commit_hash ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/lhj/helper/log_helper.rb', line 80 def last_commit_hash if File.exist?(last_commit_file) File.read(last_commit_file) else 'HEAD~3' end end |
#render_with_template(template_name = 'git') ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'lib/lhj/helper/log_helper.rb', line 93 def render_with_template(template_name = 'git') temp = Lhj::ErbTemplateHelper.load(template_name) vars = { branch: @branch, env: @env, feature: @feature, log: @log } Lhj::ErbTemplateHelper.render(temp, vars, '-') end |
#save_last_commit_hash ⇒ Object
74 75 76 77 78 |
# File 'lib/lhj/helper/log_helper.rb', line 74 def save_last_commit_hash last_commit_hash = Lhj::Actions.last_git_commit_hash(true) File.delete(last_commit_file) if File.exist?(last_commit_file) File.write(last_commit_file, last_commit_hash) end |