Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
galaxyproject
GitHub Repository: galaxyproject/training-material
Path: blob/main/_plugins/gtn/git.rb
1677 views
1
# frozen_string_literal: true
2
3
require 'jekyll'
4
require 'time'
5
6
module Gtn
7
# Parse the git repo to get some facts
8
module Git
9
def self.cache
10
@@cache ||= Jekyll::Cache.new('Git')
11
end
12
13
##
14
# Discover git-related facts and ensure they're cached
15
# Params:
16
# +site+:: The +Jekyll::Site+ object
17
# Returns:
18
# +Hash+:: A hash of git facts like the current revision, tags, etc.
19
def self.discover
20
cache.getset('facts') do
21
_discover
22
end
23
end
24
25
def self._discover
26
# Cache the git facts
27
28
begin
29
git_head = File.read(File.join('.git', 'HEAD')).strip.split[1]
30
git_head_ref = File.read(File.join('.git', git_head)).strip
31
rescue StandardError
32
git_head_ref = 'none'
33
end
34
35
begin
36
tags = `git tag -l`.strip.split.sort
37
rescue StandardError
38
tags = []
39
end
40
41
first_commit = Date.parse('2015-06-29')
42
today = Date.today
43
44
{
45
'git_revision' => git_head_ref,
46
'git_revision_short' => git_head_ref[0..6],
47
'gtn_fork' => ENV.fetch('GTN_FORK', 'galaxyproject'),
48
'git_tags' => tags,
49
'git_tags_recent' => tags.reverse[0..2],
50
'age' => (today - first_commit).to_f / 365.25,
51
'founding_date' => first_commit,
52
}
53
end
54
end
55
end
56
57