require 'jekyll'
require 'time'
module Gtn
module Git
def self.cache
@@cache ||= Jekyll::Cache.new('Git')
end
def self.discover
cache.getset('facts') do
_discover
end
end
def self._discover
begin
git_head = File.read(File.join('.git', 'HEAD')).strip.split[1]
git_head_ref = File.read(File.join('.git', git_head)).strip
rescue StandardError
git_head_ref = 'none'
end
begin
tags = `git tag -l`.strip.split.sort
rescue StandardError
tags = []
end
first_commit = Date.parse('2015-06-29')
today = Date.today
{
'git_revision' => git_head_ref,
'git_revision_short' => git_head_ref[0..6],
'gtn_fork' => ENV.fetch('GTN_FORK', 'galaxyproject'),
'git_tags' => tags,
'git_tags_recent' => tags.reverse[0..2],
'age' => (today - first_commit).to_f / 365.25,
'founding_date' => first_commit,
}
end
end
end