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

pulibrary / tigerdata-app / 16b23f14-3e1e-48ae-8a18-2f6e85dad22f

27 Oct 2025 09:13PM UTC coverage: 91.159% (-0.2%) from 91.325%
16b23f14-3e1e-48ae-8a18-2f6e85dad22f

Pull #2061

circleci

web-flow
Merge branch 'main' into i1986-scroll-bar
Pull Request #2061: Remove black fill treatment from scroll bar

2753 of 3020 relevant lines covered (91.16%)

374.31 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
5✔
16
  @@stale = true
5✔
17
  @@git_sha = nil
5✔
18
  @@branch = nil
5✔
19
  @@version = nil
5✔
20

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

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

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

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

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

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

72
  def self.version
5✔
73
    @@version ||= if File.exist?(revisions_logfile)
213✔
74
                    deployed = log_line(revisions_logfile).chomp.split(" ")[7]
3✔
75
                    Date.parse(deployed).strftime("%d %B %Y")
3✔
76
                  else
77
                    "Not in deployed environment"
210✔
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
5✔
84
    @@revision_file ||= Rails.root.join("REVISION")
447✔
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
5✔
90
    @@revisions_logfile ||= Rails.root.join("..", "..", "revisions.log")
657✔
91
  end
92

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

99
  def self.revisions_logfile=(x)
5✔
100
    @@stale = true
10✔
101
    @@revisions_logfile = x
10✔
102
  end
103

104
  def self.log_line(revisions_logfile)
5✔
105
    log_line = `tail -1 #{revisions_logfile}`
11✔
106
    if log_line.include?("rolled back")
11✔
107
      grep_lines = `grep #{log_line.chomp.split(" ").last} #{revisions_logfile}`.split("\n")
3✔
108
      log_line = grep_lines.first
3✔
109
    end
110
    log_line
11✔
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