Skip to content

Commit

Permalink
[frontend] Adapt references to classes of OBS Factory code
Browse files Browse the repository at this point in the history
Some of the name where clashing with some global ones. Now we prepend
the name of the module and the global accessor. Also some unused code,
controller and old routes were removed.
  • Loading branch information
Moises Deniz Aleman authored and David Kang committed Jun 21, 2018
1 parent a2b7c83 commit f77d0e4
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 123 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module ObsFactory
module Webui::ObsFactory
class ApplicationController < ::Webui::WebuiController
layout 'obs_factory/application'
layout 'webui/obs_factory/application'

rescue_from ObsFactory::OpenqaApi::OpenqaFailure do |ex|
rescue_from ::ObsFactory::OpenqaApi::OpenqaFailure do |ex|
render text: "failure in openQA"
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,19 @@
module ObsFactory
module Webui::ObsFactory
class DistributionsController < ApplicationController
respond_to :html

before_action :require_distribution, :require_dashboard

def require_distribution
@distribution = Distribution.find(params[:project])
unless @distribution
redirect_to main_app.root_path, flash: { error: "#{params[:project]} is not a valid openSUSE distribution, can't offer dashboard" }
end
end

def require_dashboard
if @distribution.staging_projects.empty?
redirect_to main_app.root_path, flash: { error: "#{params[:project]} does not offer a dashboard" }
end
end

def show
@staging_projects = StagingProjectPresenter.sort(@distribution.staging_projects)
@staging_projects = ::ObsFactory::StagingProjectPresenter.sort(@distribution.staging_projects)
@versions = { source: @distribution.source_version,
totest: @distribution.totest_version,
published: @distribution.published_version }
@ring_prjs = ObsProjectPresenter.wrap(@distribution.ring_projects)
@standard = ObsProjectPresenter.new(@distribution.standard_project)
@ring_prjs = ::ObsFactory::ObsProjectPresenter.wrap(@distribution.ring_projects)
@standard = ::ObsFactory::ObsProjectPresenter.new(@distribution.standard_project)
@live = @distribution.live_project
@live = ObsProjectPresenter.new(@live) unless @live.nil?
@images = ObsProjectPresenter.new(@distribution.images_project)
@live = ::ObsFactory::ObsProjectPresenter.new(@live) unless @live.nil?
@images = ::ObsFactory::ObsProjectPresenter.new(@distribution.images_project)
@openqa_jobs = @distribution.openqa_jobs_for(:totest)
calculate_reviews
# For the breadcrumbs
Expand All @@ -43,5 +30,20 @@ def calculate_reviews
@reviews[:legal_team] = @distribution.requests_with_reviews_for_group('legal-team').size
@reviews[:repo_checker] = @distribution.requests_with_reviews_for_user('repo-checker').size
end

private

def require_distribution
@distribution = ::ObsFactory::Distribution.find(params[:project])
unless @distribution
redirect_to main_app.root_path, flash: { error: "#{params[:project]} is not a valid openSUSE distribution, can't offer dashboard" }
end
end

def require_dashboard
if @distribution.staging_projects.empty?
redirect_to main_app.root_path, flash: { error: "#{params[:project]} does not offer a dashboard" }
end
end
end
end

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
module ObsFactory
module Webui::ObsFactory
class StagingProjectsController < ApplicationController
respond_to :json, :html

before_action :require_distribution

def require_distribution
@distribution = Distribution.find(params[:project])
unless @distribution
redirect_to main_app.root_path, flash: { error: "#{params[:project]} is not a valid openSUSE distribution, can't offer dashboard" }
end
end
before_action :require_project_name, only: [:show]

def index
respond_to do |format|
format.html do
@staging_projects = StagingProjectPresenter.sort(@distribution.staging_projects_all)
@backlog_requests = Request.with_open_reviews_for(by_group: @distribution.staging_manager, target_project: @distribution.name)
@requests_state_new = Request.in_state_new(by_group: @distribution.staging_manager, target_project: @distribution.name)
@staging_projects = ::ObsFactory::StagingProjectPresenter.sort(@distribution.staging_projects_all)
@backlog_requests = ::ObsFactory::Request.with_open_reviews_for(by_group: @distribution.staging_manager, target_project: @distribution.name)
@requests_state_new = ::ObsFactory::Request.in_state_new(by_group: @distribution.staging_manager, target_project: @distribution.name)
file = PackageFile.new(
project_name: "#{params[:project]}:Staging",
package_name: "dashboard",
Expand All @@ -41,24 +35,31 @@ def index
end
end

before_action :require_id, only: [:show]

def require_id
@staging_project = StagingProject.find(@distribution, params[:id])
unless @staging_project
redirect_to main_app.root_path, flash: { error: "#{params[:id]} is not a valid staging project" }
end
end

def show
respond_to do |format|
format.html do
@staging_project = StagingProjectPresenter.new(@staging_project)
@staging_project = ::ObsFactory::StagingProjectPresenter.new(@staging_project)
# For the breadcrumbs
@project = @distribution.project
end
format.json { render json: @staging_project }
end
end

private

def require_distribution
@distribution = ::ObsFactory::Distribution.find(params[:project])
unless @distribution
redirect_to main_app.root_path, flash: { error: "#{params[:project]} is not a valid openSUSE distribution, can't offer dashboard" }
end
end

def require_project_name
@staging_project = ::ObsFactory::StagingProject.find(@distribution, params[:project_name])
unless @staging_project
redirect_to main_app.root_path, flash: { error: "#{params[:project_name]} is not a valid staging project" }
end
end
end
end
19 changes: 2 additions & 17 deletions src/api/app/helpers/webui/obs_factory/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
module ObsFactory
module ApplicationHelper

# Catch some url helpers used in the OBS layout and forward them to
# the main application
%w(home_path user_tasks_path root_path project_show_path search_path user_show_url user_show_path
user_register_user_path news_feed_path project_toggle_watch_path
project_list_public_path monitor_path projects_path new_project_path
user_rss_notifications_url session_new_path session_create_path session_destroy_path).each do |m|
define_method(m) do |*args|
main_app.send(m, *args)
end
end

module Webui::ObsFactory::ApplicationHelper
def openqa_links_helper
OpenqaJob.openqa_links_url
ObsFactory::OpenqaJob.openqa_links_url
end

end
end
47 changes: 18 additions & 29 deletions src/api/app/models/obs_factory/distribution.rb
Original file line number Diff line number Diff line change
@@ -1,35 +1,21 @@
require 'open-uri'

module ObsFactory

class UnknownDistribution < Exception
end

# A Distribution. Contains a reference to the corresponding Project object.
class Distribution
include ActiveModel::Model
extend ActiveModel::Naming
extend Forwardable

SOURCE_VERSION_FILE = "000product/openSUSE.product"
RINGS_PREFIX = ":Rings"

attr_accessor :project, :strategy

def distribution_strategy_for_project(project)
s = case project.name
when 'openSUSE:Factory' then DistributionStrategyFactory.new
when 'openSUSE:Factory:PowerPC' then DistributionStrategyFactoryPPC.new
when /^openSUSE:.*/ then DistributionStrategyOpenSUSE.new
when /^SUSE:SLE-12-SP\d:GA/ then DistributionStrategySLE12SP1.new
when /^SUSE:SLE-15:GA/ then DistributionStrategySLE15.new
when /^SUSE:SLE-12-SP.*CASP\d*/ then DistributionStrategyCasp.new
else raise UnknownDistribution
end
s.project = project
s
end

def initialize(project = nil)
self.project = project
self.strategy = distribution_strategy_for_project(project)
Expand Down Expand Up @@ -117,18 +103,6 @@ def staging_projects_all
@staging_projects ||= StagingProject.for(self, false)
end

# Staging project associated to the distribution and with the given id
#
# @param [String] id of the staging project
# @return [StagingProject] the associated project or nil
def staging_project(id)
if @staging_projects
@staging_projects.select {|p| p.id == id }
else
StagingProject.find(self, id)
end
end

# Version of the distribution used as source
#
# @return [String] version string
Expand Down Expand Up @@ -231,5 +205,20 @@ def openqa_filter(project)
return strategy.openqa_filter(project)
end

private

def distribution_strategy_for_project(project)
s = case project.name
when 'openSUSE:Factory' then DistributionStrategyFactory.new
when 'openSUSE:Factory:PowerPC' then DistributionStrategyFactoryPPC.new
when /^openSUSE:.*/ then DistributionStrategyOpenSUSE.new
when /^SUSE:SLE-12-SP\d:GA/ then DistributionStrategySLE12SP1.new
when /^SUSE:SLE-15:GA/ then DistributionStrategySLE15.new
when /^SUSE:SLE-12-SP.*CASP\d*/ then DistributionStrategyCasp.new
else raise UnknownDistribution
end
s.project = project
s
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@layouttype = 'custom'
%>
<% content_for :content_for_head do -%>
<%= stylesheet_link_tag 'obs_factory/application', media: 'all' %>
<%= stylesheet_link_tag 'webui/obs_factory/application', media: 'all' %>
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
<% end -%>
<%= render :template => "layouts/webui/webui" %>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- @staging_projects.each do |project|
- next if project.overall_state == :empty
%li
= render partial: 'obs_factory/staging_projects/overall_state', locals: { project: project }
= render partial: 'webui/obs_factory/staging_projects/overall_state', locals: { project: project }
%p{class: 'clear'}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%div{class: "overall-state staging-project state-#{project.overall_state}"}
%div{class: 'letter'}
= link_to project.letter, staging_project_path(project: @distribution.name, id: project.id)
= link_to project.letter, staging_project_path(project: @distribution.name, project_name: project.id)
%div{class: 'state'}
= link_to project.overall_state, main_app.project_show_path(project.name)
%div{class: 'progress'}
Expand Down
2 changes: 1 addition & 1 deletion src/api/config/initializers/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
Rails.application.config.assets.precompile += ['webui2/webui2.css', 'webui2/application.js']
Rails.application.config.assets.precompile += ['webui2/webui2.css', 'webui2/application.js', 'webui/obs_factory/application.css']
13 changes: 1 addition & 12 deletions src/api/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,18 +302,7 @@ def self.public_or_about_path?(request)

get 'project/dashboard/:project' => 'webui/obs_factory/distributions#show', as: 'dashboard', constraints: cons
get 'project/staging_projects/:project' => 'webui/obs_factory/staging_projects#index', as: 'staging_projects', constraints: cons
get 'project/staging_projects/:project/:id' => 'webui/obs_factory/staging_projects#show', as: 'staging_project', constraints: cons

# Used to enforce the refresh of the cache of jobs (using cache=refresh)
get 'openqa_jobs' => 'webui/obs_factory/openqa_jobs#index'

# Compatibility with old routes
scope '/factory' do
get "dashboard", to: redirect('project/dashboard/openSUSE:Factory')
get "staging_projects", to: redirect('project/staging_projects/openSUSE:Factory')
get "staging_projects/:id", to: redirect('project/staging_projects/openSUSE:Factory/%{id}')
get "openqa_jobs", to: redirect('openqa_jobs')
end
get 'project/staging_projects/:project/:project_name' => 'webui/obs_factory/staging_projects#show', as: 'staging_project', constraints: cons

controller 'webui/projects/rebuild_times' do
get 'project/rebuild_time/:project/:repository/:arch' => :show, constraints: cons, as: 'project_rebuild_time'
Expand Down

0 comments on commit f77d0e4

Please sign in to comment.