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

pulibrary / pdc_describe / 7031ff5b-e2d7-4285-af8b-e7b55adfc48a

pending completion
7031ff5b-e2d7-4285-af8b-e7b55adfc48a

Pull #899

circleci

mccalluc
Finish removal of explicit if-then in js
Pull Request #899: Move messages up to sidebar on the right which can be toggled

1623 of 1788 relevant lines covered (90.77%)

105.5 hits per line

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

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

21
  # Returns a hash with version information.
22
  def self.info
1✔
23
    reset! if stale?
156✔
24
    { sha: git_sha, branch: branch, version: version, stale: stale?, tagged_release: tagged_release? }
156✔
25
  end
26

27
  def self.reset!
1✔
28
    # Initalize these values so that they recalculated
29
    @@git_sha = nil
156✔
30
    @@branch = nil
156✔
31
    @@version = nil
156✔
32
  end
33

34
  def self.stale?
1✔
35
    return false if @@stale == false
312✔
36
    # Only read the file when version information is stale
37
    if File.exist?(revision_file)
312✔
38
      local_sha = File.read(revision_file).chomp.gsub(/\)$/, "")
×
39
      @@stale = local_sha != git_sha
×
40
    else
41
      @@stale = true
312✔
42
    end
43
  end
44

45
  def self.git_sha
1✔
46
    @@git_sha ||= if File.exist?(revisions_logfile)
156✔
47
                    `tail -1 #{revisions_logfile}`.chomp.split(" ")[3].gsub(/\)$/, "")
×
48
                  elsif Rails.env.development? || Rails.env.test?
156✔
49
                    `git rev-parse HEAD`.chomp
156✔
50
                  else
51
                    "Unknown SHA"
×
52
                  end
53
  end
54

55
  def self.tagged_release?
1✔
56
    # e.g. v0.8.0
57
    branch.match(/^v[\d+\.+]+/) != nil
156✔
58
  end
59

60
  def self.branch
1✔
61
    @@branch ||= if File.exist?(revisions_logfile)
312✔
62
                   `tail -1 #{revisions_logfile}`.chomp.split(" ")[1]
×
63
                 elsif Rails.env.development? || Rails.env.test?
156✔
64
                   `git rev-parse --abbrev-ref HEAD`.chomp
156✔
65
                 else
66
                   "Unknown branch"
×
67
                 end
68
  end
69

70
  def self.version
1✔
71
    @@version ||= if File.exist?(revisions_logfile)
156✔
72
                    deployed = `tail -1 #{revisions_logfile}`.chomp.split(" ")[7]
×
73
                    Date.parse(deployed).strftime("%d %B %Y")
×
74
                  else
75
                    "Not in deployed environment"
156✔
76
                  end
77
  end
78

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

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

91
  # These assignment methods are needed to facilitate testing
92
  def self.revision_file=(x)
1✔
93
    @@stale = true
×
94
    @@revision_file = x
×
95
  end
96

97
  def self.revisions_logfile=(x)
1✔
98
    @@stale = true
×
99
    @@revisions_logfile = x
×
100
  end
101
end
102
# 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