total refactor of version header. X-Git-Update: ISO 8601 formated date of the last commit, X-Git-Revision: sha1 hash of the last commit
This commit is contained in:
parent
e02c3eafc0
commit
feb47df97e
2 changed files with 17 additions and 29 deletions
|
|
@ -10,6 +10,7 @@ class ApplicationController < ActionController::Base
|
||||||
before_filter :count_requests
|
before_filter :count_requests
|
||||||
before_filter :set_invites
|
before_filter :set_invites
|
||||||
before_filter :set_locale
|
before_filter :set_locale
|
||||||
|
before_filter :set_git_header
|
||||||
before_filter :which_action_and_user
|
before_filter :which_action_and_user
|
||||||
prepend_before_filter :clear_gc_stats
|
prepend_before_filter :clear_gc_stats
|
||||||
|
|
||||||
|
|
@ -33,6 +34,11 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_git_header
|
||||||
|
headers['X-Git-Update'] = GIT_UPDATE unless GIT_UPDATE.nil?
|
||||||
|
headers['X-Git-Revision'] = GIT_REVISION unless GIT_REVISION.nil?
|
||||||
|
end
|
||||||
|
|
||||||
def which_action_and_user
|
def which_action_and_user
|
||||||
str = "event=request_with_user controller=#{self.class} action=#{self.action_name} "
|
str = "event=request_with_user controller=#{self.class} action=#{self.action_name} "
|
||||||
if current_user
|
if current_user
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,13 @@
|
||||||
#original from https://github.com/jopper/diaspora
|
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||||
#modified by David Morley
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
require 'time'
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
def last_modified
|
|
||||||
git_last='git log -1 --pretty=format:"%cd"'
|
|
||||||
filepath = Rails.root.join('tmp', '.last_pull')
|
|
||||||
time_min = 60
|
|
||||||
@header_name = "X-Git-Update"
|
|
||||||
if File.writable?(filepath)
|
|
||||||
begin
|
|
||||||
mtime = File.mtime(filepath)
|
|
||||||
last = IO.readlines(filepath).at(0)
|
|
||||||
rescue Exception => e
|
|
||||||
Rails.logger.info("Failed to read git status #{filepath}: #{e}")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if (mtime.nil? || mtime < Time.now-time_min)
|
|
||||||
last = `#{git_last}`
|
|
||||||
begin
|
|
||||||
f = File.open(filepath, 'w')
|
|
||||||
f.puts(last)
|
|
||||||
f.close
|
|
||||||
rescue Exception => e
|
|
||||||
Rails.logger.info("Failed to log git status #{filepath}: #{e}")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
last
|
|
||||||
headers[@header_name] = "#{last}"
|
|
||||||
end
|
|
||||||
|
|
||||||
|
git_cmd = `git log -1 --format="%H %ci"`
|
||||||
|
if git_cmd =~ /^([\d\w]+?)\s(.+)$/
|
||||||
|
GIT_REVISION = $1
|
||||||
|
GIT_UPDATE = $2.strip
|
||||||
|
else
|
||||||
|
GIT_REVISION = nil
|
||||||
|
GIT_UPDATE = nil
|
||||||
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue