• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / tigerdata-app / 0fa44f37-9401-471e-84d4-efbabcf424ab

22 Oct 2025 02:10PM UTC coverage: 91.212% (+0.2%) from 91.051%
0fa44f37-9401-471e-84d4-efbabcf424ab

push

circleci

web-flow
Getting rid of the New Project Wizard flipper (#2072)

3 of 4 new or added lines in 1 file covered. (75.0%)

794 existing lines in 41 files now uncovered.

2740 of 3004 relevant lines covered (91.21%)

751.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/app/models/version_footer.rb
1
# frozen_string_literal: true
2

3
# Retrieves version information from Capistrano's files. The general approach is
4
# to read the version information (branch name, git SHA, and date deployed) out
5
# of Capistrano's revisions.log file.
6
#
7
# The code is a bit more complicated than it should because Capistrano does not
8
# always update the revision.log file before the application reads this information.
9
# Therefore there is logic in this class to detect if the version information is
10
# stale and re-read it until it is up to date. Because re-reading this file is
11
# an expensive operation we cache the information as soon as we are sure it's
12
# current.
13
#
14
# rubocop:disable Style/ClassVars
15
class VersionFooter
6✔
16
  @@stale = true
6✔
17
  @@git_sha = nil
6✔
18
  @@branch = nil
6✔
19
  @@version = nil
6✔
20

21
  # Returns a hash with version information.
22
  def self.info
6✔
23
    reset! if stale?
425✔
24
    { sha: git_sha, branch:, version:, stale: stale?, tagged_release: tagged_release? }
423✔
25
  rescue StandardError => ex
UNCOV
26
    { error: "Error retrieving version information: #{ex.message}" }
2✔
27
  end
28

29
  def self.reset!
6✔
30
    # Initalize these values so that they recalculated
31
    @@git_sha = nil
441✔
32
    @@branch = nil
441✔
33
    @@version = nil
441✔
34
  end
35

36
  def self.stale?
6✔
37
    return false if @@stale == false
852✔
38
    # Only read the file when version information is stale
39
    if File.exist?(revision_file)
848✔
UNCOV
40
      local_sha = File.read(revision_file).chomp.gsub(/\)$/, "")
32✔
UNCOV
41
      @@stale = local_sha != git_sha
32✔
42
    else
43
      @@stale = true
816✔
44
    end
45
  end
46

47
  def self.git_sha
6✔
48
    @@git_sha ||= if File.exist?(revisions_logfile)
459✔
UNCOV
49
                    log_line(revisions_logfile).chomp.split(" ")[3].gsub(/\)$/, "")
12✔
50
                  elsif Rails.env.development? || Rails.env.test?
422✔
51
                    `git rev-parse HEAD`.chomp
420✔
52
                  else
UNCOV
53
                    "Unknown SHA"
2✔
54
                  end
55
  end
56

57
  def self.tagged_release?
6✔
58
    # e.g. v0.8.0
59
    branch.match(/^v[\d+\.+]+/) != nil
423✔
60
  end
61

62
  def self.branch
6✔
63
    @@branch ||= if File.exist?(revisions_logfile)
850✔
UNCOV
64
                   log_line(revisions_logfile).chomp.split(" ")[1]
6✔
65
                 elsif Rails.env.development? || Rails.env.test?
421✔
66
                   `git rev-parse --abbrev-ref HEAD`.chomp
419✔
67
                 else
UNCOV
68
                   "Unknown branch"
2✔
69
                 end
70
  end
71

72
  def self.version
6✔
73
    @@version ||= if File.exist?(revisions_logfile)
425✔
UNCOV
74
                    deployed = log_line(revisions_logfile).chomp.split(" ")[7]
6✔
UNCOV
75
                    Date.parse(deployed).strftime("%d %B %Y")
6✔
76
                  else
77
                    "Not in deployed environment"
419✔
78
                  end
79
  end
80

81
  # This file is local to the application.
82
  # This file only has the git SHA of the version deployed (i.e. no date or branch)
83
  def self.revision_file
6✔
84
    @@revision_file ||= Rails.root.join("REVISION")
880✔
85
  end
86

87
  # Capistrano keeps this file a couple of levels up _outside_ the application.
88
  # This file includes all the information that we need (git SHA, branch name, date)
89
  def self.revisions_logfile
6✔
90
    @@revisions_logfile ||= Rails.root.join("..", "..", "revisions.log")
1,310✔
91
  end
92

93
  # These assignment methods are needed to facilitate testing
94
  def self.revision_file=(x)
6✔
UNCOV
95
    @@stale = true
12✔
UNCOV
96
    @@revision_file = x
12✔
97
  end
98

99
  def self.revisions_logfile=(x)
6✔
UNCOV
100
    @@stale = true
20✔
UNCOV
101
    @@revisions_logfile = x
20✔
102
  end
103

104
  def self.log_line(revisions_logfile)
6✔
UNCOV
105
    log_line = `tail -1 #{revisions_logfile}`
22✔
UNCOV
106
    if log_line.include?("rolled back")
22✔
UNCOV
107
      grep_lines = `grep #{log_line.chomp.split(" ").last} #{revisions_logfile}`.split("\n")
6✔
UNCOV
108
      log_line = grep_lines.first
6✔
109
    end
UNCOV
110
    log_line
22✔
111
  end
112
end
113
# rubocop:enable RuboCop::Cop::Style::ClassVars
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc