Commit 043a38f2 authored by Nick Thomas's avatar Nick Thomas

Merge branch 'environments-list-data-c' into 'master'

Show Last Deployment in Environment Dashboard

See merge request gitlab-org/gitlab!17168
parents 09020aea ebf2dd7a
...@@ -15,7 +15,7 @@ class EnvironmentFolder ...@@ -15,7 +15,7 @@ class EnvironmentFolder
environments_by_id = environments environments_by_id = environments
.id_in(folder_data.map { |(env_id, _)| env_id }) .id_in(folder_data.map { |(env_id, _)| env_id })
.includes(:project) .includes(:project, last_deployment: [:project, deployable: :user])
.index_by(&:id) .index_by(&:id)
folders = folder_data.map do |(environment_id, count)| folders = folder_data.map do |(environment_id, count)|
......
...@@ -10,4 +10,19 @@ class DashboardEnvironmentEntity < Grape::Entity ...@@ -10,4 +10,19 @@ class DashboardEnvironmentEntity < Grape::Entity
end end
expose :external_url expose :external_url
expose :last_deployment, expose_nil: false do |environment|
DeploymentEntity.represent(environment.last_deployment, options.merge(request: new_request))
end
private
alias_method :environment, :object
def new_request
EntityRequest.new(
current_user: request.current_user,
project: environment.project
)
end
end end
...@@ -389,6 +389,40 @@ describe OperationsController do ...@@ -389,6 +389,40 @@ describe OperationsController do
expect(project_json['environments'].first['within_folder']).to eq(true) expect(project_json['environments'].first['within_folder']).to eq(true)
expect(project_json['environments'].first['id']).to eq(environment.id) expect(project_json['environments'].first['id']).to eq(environment.id)
end end
it 'returns the last deployment for an environment' do
environment = create(:environment, project: project)
deployment = create(:deployment, project: project, environment: environment, status: :success)
get :environments_list
expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('dashboard/operations/environments_list', dir: 'ee')
project_json = json_response['projects'].first
environment_json = project_json['environments'].first
last_deployment_json = environment_json['last_deployment']
expect(last_deployment_json['id']).to eq(deployment.id)
end
it "returns the last deployment's deployable" do
environment = create(:environment, project: project)
ci_build = create(:ci_build, project: project)
create(:deployment, project: project, environment: environment, deployable: ci_build, status: :success)
get :environments_list
expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('dashboard/operations/environments_list', dir: 'ee')
project_json = json_response['projects'].first
environment_json = project_json['environments'].first
deployable_json = environment_json['last_deployment']['deployable']
expect(deployable_json['id']).to eq(ci_build.id)
expect(deployable_json['build_path']).to eq(project_job_path(project, ci_build))
end
end end
end end
end end
......
...@@ -66,7 +66,8 @@ ...@@ -66,7 +66,8 @@
"size": { "type": "integer" }, "size": { "type": "integer" },
"within_folder": { "type": "boolean" }, "within_folder": { "type": "boolean" },
"external_url": { "type": "string" }, "external_url": { "type": "string" },
"environment_path": { "type": "string" } "environment_path": { "type": "string" },
"last_deployment": { "$ref": "../../../../../../../spec/fixtures/api/schemas/deployment.json" }
} }
} }
} }
......
...@@ -5,11 +5,14 @@ require 'spec_helper' ...@@ -5,11 +5,14 @@ require 'spec_helper'
describe DashboardEnvironmentEntity do describe DashboardEnvironmentEntity do
describe '.as_json' do describe '.as_json' do
it 'includes environment attributes' do it 'includes environment attributes' do
user = create(:user)
environment = create(:environment) environment = create(:environment)
create(:deployment, project: environment.project, environment: environment, status: :success)
request = EntityRequest.new(current_user: user)
result = described_class.new(environment).as_json result = described_class.new(environment, request: request).as_json
expect(result.keys.sort).to eq([:environment_path, :external_url, :id, :name]) expect(result.keys.sort).to eq([:environment_path, :external_url, :id, :last_deployment, :name])
end end
end end
end end
...@@ -5,13 +5,16 @@ require 'spec_helper' ...@@ -5,13 +5,16 @@ require 'spec_helper'
describe DashboardEnvironmentsFolderEntity do describe DashboardEnvironmentsFolderEntity do
describe '.as_json' do describe '.as_json' do
it 'includes folder and environment attributes' do it 'includes folder and environment attributes' do
user = create(:user)
environment = create(:environment) environment = create(:environment)
create(:deployment, project: environment.project, environment: environment, status: :success)
size = 1 size = 1
environment_folder = EnvironmentFolder.new(environment, size) environment_folder = EnvironmentFolder.new(environment, size)
request = EntityRequest.new(current_user: user)
result = described_class.new(environment_folder).as_json result = described_class.new(environment_folder, request: request).as_json
expect(result.keys.sort).to eq([:environment_path, :external_url, :id, :name, :size, :within_folder]) expect(result.keys.sort).to eq([:environment_path, :external_url, :id, :last_deployment, :name, :size, :within_folder])
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment