Skip to content
Snippets Groups Projects
Commit b631323b authored by Shinya Maeda's avatar Shinya Maeda
Browse files

Merge branch '356420-environments-view-deploy-button-tied-to-wrong-job' into 'master'

Resolve "Environments View - Deploy button tied to wrong job"

See merge request gitlab-org/gitlab!87138
parents 772b94b7 9fe1b32f
No related branches found
No related tags found
No related merge requests found
Showing with 94 additions and 29 deletions
Loading
Loading
@@ -425,10 +425,18 @@ def other_manual_actions
pipeline.manual_actions.reject { |action| action.name == self.name }
end
 
def environment_manual_actions
pipeline.manual_actions.filter { |action| action.expanded_environment_name == self.expanded_environment_name }
end
def other_scheduled_actions
pipeline.scheduled_actions.reject { |action| action.name == self.name }
end
 
def environment_scheduled_actions
pipeline.scheduled_actions.filter { |action| action.expanded_environment_name == self.expanded_environment_name }
end
def pages_generator?
Gitlab.config.pages.enabled &&
self.name == 'pages'
Loading
Loading
Loading
Loading
@@ -256,11 +256,27 @@ def invalidate_cache
end
 
def manual_actions
@manual_actions ||= deployable.try(:other_manual_actions)
Feature.enabled?(:deployment_environment_manual_actions) ? environment_manual_actions : other_manual_actions
end
def other_manual_actions
@other_manual_actions ||= deployable.try(:other_manual_actions)
end
def environment_manual_actions
@environment_manual_actions ||= deployable.try(:environment_manual_actions)
end
 
def scheduled_actions
@scheduled_actions ||= deployable.try(:other_scheduled_actions)
Feature.enabled?(:deployment_environment_manual_actions) ? environment_scheduled_actions : other_scheduled_actions
end
def environment_scheduled_actions
@environment_scheduled_actions ||= deployable.try(:environment_scheduled_actions)
end
def other_scheduled_actions
@other_scheduled_actions ||= deployable.try(:other_scheduled_actions)
end
 
def playable_build
Loading
Loading
Loading
Loading
@@ -59,7 +59,7 @@ class Environment < ApplicationRecord
allow_nil: true,
addressable_url: true
 
delegate :manual_actions, to: :last_deployment, allow_nil: true
delegate :manual_actions, :other_manual_actions, to: :last_deployment, allow_nil: true
delegate :auto_rollback_enabled?, to: :project
 
scope :available, -> { with_state(:available) }
Loading
Loading
@@ -325,9 +325,9 @@ def reset_auto_stop
end
 
def actions_for(environment)
return [] unless manual_actions
return [] unless other_manual_actions
 
manual_actions.select do |action|
other_manual_actions.select do |action|
action.expanded_environment_name == environment
end
end
Loading
Loading
Loading
Loading
@@ -89,8 +89,8 @@ def deployment_associations
user: [],
metadata: [],
pipeline: {
manual_actions: [],
scheduled_actions: []
manual_actions: [:metadata],
scheduled_actions: [:metadata]
},
project: project_associations
}
Loading
Loading
---
name: deployment_environment_manual_actions
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/87138
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/362824
milestone: '15.1'
type: development
group: group::release
default_enabled: false
Loading
Loading
@@ -33,7 +33,7 @@ def actions_button_selector
 
context 'when environment has manual actions' do
let!(:pipeline) { create(:ci_pipeline, project: project) }
let!(:build) { create(:ci_build, pipeline: pipeline) }
let!(:build) { create(:ci_build, pipeline: pipeline, environment: 'production') }
 
let!(:deployment) do
create(:deployment,
Loading
Loading
Loading
Loading
@@ -109,7 +109,10 @@
end
 
context 'with stop action' do
let(:manual) { create(:ci_build, :manual, pipeline: pipeline, name: 'close_app') }
let(:manual) do
create(:ci_build, :manual, pipeline: pipeline,
name: 'close_app', environment: environment.name)
end
 
before do
stub_feature_flags(bootstrap_confirmation_modals: false)
Loading
Loading
Loading
Loading
@@ -157,7 +157,7 @@ def auto_stop_button_selector
 
context 'with related deployable present' do
let(:pipeline) { create(:ci_pipeline, project: project) }
let(:build) { create(:ci_build, pipeline: pipeline) }
let(:build) { create(:ci_build, pipeline: pipeline, environment: environment.name) }
 
let(:deployment) do
create(:deployment, :success, environment: environment, deployable: build)
Loading
Loading
@@ -263,7 +263,8 @@ def auto_stop_button_selector
context 'with stop action' do
let(:action) do
create(:ci_build, :manual, pipeline: pipeline,
name: 'close_app')
name: 'close_app',
environment: environment.name)
end
 
let(:deployment) do
Loading
Loading
Loading
Loading
@@ -32,7 +32,7 @@
context 'with environment' do
let!(:staging) { create(:environment, name: 'staging', project: project) }
let!(:pipeline) { create(:ci_pipeline, project: project) }
let!(:build) { create(:ci_build, pipeline: pipeline) }
let!(:build) { create(:ci_build, pipeline: pipeline, environment: 'production') }
let!(:deployment) { create(:deployment, :success, environment: staging, deployable: build) }
 
context 'without actions' do
Loading
Loading
Loading
Loading
@@ -17,7 +17,6 @@
it { is_expected.to delegate_method(:name).to(:environment).with_prefix }
it { is_expected.to delegate_method(:commit).to(:project) }
it { is_expected.to delegate_method(:commit_title).to(:commit).as(:try) }
it { is_expected.to delegate_method(:manual_actions).to(:deployable).as(:try) }
it { is_expected.to delegate_method(:kubernetes_namespace).to(:deployment_cluster).as(:kubernetes_namespace) }
 
it { is_expected.to validate_presence_of(:ref) }
Loading
Loading
@@ -25,20 +24,43 @@
 
it_behaves_like 'having unique enum values'
 
describe '#manual_actions' do
let(:deployment) { create(:deployment) }
it 'delegates to environment_manual_actions when deployment_environment_manual_actions ff is enabled' do
stub_feature_flags(deployment_environment_manual_actions: true)
expect(deployment.deployable).to receive(:environment_manual_actions).and_call_original
deployment.manual_actions
end
it 'delegates to other_manual_actions when deployment_environment_manual_actions ff is disabled' do
stub_feature_flags(deployment_environment_manual_actions: false)
expect(deployment.deployable).to receive(:other_manual_actions).and_call_original
deployment.manual_actions
end
end
describe '#scheduled_actions' do
subject { deployment.scheduled_actions }
let(:deployment) { create(:deployment) }
 
let(:project) { create(:project, :repository) }
let(:pipeline) { create(:ci_pipeline, project: project) }
let(:build) { create(:ci_build, :success, pipeline: pipeline) }
let(:deployment) { create(:deployment, deployable: build) }
it 'delegates to environment_scheduled_actions when deployment_environment_manual_actions ff is enabled' do
stub_feature_flags(deployment_environment_manual_actions: true)
 
it 'delegates to other_scheduled_actions' do
expect_next_instance_of(Ci::Build) do |instance|
expect(instance).to receive(:other_scheduled_actions)
end
expect(deployment.deployable).to receive(:environment_scheduled_actions).and_call_original
 
subject
deployment.scheduled_actions
end
it 'delegates to other_scheduled_actions when deployment_environment_manual_actions ff is disabled' do
stub_feature_flags(deployment_environment_manual_actions: false)
expect(deployment.deployable).to receive(:other_scheduled_actions).and_call_original
deployment.scheduled_actions
end
end
 
Loading
Loading
Loading
Loading
@@ -60,12 +60,16 @@
end
 
context 'when the pipeline has another manual action' do
let(:other_build) { create(:ci_build, :manual, name: 'another deploy', pipeline: pipeline) }
let!(:other_deployment) { create(:deployment, deployable: other_build) }
let!(:other_build) do
create(:ci_build, :manual, name: 'another deploy',
pipeline: pipeline, environment: build.environment)
end
let!(:other_deployment) { create(:deployment, deployable: build) }
 
it 'returns another manual action' do
expect(subject[:manual_actions].count).to eq(1)
expect(subject[:manual_actions].first[:name]).to eq('another deploy')
expect(subject[:manual_actions].count).to eq(2)
expect(subject[:manual_actions].second[:name]).to eq('another deploy')
end
 
context 'when user is a reporter' do
Loading
Loading
Loading
Loading
@@ -227,8 +227,11 @@
 
def create_environment_with_associations(project)
create(:environment, project: project).tap do |environment|
create(:deployment, :success, environment: environment, project: project)
create(:deployment, :running, environment: environment, project: project)
pipeline = create(:ci_pipeline, project: project)
manual_build = create(:ci_build, :manual, project: project, pipeline: pipeline, environment: environment.name)
scheduled_build = create(:ci_build, :scheduled, project: project, pipeline: pipeline, environment: environment.name)
create(:deployment, :success, environment: environment, project: project, deployable: manual_build)
create(:deployment, :running, environment: environment, project: project, deployable: scheduled_build)
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment