Websites/app/logical/git_helper.rb

29 lines
552 B
Ruby
Raw Normal View History

2024-05-03 03:04:43 +00:00
# frozen_string_literal: true
module GitHelper
2024-08-06 10:28:38 +00:00
module_function
def init
2024-05-03 03:04:43 +00:00
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
2024-08-06 10:28:38 +00:00
def full_hash
@hash
end
def short_hash
2024-05-03 03:04:43 +00:00
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