Skip to content

Commit

Permalink
Allow status checks to be attached to built repositories
Browse files Browse the repository at this point in the history
I left required check controller alone as it needs
a little more work as it's currently has required checks
for /published in /repositories - which collides with
what I want to achieve here
  • Loading branch information
coolo committed Nov 14, 2018
1 parent bf0feda commit 758b12e
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/api/app/controllers/status/concerns/set_checkable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module SetCheckable
private

def set_checkable
set_repository || set_bs_request
set_repository_architecture || set_bs_request
return if @checkable

@error_message ||= 'Provide at least project_name and repository_name or request number.'
Expand Down Expand Up @@ -38,6 +38,15 @@ def set_repository
@error_message = "Repository '#{params[:project_name]}/#{params[:repository_name]}' not found."
end

def set_repository_architecture
return unless set_repository
return @checkable unless params[:arch]
@checkable = @checkable.repository_architectures.joins(:architecture).find_by(architectures: { name: params[:arch] })
return @checkable if @checkable

@error_message = "Repository '#{params[:project_name]}/#{params[:repository_name]}/#{params[:arch]}' not found."
end

def set_bs_request
@checkable = BsRequest.with_submit_requests.find_by(number: params[:bs_request_number])
return @checkable if @checkable
Expand Down
11 changes: 11 additions & 0 deletions src/api/app/models/repository_architecture.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
class RepositoryArchitecture < ApplicationRecord
serialize :required_checks, Array
belongs_to :repository, inverse_of: :repository_architectures
belongs_to :architecture, inverse_of: :repository_architectures

acts_as_list scope: [:repository_id], top_of_list: 0

validates :repository, :architecture, :position, presence: true
validates :repository, uniqueness: { scope: :architecture }

has_many :status_reports, as: :checkable, class_name: 'Status::Report', dependent: :destroy do
def for_uuid(uuid)
where(status_reports: { uuid: uuid })
end

def latest
for_uuid(proxy_association.owner.build_id)
end
end
end

# == Schema Information
Expand Down
2 changes: 2 additions & 0 deletions src/api/app/models/status/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def projects
checkable.bs_request_actions.map(&:target_project_object).flatten
when Repository
[checkable.project]
when RepositoryArchitecture
[checkable.repository.project]
else
[]
end
Expand Down
6 changes: 6 additions & 0 deletions src/api/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,9 @@ def self.public_or_about_path?(request)
scope :published do
get ':project_name/:repository_name/reports/:report_uuid' => :show, constraints: cons
end
scope :built do
get ':project_name/:repository_name/:arch/reports/:report_uuid' => :show, constraints: cons
end
scope :requests do
get ':bs_request_number/reports' => :show
end
Expand All @@ -807,6 +810,9 @@ def self.public_or_about_path?(request)
scope :published do
post ':project_name/:repository_name/reports/:report_uuid' => :update, constraints: cons
end
scope :built do
post ':project_name/:repository_name/:arch/reports/:report_uuid' => :update, constraints: cons
end
scope :requests do
post ':bs_request_number/reports' => :update
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddRequiredChecksToRepositoryArchitecture < ActiveRecord::Migration[5.2]
def change
add_column :repository_architectures, :required_checks, :string
end
end
4 changes: 3 additions & 1 deletion src/api/db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,7 @@ CREATE TABLE `repository_architectures` (
`architecture_id` int(11) NOT NULL,
`position` int(11) NOT NULL DEFAULT '0',
`id` int(11) NOT NULL AUTO_INCREMENT,
`required_checks` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `arch_repo_index` (`repository_id`,`architecture_id`) USING BTREE,
KEY `architecture_id` (`architecture_id`) USING BTREE,
Expand Down Expand Up @@ -1421,6 +1422,7 @@ INSERT INTO `schema_migrations` (version) VALUES
('20180911123709'),
('20180924135535'),
('20181008150453'),
('20181016103905');
('20181016103905'),
('20181025152009');


11 changes: 11 additions & 0 deletions src/api/spec/controllers/status/checks_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
let(:user) { create(:confirmed_user) }
let(:project) { create(:project) }
let(:repository) { create(:repository, project: project) }
let(:repository_architecture) { create(:repository_architecture, repository: repository) }
let(:status_report) { create(:status_report, checkable: repository) }

before do
Expand Down Expand Up @@ -177,6 +178,16 @@
include_context 'does update the check'
end

context 'for a repository architecture' do
let(:status_report) { create(:status_report, checkable: repository_architecture) }
let!(:check) { create(:check, name: 'openQA', state: 'pending', status_report: status_report) }
let(:params) do
{ report_uuid: status_report.uuid, repository_name: repository.name, project_name: project.name, arch: repository_architecture.architecture.name }
end

include_context 'does update the check'
end

context 'for a request' do
let(:source_package) { create(:package) }
let(:source_project) { source_package.project }
Expand Down
23 changes: 22 additions & 1 deletion src/api/spec/controllers/status/reports_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
it { expect(assigns(:missing_checks)).to contain_exactly('openQA') }
end

context 'for repository' do
context 'for published repository' do
let(:project) { create(:project_with_repository) }
let(:repository) { project.repositories.first }
let(:status_report) { create(:status_report, checkable: repository) }
Expand All @@ -43,5 +43,26 @@
it { expect(assigns(:checks)).to contain_exactly(check) }
it { expect(assigns(:missing_checks)).to contain_exactly('openQA') }
end

context 'for built repository' do
let(:project) { create(:project_with_repository) }
let(:repository) { project.repositories.first }
let(:repository_architecture) { create(:repository_architecture, repository: repository) }
let(:status_report) { create(:status_report, checkable: repository_architecture) }
let!(:check) { create(:check, status_report: status_report, name: 'ExampleCI') }

before do
repository_architecture.update_attributes!(required_checks: ['openQA'])
end

subject! do
get :show, params: { project_name: project.name, repository_name: repository.name,
arch: repository_architecture.architecture.name, report_uuid: status_report.uuid }, format: :xml
end

it { is_expected.to have_http_status(:success) }
it { expect(assigns(:checks)).to contain_exactly(check) }
it { expect(assigns(:missing_checks)).to contain_exactly('openQA') }
end
end
end

0 comments on commit 758b12e

Please sign in to comment.