Skip to content

Commit

Permalink
Filter Recent Deployments by Environments
Browse files Browse the repository at this point in the history
This could be useful for things like finding out which deploys have happened on
production recently, to aid in debugging a live incident.

It would also allow going further back in history, as currently the search is
restricted to the last 25 deployments across all envs, so being able to show 25
deployments in a single env will show more results that would otherwise be
lost.
  • Loading branch information
PeterHattyar committed Sep 4, 2023
1 parent 872aae7 commit 913b4e9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app/controllers/deployments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ def show
end

def recent
@deployments = Deployment.includes(:application).newest_first.limit(25)
env = recent_deployment_params[:environment_filter]

filtered_deployments = env ? Deployment.where(environment: [env, "#{env} EKS"]) : Deployment
@deployments = filtered_deployments.includes(:application).newest_first.limit(25)
end

def new
Expand Down Expand Up @@ -131,4 +134,10 @@ def new_deployment_params
:environment,
)
end

def recent_deployment_params
params.permit(
:environment_filter,
)
end
end
22 changes: 22 additions & 0 deletions app/views/deployments/recent.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,27 @@
title: "Recent deployments"
} %>

<%= form_tag(activity_path, method: :get) do %>
<div class="govuk-form-group">
<%= render "govuk_publishing_components/components/label", {
text: "Filter environment",
html_for: "deployment-environment-filter",
bold: true
} %>

<%= select_tag "environment_filter",
options_for_select(Application::ENVIRONMENTS_ORDER.map(&:capitalize), [params[:environment_filter]]),
include_blank: true,
id: "deployment-environment-filter",
class: "govuk-select"
%>
</div>

<%= render "govuk_publishing_components/components/button", {
text: "Filter",
margin_bottom: true
} %>
<% end %>

<%= render "deployments_list", deploys: @deployments %>
</section>
9 changes: 9 additions & 0 deletions test/functional/deployments_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ class DeploymentsControllerTest < ActionController::TestCase

assert_equal 10, assigns(:deployments).size
end

should "assign only filtered environments" do
FactoryBot.create(:deployment, application_id: @application.id, environment: "integration EKS")
FactoryBot.create(:deployment, application_id: @application.id, environment: "integration")

get :recent, params: { environment_filter: "Integration" }

assert_equal 2, assigns(:deployments).size
end
end

context "GET new" do
Expand Down

0 comments on commit 913b4e9

Please sign in to comment.