Skip to content

Commit

Permalink
Simplify API staging projects results
Browse files Browse the repository at this point in the history
When retrieving staging projects via API, only a minimal set of
information is going to be shown by default. Any extra information like
history, status or even staged requests can be ordered optionally by
setting the corresponding parameter in the URL.

Examples:
 - staging/<project>/staging_projects?requests=1&status=1
 - staging/<project>/staging_projects/<staging_project>?requests=1&status=1&history=1
  • Loading branch information
saraycp committed Nov 5, 2019
1 parent 0a36a72 commit 3ce1dbb
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 22 deletions.
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 })

0 comments on commit 3ce1dbb

Please sign in to comment.