Skip to content

Commit

Permalink
Merge pull request #2915 from bgeuken/maintenance_stats_
Browse files Browse the repository at this point in the history
Maintenance stats for remote projects
  • Loading branch information
bgeuken committed Apr 4, 2017
2 parents 658f1e9 + 78b8993 commit 0523386
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
@@ -1,12 +1,25 @@
module Statistics
class MaintenanceStatisticsController < ApplicationController
skip_before_action :extract_user
skip_before_action :extract_user, :require_login

def index
@project = Project.get_by_name(params[:project])
@maintenance_statistics = MaintenanceStatisticDecorator.wrap(
MaintenanceStatistic.find_by_project(@project)
)
if @project.is_a?(String)
# FIXME: This could be simplified by redirecting to the remote instead
remote_instance, remote_project = Project.find_remote_project(@project)
remote_response = ActiveXML.backend.load_external_url(
"#{remote_instance.remoteurl}#{maintenance_statistics_path(project: remote_project)}"
)
if remote_response
render xml: remote_response
else
render_error status: 404, errorcode: 'remote_project', message: "Project '#{@project}' not found"
end
else
@maintenance_statistics = MaintenanceStatisticDecorator.wrap(
MaintenanceStatistic.find_by_project(@project)
)
end
end
end
end
4 changes: 3 additions & 1 deletion src/api/config/routes.rb
Expand Up @@ -517,7 +517,9 @@ def self.public_or_about_path?(request)
get 'statistics/latest_built' => :latest_built

get 'statistics/active_request_creators/:project' => :active_request_creators, constraints: cons
get 'statistics/maintenance_statistics/:project' => 'statistics/maintenance_statistics#index', constraints: cons
get 'statistics/maintenance_statistics/:project' => 'statistics/maintenance_statistics#index', constraints: cons,
as: 'maintenance_statistics'
get 'public/statistics/maintenance_statistics/:project' => 'statistics/maintenance_statistics#index', constraints: cons
end

### /status_message
Expand Down
Expand Up @@ -8,7 +8,6 @@

context 'and no access restrictions' do
before do
login(user)
get :index, params: { format: :xml, project: project.name }
end

Expand Down Expand Up @@ -38,6 +37,25 @@
assert_response :not_found
end
end

context 'with a remote project' do
let(:remote) { create(:remote_project) }

it 'forwards the request to the remote instance' do
get :index, params: { format: :xml, project: "#{remote}:my_project" }
expect(a_request(:get, maintenance_statistics_url(host: remote.remoteurl, project: 'my_project')
)).to have_been_made.once
end

it 'responds with the xml received from the remote instance' do
stub_request(:get, maintenance_statistics_url(host: remote.remoteurl, project: 'my_project')).
to_return(status: 200, body: '<received><xml/></received>')

get :index, params: { format: :xml, project: "#{remote}:my_project" }
expect(response).to have_http_status(:success)
expect(Xmlhash.parse(response.body)).to eq('xml' => {})
end
end
end

context 'with no project existing' do
Expand Down

0 comments on commit 0523386

Please sign in to comment.