Commit 03174414 authored by Shinya Maeda's avatar Shinya Maeda

Merge branch 'afontaine/environment-tier-on-page' into 'master'

Display the tier of the environment on page

See merge request gitlab-org/gitlab!83429
parents adca1911 39765b0b
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import { import {
GlCollapse, GlCollapse,
GlDropdown, GlDropdown,
GlBadge,
GlButton, GlButton,
GlLink, GlLink,
GlSprintf, GlSprintf,
...@@ -26,6 +27,7 @@ export default { ...@@ -26,6 +27,7 @@ export default {
components: { components: {
GlCollapse, GlCollapse,
GlDropdown, GlDropdown,
GlBadge,
GlButton, GlButton,
GlLink, GlLink,
GlSprintf, GlSprintf,
...@@ -74,6 +76,7 @@ export default { ...@@ -74,6 +76,7 @@ export default {
'Environments|There are no deployments for this environment yet. %{linkStart}Learn more about setting up deployments.%{linkEnd}', 'Environments|There are no deployments for this environment yet. %{linkStart}Learn more about setting up deployments.%{linkEnd}',
), ),
autoStopIn: s__('Environment|Auto stop %{time}'), autoStopIn: s__('Environment|Auto stop %{time}'),
tierTooltip: s__('Environment|Deployment tier'),
}, },
data() { data() {
return { visible: false }; return { visible: false };
...@@ -100,6 +103,9 @@ export default { ...@@ -100,6 +103,9 @@ export default {
hasDeployment() { hasDeployment() {
return Boolean(this.environment?.upcomingDeployment || this.environment?.lastDeployment); return Boolean(this.environment?.upcomingDeployment || this.environment?.lastDeployment);
}, },
tier() {
return this.lastDeployment?.tierInYaml;
},
hasOpenedAlert() { hasOpenedAlert() {
return this.environment?.hasOpenedAlert; return this.environment?.hasOpenedAlert;
}, },
...@@ -206,6 +212,13 @@ export default { ...@@ -206,6 +212,13 @@ export default {
> >
{{ displayName }} {{ displayName }}
</gl-link> </gl-link>
<gl-badge
v-if="tier"
v-gl-tooltip
:title="$options.i18n.tierTooltip"
class="gl-ml-3 gl-font-monospace"
>{{ tier }}</gl-badge
>
</div> </div>
<div class="gl-display-flex gl-align-items-center"> <div class="gl-display-flex gl-align-items-center">
<p v-if="canShowAutoStopDate" class="gl-font-sm gl-text-gray-700 gl-mr-5 gl-mb-0"> <p v-if="canShowAutoStopDate" class="gl-font-sm gl-text-gray-700 gl-mr-5 gl-mb-0">
......
...@@ -24,7 +24,7 @@ const mapNestedEnvironment = (env) => ({ ...@@ -24,7 +24,7 @@ const mapNestedEnvironment = (env) => ({
__typename: 'NestedLocalEnvironment', __typename: 'NestedLocalEnvironment',
}); });
const mapEnvironment = (env) => ({ const mapEnvironment = (env) => ({
...convertObjectPropsToCamelCase(env), ...convertObjectPropsToCamelCase(env, { deep: true }),
__typename: 'LocalEnvironment', __typename: 'LocalEnvironment',
}); });
......
...@@ -380,6 +380,12 @@ class Deployment < ApplicationRecord ...@@ -380,6 +380,12 @@ class Deployment < ApplicationRecord
status == params[:status] status == params[:status]
end end
def tier_in_yaml
return unless deployable
deployable.environment_deployment_tier
end
private private
def update_status!(status) def update_status!(status)
......
...@@ -23,6 +23,7 @@ class DeploymentEntity < Grape::Entity ...@@ -23,6 +23,7 @@ class DeploymentEntity < Grape::Entity
expose :tag expose :tag
expose :last? expose :last?
expose :last?, as: :is_last expose :last?, as: :is_last
expose :tier_in_yaml
expose :deployed_by, as: :user, using: UserEntity expose :deployed_by, as: :user, using: UserEntity
......
...@@ -14398,6 +14398,9 @@ msgstr "" ...@@ -14398,6 +14398,9 @@ msgstr ""
msgid "Environment|Auto stop %{time}" msgid "Environment|Auto stop %{time}"
msgstr "" msgstr ""
msgid "Environment|Deployment tier"
msgstr ""
msgid "Epic" msgid "Epic"
msgstr "" msgstr ""
......
...@@ -543,6 +543,7 @@ export const resolvedEnvironment = { ...@@ -543,6 +543,7 @@ export const resolvedEnvironment = {
externalUrl: 'https://example.org', externalUrl: 'https://example.org',
environmentType: 'review', environmentType: 'review',
nameWithoutType: 'hello', nameWithoutType: 'hello',
tier: 'development',
lastDeployment: { lastDeployment: {
id: 78, id: 78,
iid: 24, iid: 24,
...@@ -551,6 +552,7 @@ export const resolvedEnvironment = { ...@@ -551,6 +552,7 @@ export const resolvedEnvironment = {
status: 'success', status: 'success',
createdAt: '2022-01-07T15:47:27.415Z', createdAt: '2022-01-07T15:47:27.415Z',
deployedAt: '2022-01-07T15:47:32.450Z', deployedAt: '2022-01-07T15:47:32.450Z',
tierInYaml: 'staging',
tag: false, tag: false,
isLast: true, isLast: true,
user: { user: {
......
...@@ -73,6 +73,34 @@ describe('~/environments/components/new_environment_item.vue', () => { ...@@ -73,6 +73,34 @@ describe('~/environments/components/new_environment_item.vue', () => {
expect(name.text()).toHaveLength(80); expect(name.text()).toHaveLength(80);
}); });
describe('tier', () => {
it('displays the tier of the environment when defined in yaml', () => {
wrapper = createWrapper({ apolloProvider: createApolloProvider() });
const tier = wrapper.findByTitle(s__('Environment|Deployment tier'));
expect(tier.text()).toBe(resolvedEnvironment.lastDeployment.tierInYaml);
});
it('does not display the tier if not defined in yaml', () => {
const environment = {
...resolvedEnvironment,
lastDeployment: {
...resolvedEnvironment.lastDeployment,
tierInYaml: null,
},
};
wrapper = createWrapper({
propsData: { environment },
apolloProvider: createApolloProvider(),
});
const tier = wrapper.findByTitle(s__('Environment|Deployment tier'));
expect(tier.exists()).toBe(false);
});
});
describe('url', () => { describe('url', () => {
it('shows a link for the url if one is present', () => { it('shows a link for the url if one is present', () => {
wrapper = createWrapper({ apolloProvider: createApolloProvider() }); wrapper = createWrapper({ apolloProvider: createApolloProvider() });
......
...@@ -1055,6 +1055,40 @@ RSpec.describe Deployment do ...@@ -1055,6 +1055,40 @@ RSpec.describe Deployment do
end end
end end
describe '#tier_in_yaml' do
context 'when deployable is nil' do
before do
subject.deployable = nil
end
it 'returns nil' do
expect(subject.tier_in_yaml).to be_nil
end
end
context 'when deployable is present' do
context 'when tier is specified' do
let(:deployable) { create(:ci_build, :success, :environment_with_deployment_tier) }
before do
subject.deployable = deployable
end
it 'returns the tier' do
expect(subject.tier_in_yaml).to eq('testing')
end
context 'when tier is not specified' do
let(:deployable) { create(:ci_build, :success) }
it 'returns nil' do
expect(subject.tier_in_yaml).to be_nil
end
end
end
end
end
describe '.fast_destroy_all' do describe '.fast_destroy_all' do
it 'cleans path_refs for destroyed environments' do it 'cleans path_refs for destroyed environments' do
project = create(:project, :repository) project = create(:project, :repository)
......
...@@ -9,7 +9,7 @@ RSpec.describe DeploymentEntity do ...@@ -9,7 +9,7 @@ RSpec.describe DeploymentEntity do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:request) { double('request') } let(:request) { double('request') }
let(:deployment) { create(:deployment, deployable: build, project: project) } let(:deployment) { create(:deployment, deployable: build, project: project) }
let(:build) { create(:ci_build, :manual, pipeline: pipeline) } let(:build) { create(:ci_build, :manual, :environment_with_deployment_tier, pipeline: pipeline) }
let(:pipeline) { create(:ci_pipeline, project: project, user: user) } let(:pipeline) { create(:ci_pipeline, project: project, user: user) }
let(:entity) { described_class.new(deployment, request: request) } let(:entity) { described_class.new(deployment, request: request) }
...@@ -46,6 +46,10 @@ RSpec.describe DeploymentEntity do ...@@ -46,6 +46,10 @@ RSpec.describe DeploymentEntity do
expect(subject).to include(:is_last) expect(subject).to include(:is_last)
end end
it 'exposes deployment tier in yaml' do
expect(subject).to include(:tier_in_yaml)
end
context 'when deployable is nil' do context 'when deployable is nil' do
let(:entity) { described_class.new(deployment, request: request, deployment_details: false) } let(:entity) { described_class.new(deployment, request: request, deployment_details: false) }
let(:deployment) { create(:deployment, deployable: nil, project: project) } let(:deployment) { create(:deployment, deployable: nil, project: project) }
......
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