2019-07-25 05:24:42 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-29 07:56:52 +00:00
|
|
|
require 'spec_helper'
|
2016-08-12 14:23:00 +00:00
|
|
|
|
2020-06-16 18:09:01 +00:00
|
|
|
RSpec.describe 'Merge request > User sees pipelines', :js do
|
2017-08-04 09:01:59 +00:00
|
|
|
describe 'pipeline tab' do
|
2017-08-01 18:03:07 +00:00
|
|
|
let(:merge_request) { create(:merge_request) }
|
|
|
|
let(:project) { merge_request.target_project }
|
|
|
|
let(:user) { project.creator }
|
2016-08-12 14:23:00 +00:00
|
|
|
|
2017-08-04 09:01:59 +00:00
|
|
|
before do
|
2018-07-11 14:36:08 +00:00
|
|
|
project.add_maintainer(user)
|
2017-08-01 18:03:07 +00:00
|
|
|
sign_in(user)
|
2016-08-12 14:23:00 +00:00
|
|
|
end
|
|
|
|
|
2017-08-04 09:01:59 +00:00
|
|
|
context 'with pipelines' do
|
|
|
|
let!(:pipeline) do
|
|
|
|
create(:ci_empty_pipeline,
|
|
|
|
project: merge_request.source_project,
|
|
|
|
ref: merge_request.source_branch,
|
|
|
|
sha: merge_request.diff_head_sha)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2017-09-07 07:58:15 +00:00
|
|
|
merge_request.update_attribute(:head_pipeline_id, pipeline.id)
|
2017-08-04 09:01:59 +00:00
|
|
|
end
|
|
|
|
|
2017-08-01 18:03:07 +00:00
|
|
|
it 'user visits merge request pipelines tab' do
|
2017-09-07 07:58:15 +00:00
|
|
|
visit project_merge_request_path(project, merge_request)
|
|
|
|
|
|
|
|
expect(page.find('.ci-widget')).to have_content('pending')
|
|
|
|
|
2017-08-04 09:01:59 +00:00
|
|
|
page.within('.merge-request-tabs') do
|
|
|
|
click_link('Pipelines')
|
|
|
|
end
|
|
|
|
wait_for_requests
|
|
|
|
|
2017-08-04 11:18:05 +00:00
|
|
|
expect(page).to have_selector('.stage-cell')
|
2017-08-04 09:01:59 +00:00
|
|
|
end
|
2017-09-07 07:58:15 +00:00
|
|
|
|
2019-09-11 09:06:33 +00:00
|
|
|
context 'with a detached merge request pipeline' do
|
|
|
|
let(:merge_request) { create(:merge_request, :with_detached_merge_request_pipeline) }
|
|
|
|
|
2021-04-09 06:09:30 +00:00
|
|
|
it 'displays the "Run pipeline" button' do
|
2019-09-11 09:06:33 +00:00
|
|
|
visit project_merge_request_path(project, merge_request)
|
|
|
|
|
|
|
|
page.within('.merge-request-tabs') do
|
|
|
|
click_link('Pipelines')
|
|
|
|
end
|
|
|
|
|
|
|
|
wait_for_requests
|
|
|
|
|
2021-04-09 06:09:30 +00:00
|
|
|
expect(page.find('[data-testid="run_pipeline_button"]')).to have_text('Run pipeline')
|
2019-09-11 09:06:33 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a merged results pipeline' do
|
|
|
|
let(:merge_request) { create(:merge_request, :with_merge_request_pipeline) }
|
|
|
|
|
2021-04-09 06:09:30 +00:00
|
|
|
it 'displays the "Run pipeline" button' do
|
2019-09-11 09:06:33 +00:00
|
|
|
visit project_merge_request_path(project, merge_request)
|
|
|
|
|
|
|
|
page.within('.merge-request-tabs') do
|
|
|
|
click_link('Pipelines')
|
|
|
|
end
|
|
|
|
|
|
|
|
wait_for_requests
|
|
|
|
|
2021-04-09 06:09:30 +00:00
|
|
|
expect(page.find('[data-testid="run_pipeline_button"]')).to have_text('Run pipeline')
|
2019-09-11 09:06:33 +00:00
|
|
|
end
|
|
|
|
end
|
2016-08-12 14:23:00 +00:00
|
|
|
end
|
|
|
|
|
2017-08-04 09:01:59 +00:00
|
|
|
context 'without pipelines' do
|
|
|
|
before do
|
|
|
|
visit project_merge_request_path(project, merge_request)
|
2016-08-12 14:23:00 +00:00
|
|
|
end
|
|
|
|
|
2017-08-01 18:03:07 +00:00
|
|
|
it 'user visits merge request page' do
|
2017-08-04 09:01:59 +00:00
|
|
|
page.within('.merge-request-tabs') do
|
2022-07-28 21:09:42 +00:00
|
|
|
expect(page).to have_link('Pipelines')
|
2017-08-04 09:01:59 +00:00
|
|
|
end
|
|
|
|
end
|
2022-07-28 21:09:42 +00:00
|
|
|
|
|
|
|
it 'shows empty state with run pipeline button' do
|
|
|
|
page.within('.merge-request-tabs') do
|
|
|
|
click_link('Pipelines')
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(page).to have_content('There are currently no pipelines.')
|
|
|
|
expect(page.find('[data-testid="run_pipeline_button"]')).to have_text('Run pipeline')
|
|
|
|
end
|
2016-08-12 14:23:00 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-15 21:09:26 +00:00
|
|
|
describe 'fork MRs in parent project', :sidekiq_inline do
|
|
|
|
include ProjectForksHelper
|
|
|
|
|
|
|
|
let_it_be(:parent_project) { create(:project, :public, :repository) }
|
|
|
|
let_it_be(:forked_project) { fork_project(parent_project, developer_in_fork, repository: true, target_project: create(:project, :public, :repository)) }
|
|
|
|
let_it_be(:developer_in_parent) { create(:user) }
|
|
|
|
let_it_be(:developer_in_fork) { create(:user) }
|
|
|
|
let_it_be(:reporter_in_parent_and_developer_in_fork) { create(:user) }
|
|
|
|
|
|
|
|
let(:merge_request) do
|
|
|
|
create(:merge_request, :with_detached_merge_request_pipeline,
|
|
|
|
source_project: forked_project, source_branch: 'feature',
|
|
|
|
target_project: parent_project, target_branch: 'master')
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:config) do
|
|
|
|
{ test: { script: 'test', rules: [{ if: '$CI_MERGE_REQUEST_ID' }] } }
|
|
|
|
end
|
|
|
|
|
|
|
|
before_all do
|
|
|
|
parent_project.add_developer(developer_in_parent)
|
|
|
|
parent_project.add_reporter(reporter_in_parent_and_developer_in_fork)
|
|
|
|
forked_project.add_developer(developer_in_fork)
|
|
|
|
forked_project.add_developer(reporter_in_parent_and_developer_in_fork)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_ci_pipeline_yaml_file(YAML.dump(config))
|
|
|
|
sign_in(actor)
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
parent_project.all_pipelines.delete_all
|
|
|
|
forked_project.all_pipelines.delete_all
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when actor is a developer in parent project' do
|
|
|
|
let(:actor) { developer_in_parent }
|
|
|
|
|
2020-07-22 15:09:28 +00:00
|
|
|
it 'creates a pipeline in the parent project when user proceeds with the warning' do
|
2020-07-15 21:09:26 +00:00
|
|
|
visit project_merge_request_path(parent_project, merge_request)
|
|
|
|
|
|
|
|
create_merge_request_pipeline
|
2021-04-09 06:09:30 +00:00
|
|
|
act_on_security_warning(action: 'Run pipeline')
|
2020-07-15 21:09:26 +00:00
|
|
|
|
2022-02-18 18:18:16 +00:00
|
|
|
check_pipeline(expected_project: parent_project)
|
2020-07-15 21:09:26 +00:00
|
|
|
check_head_pipeline(expected_project: parent_project)
|
|
|
|
end
|
2020-07-22 15:09:28 +00:00
|
|
|
|
2021-07-19 06:08:44 +00:00
|
|
|
it 'does not create a pipeline in the parent project when user cancels the action', :clean_gitlab_redis_cache, :clean_gitlab_redis_shared_state do
|
2020-07-22 15:09:28 +00:00
|
|
|
visit project_merge_request_path(parent_project, merge_request)
|
|
|
|
|
|
|
|
create_merge_request_pipeline
|
|
|
|
act_on_security_warning(action: 'Cancel')
|
|
|
|
|
|
|
|
check_no_pipelines
|
|
|
|
end
|
2020-07-15 21:09:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when actor is a developer in fork project' do
|
|
|
|
let(:actor) { developer_in_fork }
|
|
|
|
|
|
|
|
it 'creates a pipeline in the fork project' do
|
|
|
|
visit project_merge_request_path(parent_project, merge_request)
|
|
|
|
|
|
|
|
create_merge_request_pipeline
|
|
|
|
|
|
|
|
check_pipeline(expected_project: forked_project)
|
|
|
|
check_head_pipeline(expected_project: forked_project)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when actor is a reporter in parent project and a developer in fork project' do
|
|
|
|
let(:actor) { reporter_in_parent_and_developer_in_fork }
|
|
|
|
|
|
|
|
it 'creates a pipeline in the fork project' do
|
|
|
|
visit project_merge_request_path(parent_project, merge_request)
|
|
|
|
|
|
|
|
create_merge_request_pipeline
|
|
|
|
|
|
|
|
check_pipeline(expected_project: forked_project)
|
|
|
|
check_head_pipeline(expected_project: forked_project)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_merge_request_pipeline
|
|
|
|
page.within('.merge-request-tabs') { click_link('Pipelines') }
|
2021-04-09 06:09:30 +00:00
|
|
|
click_button('Run pipeline')
|
2020-07-15 21:09:26 +00:00
|
|
|
end
|
|
|
|
|
2022-02-18 18:18:16 +00:00
|
|
|
def check_pipeline(expected_project:)
|
2020-07-15 21:09:26 +00:00
|
|
|
page.within('.ci-table') do
|
|
|
|
expect(page).to have_selector('.commit', count: 2)
|
|
|
|
|
|
|
|
page.within(first('.commit')) do
|
|
|
|
page.within('.pipeline-tags') do
|
2022-02-18 18:18:16 +00:00
|
|
|
expect(page.find('[data-testid="pipeline-url-link"]')[:href]).to include(expected_project.full_path)
|
2022-02-24 18:19:04 +00:00
|
|
|
expect(page).to have_content('merge request')
|
2020-07-15 21:09:26 +00:00
|
|
|
end
|
|
|
|
page.within('.pipeline-triggerer') do
|
|
|
|
expect(page).to have_link(href: user_path(actor))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_head_pipeline(expected_project:)
|
|
|
|
page.within('.merge-request-tabs') { click_link('Overview') }
|
|
|
|
|
|
|
|
page.within('.ci-widget-content') do
|
|
|
|
expect(page.find('.pipeline-id')[:href]).to include(expected_project.full_path)
|
|
|
|
end
|
|
|
|
end
|
2020-07-22 15:09:28 +00:00
|
|
|
|
|
|
|
def act_on_security_warning(action:)
|
|
|
|
page.within('#create-pipeline-for-fork-merge-request-modal') do
|
|
|
|
expect(page).to have_content('Are you sure you want to run this pipeline?')
|
|
|
|
click_button(action)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_no_pipelines
|
|
|
|
page.within('.ci-table') do
|
|
|
|
expect(page).to have_selector('.commit', count: 1)
|
|
|
|
end
|
|
|
|
end
|
2020-07-15 21:09:26 +00:00
|
|
|
end
|
|
|
|
|
2017-08-04 09:01:59 +00:00
|
|
|
describe 'race condition' do
|
2017-08-01 18:03:07 +00:00
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:build_push_data) { { ref: 'feature', checkout_sha: TestEnv::BRANCH_SHA['feature'] } }
|
2017-08-04 09:01:59 +00:00
|
|
|
|
2017-08-01 18:03:07 +00:00
|
|
|
let(:merge_request_params) do
|
2017-08-04 12:44:19 +00:00
|
|
|
{ "source_branch" => "feature", "source_project_id" => project.id,
|
|
|
|
"target_branch" => "master", "target_project_id" => project.id, "title" => "A" }
|
2017-08-04 09:01:59 +00:00
|
|
|
end
|
|
|
|
|
2017-08-01 18:03:07 +00:00
|
|
|
before do
|
2018-07-11 14:36:08 +00:00
|
|
|
project.add_maintainer(user)
|
2017-08-04 09:01:59 +00:00
|
|
|
sign_in user
|
2016-08-12 14:23:00 +00:00
|
|
|
end
|
|
|
|
|
2022-02-21 12:16:55 +00:00
|
|
|
context 'when pipeline and merge request were created simultaneously', :delete do
|
2017-08-01 18:03:07 +00:00
|
|
|
before do
|
2017-08-04 09:01:59 +00:00
|
|
|
stub_ci_pipeline_to_return_yaml_file
|
|
|
|
|
|
|
|
threads = []
|
2017-08-04 11:18:05 +00:00
|
|
|
|
2017-08-04 09:01:59 +00:00
|
|
|
threads << Thread.new do
|
2020-12-24 09:10:15 +00:00
|
|
|
Sidekiq::Worker.skipping_transaction_check do
|
2021-05-12 03:10:21 +00:00
|
|
|
@merge_request = MergeRequests::CreateService.new(project: project, current_user: user, params: merge_request_params).execute
|
2020-12-24 09:10:15 +00:00
|
|
|
end
|
2017-08-04 09:01:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
threads << Thread.new do
|
2020-12-24 09:10:15 +00:00
|
|
|
Sidekiq::Worker.skipping_transaction_check do
|
2021-07-20 12:10:29 +00:00
|
|
|
@pipeline = Ci::CreatePipelineService.new(project, user, build_push_data).execute(:push).payload
|
2020-12-24 09:10:15 +00:00
|
|
|
end
|
2017-08-04 09:01:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
threads.each { |thr| thr.join }
|
|
|
|
end
|
|
|
|
|
2019-10-23 09:06:03 +00:00
|
|
|
it 'user sees pipeline in merge request widget', :sidekiq_might_not_need_inline do
|
2017-08-04 09:01:59 +00:00
|
|
|
visit project_merge_request_path(project, @merge_request)
|
2017-08-04 11:18:05 +00:00
|
|
|
|
2017-08-04 09:01:59 +00:00
|
|
|
expect(page.find(".ci-widget")).to have_content(TestEnv::BRANCH_SHA['feature'])
|
|
|
|
expect(page.find(".ci-widget")).to have_content("##{@pipeline.id}")
|
2016-08-12 14:23:00 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|