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.
-
#log ⇒ Object
readonly
Returns the value of attribute log.
Class Method Summary collapse
Instance Method Summary collapse
- #commit_log(env) ⇒ Object
- #fetch_branch ⇒ Object
- #fetch_env(env) ⇒ Object
- #fetch_log ⇒ Object
- #last_commit_file ⇒ Object
- #last_commit_hash ⇒ Object
- #render_template ⇒ Object
- #save_last_commit_hash ⇒ Object
Instance Attribute Details
#branch ⇒ Object (readonly)
Returns the value of attribute branch.
4 5 6 |
# File 'lib/lhj/helper/log_helper.rb', line 4 def branch @branch end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
4 5 6 |
# File 'lib/lhj/helper/log_helper.rb', line 4 def env @env end |
#log ⇒ Object (readonly)
Returns the value of attribute log.
4 5 6 |
# File 'lib/lhj/helper/log_helper.rb', line 4 def log @log end |
Class Method Details
.instance ⇒ Object
6 7 8 |
# File 'lib/lhj/helper/log_helper.rb', line 6 def self.instance @instance ||= new end |
Instance Method Details
#commit_log(env) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/lhj/helper/log_helper.rb', line 10 def commit_log(env) @branch = fetch_branch @env = fetch_env(env) @log = fetch_log save_last_commit_hash render_template end |
#fetch_branch ⇒ Object
18 19 20 |
# File 'lib/lhj/helper/log_helper.rb', line 18 def fetch_branch Lhj::Actions.git_branch || '' end |
#fetch_env(env) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/lhj/helper/log_helper.rb', line 22 def fetch_env(env) case env when :release 'release' when :gray 'gray' else 'uat' end end |
#fetch_log ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/lhj/helper/log_helper.rb', line 33 def fetch_log from = last_commit_hash to = 'HEAD' changelog = Lhj::Actions.git_log_between(' %an, %ar - %s;', from, to, :exclude_merges, 'short', false) changelog ||= '' changelog&.gsub("\n\n", "\n") changelog = changelog.gsub('seconds ', '秒').gsub('minutes ', '分钟').gsub('hours ', '小时').gsub('days ', '天').gsub('ago ', '前') changelog = '此次打包没代码更新' if changelog.empty? changelog end |
#last_commit_file ⇒ Object
58 59 60 |
# File 'lib/lhj/helper/log_helper.rb', line 58 def last_commit_file File.join(Lhj::Config.instance.home_dir, ".#{@branch}_last_commit") end |
#last_commit_hash ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/lhj/helper/log_helper.rb', line 50 def last_commit_hash if File.exist?(last_commit_file) File.read(last_commit_file) else 'HEAD~3' end end |
#render_template ⇒ Object
62 63 64 65 |
# File 'lib/lhj/helper/log_helper.rb', line 62 def render_template temp_str = File.read(File.join(Lhj::Config.instance.home_dir, 'git.erb')) Lhj::ErbFormatter::Service.new(self).render_template(temp_str) end |
#save_last_commit_hash ⇒ Object
44 45 46 47 48 |
# File 'lib/lhj/helper/log_helper.rb', line 44 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 |