work in progress, admin page for upgrades (provides source lives in git)
This commit is contained in:
parent
3473734af0
commit
932c2675a7
|
@ -0,0 +1,20 @@
|
||||||
|
# EXPERIMENTAL: front end for upgrading your instance using the web UI
|
||||||
|
|
||||||
|
class Admin::UpgradeController < Admin::AdminController
|
||||||
|
|
||||||
|
before_filter :ensure_admin
|
||||||
|
skip_before_filter :check_xhr
|
||||||
|
|
||||||
|
layout 'no_js'
|
||||||
|
|
||||||
|
def index
|
||||||
|
require_dependency 'upgrade/git_repo'
|
||||||
|
@main_repo = Upgrade::GitRepo.new(Rails.root)
|
||||||
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
def ensure_admin
|
||||||
|
raise Discourse::InvalidAccess.new unless current_user.admin?
|
||||||
|
end
|
||||||
|
end
|
Binary file not shown.
|
@ -0,0 +1,10 @@
|
||||||
|
<% if repo.valid? %>
|
||||||
|
Current version: <%= repo.latest_local_commit %> (<%= time_ago_in_words repo.latest_local_commit_date %> ago),
|
||||||
|
Remote version: <a href="<%= repo.url %>"><%= repo.latest_origin_commit %></a> (<%= time_ago_in_words repo.latest_origin_commit_date %> ago)
|
||||||
|
<% if repo.commits_behind > 0 %>
|
||||||
|
commits behind: <%= repo.commits_behind %>
|
||||||
|
<button action="">upgrade</button>
|
||||||
|
<% end %>
|
||||||
|
<% else %>
|
||||||
|
Not under source control.
|
||||||
|
<% end %>
|
|
@ -0,0 +1,18 @@
|
||||||
|
<h2>Discourse</h2>
|
||||||
|
<p>
|
||||||
|
<%= render partial: 'git_status', locals: {repo: @main_repo} %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>Plugins</h2>
|
||||||
|
<ul>
|
||||||
|
<% Discourse.plugins.each do |plugin| %>
|
||||||
|
<li>
|
||||||
|
<%= plugin.name %> -
|
||||||
|
<%= render partial: 'git_status', locals: {repo: Upgrade::GitRepo.new(File.dirname(plugin.path))} %>
|
||||||
|
</li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h2>Processes</h2>
|
||||||
|
|
||||||
|
<h2>Log</h2>
|
|
@ -21,6 +21,7 @@ Discourse::Application.routes.draw do
|
||||||
namespace :admin, constraints: StaffConstraint.new do
|
namespace :admin, constraints: StaffConstraint.new do
|
||||||
get '' => 'admin#index'
|
get '' => 'admin#index'
|
||||||
|
|
||||||
|
|
||||||
resources :site_settings, constraints: AdminConstraint.new
|
resources :site_settings, constraints: AdminConstraint.new
|
||||||
|
|
||||||
get 'reports/:type' => 'reports#show'
|
get 'reports/:type' => 'reports#show'
|
||||||
|
@ -96,7 +97,10 @@ Discourse::Application.routes.draw do
|
||||||
delete 'key' => 'api#revoke_key'
|
delete 'key' => 'api#revoke_key'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
get 'upgrade' => 'upgrade#index'
|
||||||
|
|
||||||
|
end # admin namespace
|
||||||
|
|
||||||
get 'email_preferences' => 'email#preferences_redirect', :as => 'email_preferences_redirect'
|
get 'email_preferences' => 'email#preferences_redirect', :as => 'email_preferences_redirect'
|
||||||
get 'email/unsubscribe/:key' => 'email#unsubscribe', as: 'email_unsubscribe'
|
get 'email/unsubscribe/:key' => 'email#unsubscribe', as: 'email_unsubscribe'
|
||||||
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
module Upgrade; end
|
||||||
|
|
||||||
|
# like Grit just very very minimal
|
||||||
|
class Upgrade::GitRepo
|
||||||
|
attr_reader :path
|
||||||
|
|
||||||
|
def initialize(path)
|
||||||
|
@path = path
|
||||||
|
@memoize = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
def valid?
|
||||||
|
File.directory?("#{path}/.git")
|
||||||
|
end
|
||||||
|
|
||||||
|
def latest_local_commit
|
||||||
|
run "rev-parse --short HEAD"
|
||||||
|
end
|
||||||
|
|
||||||
|
def latest_origin_commit
|
||||||
|
run "rev-parse --short #{tracking_branch}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def latest_origin_commit_date
|
||||||
|
commit_date(latest_origin_commit)
|
||||||
|
end
|
||||||
|
|
||||||
|
def latest_local_commit_date
|
||||||
|
commit_date(latest_local_commit)
|
||||||
|
end
|
||||||
|
|
||||||
|
def commits_behind
|
||||||
|
run("rev-list --count #{tracking_branch}..HEAD").to_i
|
||||||
|
end
|
||||||
|
|
||||||
|
def url
|
||||||
|
url = run "config --get remote.origin.url"
|
||||||
|
if url =~ /^git/
|
||||||
|
# hack so it works with git urls
|
||||||
|
url = "https://github.com/#{url.split(":")[1]}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
def commit_date(commit)
|
||||||
|
unix_timestamp = run('show -s --format="%ct" ' << commit).to_i
|
||||||
|
Time.at(unix_timestamp).to_datetime
|
||||||
|
end
|
||||||
|
|
||||||
|
def tracking_branch
|
||||||
|
run "for-each-ref --format='%(upstream:short)' $(git symbolic-ref -q HEAD)"
|
||||||
|
end
|
||||||
|
|
||||||
|
def ensure_updated
|
||||||
|
@updated ||= Thread.new do
|
||||||
|
# this is a very slow operation, make it async
|
||||||
|
`cd #{path} && git remote update`
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def run(cmd)
|
||||||
|
ensure_updated
|
||||||
|
@memoize[cmd] ||= `cd #{path} && git #{cmd}`.strip
|
||||||
|
rescue => e
|
||||||
|
p e
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
Loading…
Reference in New Issue