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

pulibrary / pdc_describe / 4e4e59fc-9df4-4838-9fd4-6c7ea33cdb7c

07 Apr 2025 06:36PM UTC coverage: 1.283% (-94.6%) from 95.862%
4e4e59fc-9df4-4838-9fd4-6c7ea33cdb7c

Pull #1994

circleci

hectorcorrea
Switched to use the autocomplete that we aleady use for ROR. Integrated it with the existing logic for creators
Pull Request #1994: Started adding auto complete to contributors

0 of 46 new or added lines in 2 files covered. (0.0%)

4806 existing lines in 74 files now uncovered.

65 of 5065 relevant lines covered (1.28%)

0.01 hits per line

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

0.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
UNCOV
15
class VersionFooter
×
UNCOV
16
  @@stale = true
×
UNCOV
17
  @@git_sha = nil
×
UNCOV
18
  @@branch = nil
×
UNCOV
19
  @@version = nil
×
20

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

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

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

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

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

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

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

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

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

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