Skip to content

Commit

Permalink
Merge pull request #8657 from saraycp/optional_info_staging
Browse files Browse the repository at this point in the history
Simplify API staging projects results
  • Loading branch information
coolo committed Nov 6, 2019
2 parents e440f66 + bed28e6 commit f6fecd1
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 41 deletions.
20 changes: 16 additions & 4 deletions docs/api/api/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1940,12 +1940,24 @@ DELETE /staging/<staging_workflow_project>/workflow
Delete a staging workflow associated to a given project.
XmlResult: status_ok

GET /staging/<staging_workflow_project>/staging_projects
Get the overall state of all staging projects belonging to a staging workflow project
GET /staging/<staging_workflow_project>/staging_projects?requests=1&status=1&history=1
Get the overall state of all staging projects belonging to a staging workflow project.
Extra information can be requested by adding any combination of these parameters in the URL: requests, status and history.

- If requests is present, the output includes the staged requests.
- If status is present, the output includes the overall state and the status xml (broken packages, missing reviews, checks, etc.)
- If history is present, the output includes the history of the staging project.

XmlResult: staging_projects

GET /staging/<staging_workflow_project>/staging_projects/<staging_project>
Get the overall state of a staging project
GET /staging/<staging_workflow_project>/staging_projects/<staging_project>?requests=1&status=1&history=1
Get the overall state of a staging project.
Extra information can be requested by adding any combination of these parameters in the URL: requests, status and history.

- If requests is present, the output includes the staged requests.
- If status is present, the output includes the overall state and the status xml (broken packages, missing reviews, checks, etc.)
- If history is present, the output includes the history of the staging project.

XmlResult: staging_project

POST /staging/<staging_workflow_project>/staging_projects/<staging_project>/copy/<staging_project_copy_name>
Expand Down
10 changes: 10 additions & 0 deletions src/api/app/controllers/staging/staging_projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class Staging::StagingProjectsController < Staging::StagingController
before_action :require_login, except: [:index, :show]
before_action :set_project
before_action :set_staging_workflow, only: :create
before_action :set_options, only: [:index, :show]

validate_action create: { method: :post, request: :staging_project }

Expand Down Expand Up @@ -59,4 +60,13 @@ def accept
StagingProjectAcceptJob.perform_later(project_id: staging_project.id, user_login: User.session!.login)
render_ok
end

private

def set_options
@options = {}
[:requests, :history, :status].each do |option|
@options[option] = params[option].present?
end
end
end
Original file line number Diff line number Diff line change
@@ -1,24 +1,41 @@
builder.staging_project(name: staging_project.name, state: staging_project.overall_state) do
builder.staged_requests(count: staging_project.staged_requests.count) do
render(partial: 'requests', locals: { requests: staging_project.staged_requests, builder: builder })
attributes = { name: staging_project.name }
attributes.merge!(state: staging_project.overall_state) if options[:status]

builder.staging_project(attributes) do
if options[:requests]
builder.staged_requests(count: staging_project.staged_requests.count) do
render(partial: 'requests', locals: { requests: staging_project.staged_requests, builder: builder })
end
end
builder.untracked_requests(count: staging_project.untracked_requests.count) do
render(partial: 'requests', locals: { requests: staging_project.untracked_requests, builder: builder })

if options[:status]
builder.untracked_requests(count: staging_project.untracked_requests.count) do
render(partial: 'requests', locals: { requests: staging_project.untracked_requests, builder: builder })
end
builder.requests_to_review(count: staging_project.requests_to_review.count) do
render(partial: 'requests', locals: { requests: staging_project.requests_to_review, builder: builder })
end
builder.obsolete_requests(count: staging_project.staged_requests.obsolete.count) do
render(partial: 'requests', locals: { requests: staging_project.staged_requests.obsolete, builder: builder })
end
render(partial: 'missing_reviews', locals: { missing_reviews: staging_project.missing_reviews,
count: staging_project.missing_reviews.count,
builder: builder })
render(partial: 'building_repositories', locals: { building_repositories: staging_project.building_repositories,
count: staging_project.building_repositories.count,
builder: builder })
render(partial: 'broken_packages', locals: { broken_packages: staging_project.broken_packages,
count: staging_project.broken_packages.count,
builder: builder })
render(partial: 'checks', locals: { checks: staging_project.checks, builder: builder })
render(partial: 'missing_checks', locals: { missing_checks: staging_project.missing_checks, builder: builder })
end
builder.requests_to_review(count: staging_project.requests_to_review.count) do
render(partial: 'requests', locals: { requests: staging_project.requests_to_review, builder: builder })
end
builder.obsolete_requests(count: staging_project.staged_requests.obsolete.count) do
render(partial: 'requests', locals: { requests: staging_project.staged_requests.obsolete, builder: builder })
end
render(partial: 'missing_reviews', locals: { missing_reviews: staging_project.missing_reviews, count: staging_project.missing_reviews.count, builder: builder })
render(partial: 'building_repositories', locals: { building_repositories: staging_project.building_repositories, count: staging_project.building_repositories.count, builder: builder })
render(partial: 'broken_packages', locals: { broken_packages: staging_project.broken_packages, count: staging_project.broken_packages.count, builder: builder })
render(partial: 'checks', locals: { checks: staging_project.checks, builder: builder })
render(partial: 'missing_checks', locals: { missing_checks: staging_project.missing_checks, builder: builder })
builder.history(count: staging_project.project_log_entries.where(event_type: [:staged_request, :unstaged_request]).count) do
render(partial: 'history_elements', locals: { builder: builder,
elements: staging_project.project_log_entries.where(event_type:
[:staged_request, :unstaged_request]).includes(:bs_request) })

