Link to current commit in footer

This commit is contained in:
Max Wofford
2025-03-01 08:58:41 -06:00
parent 7d11ff71a2
commit b8a4f5e2b7
2 changed files with 12 additions and 4 deletions

View File

@@ -32,7 +32,8 @@
<footer>
<div class="container">
<p>
Build <%= Rails.application.config.git_version %> from <%= time_ago_in_words(Rails.application.config.server_start_time) %> ago.
Build <%= link_to Rails.application.config.git_version, Rails.application.config.commit_link %>
from <%= time_ago_in_words(Rails.application.config.server_start_time) %> ago.
<%= pluralize(Heartbeat.cached_recent_count, 'heartbeat') %> in the last 24 hours.
(DB: <%= pluralize(QueryCount::Counter.counter, "query") %>, <%= QueryCount::Counter.counter_cache %> cached)
(CACHE: <%= cache_stats[:hits] %> hits, <%= cache_stats[:misses] %> misses)

View File

@@ -1,15 +1,22 @@
# Get the first 6 characters of the current git commit hash
git_hash = ENV["SOURCE_COMMIT"]&.[](0..5) ||
`git rev-parse HEAD`.strip[0..5] rescue "unknown"
git_hash = ENV["SOURCE_COMMIT"] || `git rev-parse HEAD` rescue "unknown"
commit_link = git_hash != "unknown" ? "https://github.com/hackclub/harbor/commit/#{git_hash}" : nil
short_hash = git_hash[0..7]
commit_count = `git rev-list --count HEAD`.strip rescue 0
# Check if there are any uncommitted changes
is_dirty = `git status --porcelain`.strip.length > 0 rescue false
# Append "-dirty" if there are uncommitted changes
version = is_dirty ? "#{git_hash}-dirty" : git_hash
version = is_dirty ? "#{short_hash}-dirty" : short_hash
# Store server start time
Rails.application.config.server_start_time = Time.current
# Store the version
Rails.application.config.git_version = version
Rails.application.config.git_commit_count = commit_count
Rails.application.config.commit_link = commit_link