Websites/app/logical/git_helper.rb

29 lines
552 B
Ruby

# frozen_string_literal: true
module GitHelper
module_function
def init
if Rails.root.join("REVISION").exist?
@hash = Rails.root.join("REVISION").read.strip
elsif system("type git > /dev/null && git rev-parse --show-toplevel > /dev/null")
@hash = `git rev-parse HEAD`.strip
else
@hash = nil
end
end
def full_hash
@hash
end
def short_hash
return nil if @hash.nil?
@hash[0..8]
end
def self.commit_url(commit_hash)
"#{Websites.config.source_code_url}/commit/#{commit_hash}"
end
end