Commit 79c2fc75 authored by Shinya Maeda's avatar Shinya Maeda

Merge branch...

Merge branch '213052-mr-prompts-to-create-gitlab-ci-yml-even-if-the-project-has-already-had-it' into 'master'

Resolve "MR prompts to create .gitlab-ci.yml even if the project has already had it"

Closes #213052

See merge request gitlab-org/gitlab!28563
parents 8629e93a 3c879350
...@@ -96,7 +96,7 @@ class MergeRequestWidgetEntity < Grape::Entity ...@@ -96,7 +96,7 @@ class MergeRequestWidgetEntity < Grape::Entity
def can_add_ci_config_path?(merge_request) def can_add_ci_config_path?(merge_request)
merge_request.source_project&.uses_default_ci_config? && merge_request.source_project&.uses_default_ci_config? &&
merge_request.all_pipelines.none? && !merge_request.source_project.has_ci? &&
merge_request.commits_count.positive? && merge_request.commits_count.positive? &&
can?(current_user, :read_build, merge_request.source_project) && can?(current_user, :read_build, merge_request.source_project) &&
can?(current_user, :create_pipeline, merge_request.source_project) can?(current_user, :create_pipeline, merge_request.source_project)
......
...@@ -54,15 +54,17 @@ describe MergeRequestWidgetEntity do ...@@ -54,15 +54,17 @@ describe MergeRequestWidgetEntity do
end end
describe 'merge_request_add_ci_config_path' do describe 'merge_request_add_ci_config_path' do
let!(:project_auto_devops) { create(:project_auto_devops, :disabled, project: project) }
before do before do
project.add_role(user, role) project.add_role(user, role)
end end
context 'when there are pipelines' do context 'when there is a standard ci config file in the source project' do
let(:role) { :developer } let(:role) { :developer }
before do before do
create(:ci_empty_pipeline, project: project, sha: resource.all_commit_shas.first, ref: resource.source_branch) project.repository.create_file(user, Gitlab::FileDetector::PATTERNS[:gitlab_ci], 'CONTENT', message: 'Add .gitlab-ci.yml', branch_name: 'master')
end end
it 'no ci config path' do it 'no ci config path' do
...@@ -70,7 +72,7 @@ describe MergeRequestWidgetEntity do ...@@ -70,7 +72,7 @@ describe MergeRequestWidgetEntity do
end end
end end
context 'when there are no pipelines' do context 'when there is no standard ci config file in the source project' do
context 'when user has permissions' do context 'when user has permissions' do
let(:role) { :developer } let(:role) { :developer }
...@@ -80,6 +82,16 @@ describe MergeRequestWidgetEntity do ...@@ -80,6 +82,16 @@ describe MergeRequestWidgetEntity do
expect(subject[:merge_request_add_ci_config_path]).to eq(expected_path) expect(subject[:merge_request_add_ci_config_path]).to eq(expected_path)
end end
context 'when auto devops is enabled' do
before do
project_auto_devops.enabled = true
end
it 'returns a blank ci config path' do
expect(subject[:merge_request_add_ci_config_path]).to be_nil
end
end
context 'when source project is missing' do context 'when source project is missing' do
before do before do
resource.source_project = nil resource.source_project = nil
......
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