Websites/app/logical/git_helper.rb

23 lines
510 B
Ruby
Raw Normal View History

2024-05-03 03:04:43 +00:00
# frozen_string_literal: true
module GitHelper
def self.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 self.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