if options[:history]
builder.history(count: staging_project.project_log_entries.where(event_type: [:staged_request, :unstaged_request]).count) do
render(partial: 'history_elements', locals: { builder: builder,
elements: staging_project.project_log_entries.where(event_type:
[:staged_request, :unstaged_request]).includes(:bs_request) })
end
end
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
xml.staging_projects do
@staging_projects.each do |staging_project|
render(partial: 'staging_project_item', locals: { staging_project: staging_project, builder: xml })
render(partial: 'staging_project_item', locals: { staging_project: staging_project, options: @options, builder: xml })
end
end
Original file line number Diff line number Diff line change
@@ -1 +1 @@
render(partial: 'staging_project_item', locals: { staging_project: @staging_project, builder: xml })
render(partial: 'staging_project_item', locals: { staging_project: @staging_project, options: @options, builder: xml })
135 changes: 120 additions & 15 deletions src/api/spec/controllers/staging/staging_projects_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,29 +86,134 @@
untracked_request.change_review_state(:accepted, by_group: staging_workflow.managers_group.title)
bs_request.change_review_state(:accepted, by_group: staging_workflow.managers_group.title)
logout
get :show, params: { staging_workflow_project: staging_workflow.project.name, staging_project_name: staging_project.name, format: :xml }
end

it { expect(response).to have_http_status(:success) }
context 'without requesting extra information' do
before do
get :show, params: { staging_workflow_project: staging_workflow.project.name, staging_project_name: staging_project.name, format: :xml }
end

it { expect(response).to have_http_status(:success) }

it { expect(response.body).not_to include("<staging_project name=\"#{staging_project.name}\" state=") }

it 'returns the staging_project name xml' do
assert_select 'staging_project' do
assert_select 'staged_requests', 1 do
assert_select 'request', 3
it 'returns the staging_project default xml' do
assert_select 'staging_project' do
assert_select 'staged_requests', 0
assert_select 'untracked_requests', 0
assert_select 'requests_to_review', 0
assert_select 'missing_reviews', 0
assert_select 'broken_packages', 0
assert_select 'history', 0
end
assert_select 'untracked_requests', 1 do
assert_select 'request', 1
end
end

context 'with staged requests' do
before do
get :show, params: { staging_workflow_project: staging_workflow.project.name, staging_project_name: staging_project.name,
requests: 1, format: :xml }
end

it { expect(response).to have_http_status(:success) }

it { expect(response.body).not_to include("<staging_project name=\"#{staging_project.name}\" state=") }

it 'returns the staging_project with staged requests xml' do
assert_select 'staging_project' do
assert_select 'staged_requests', 1 do
assert_select 'request', 3
end
assert_select 'untracked_requests', 0
assert_select 'requests_to_review', 0
assert_select 'missing_reviews', 0
assert_select 'broken_packages', 0
assert_select 'history', 0
end
assert_select 'requests_to_review', 1 do
assert_select 'request', 2
end
end

context 'with status info' do
before do
get :show, params: { staging_workflow_project: staging_workflow.project.name, staging_project_name: staging_project.name,
status: 1, format: :xml }
end

it { expect(response).to have_http_status(:success) }

it { expect(response.body).to include("<staging_project name=\"#{staging_project.name}\" state=") }

it 'returns the staging_project with status xml' do
assert_select 'staging_project' do
assert_select 'staged_requests', 0
assert_select 'untracked_requests', 1 do
assert_select 'request', 1
end
assert_select 'requests_to_review', 1 do
assert_select 'request', 2
end
assert_select 'missing_reviews', 1 do
assert_select 'review', 1
end
assert_select 'broken_packages', 1 do
assert_select 'package', 1
end
assert_select 'history', 0
end
assert_select 'missing_reviews', 1 do
assert_select 'review', 1
end
end

context 'with history' do
before do
get :show, params: { staging_workflow_project: staging_workflow.project.name, staging_project_name: staging_project.name,
history: 1, format: :xml }
end

it { expect(response).to have_http_status(:success) }

it { expect(response.body).not_to include("<staging_project name=\"#{staging_project.name}\" state=") }

it 'returns the staging_project with history xml' do
assert_select 'staging_project' do
assert_select 'staged_requests', 0
assert_select 'untracked_requests', 0
assert_select 'requests_to_review', 0
assert_select 'missing_reviews', 0
assert_select 'broken_packages', 0
assert_select 'history', 1
end
assert_select 'broken_packages', 1 do
assert_select 'package', 1
end
end

context 'with requests, status, history' do
before do
get :show, params: { staging_workflow_project: staging_workflow.project.name, staging_project_name: staging_project.name,
requests: 1, status: 1, history: 1, format: :xml }
end

it { expect(response).to have_http_status(:success) }

it { expect(response.body).to include("<staging_project name=\"#{staging_project.name}\" state=") }

it 'returns the staging_project with requests, status and history xml' do
assert_select 'staging_project' do
assert_select 'staged_requests', 1 do
assert_select 'request', 3
end
assert_select 'untracked_requests', 1 do
assert_select 'request', 1
end
assert_select 'requests_to_review', 1 do
assert_select 'request', 2
end
assert_select 'missing_reviews', 1 do
assert_select 'review', 1
end
assert_select 'broken_packages', 1 do
assert_select 'package', 1
end
assert_select 'history', 1
end
assert_select 'history', 1
end
end
end
Expand Down

0 comments on commit f6fecd1

Please sign in to comment.