Commit 0edb65c0 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'add-merge-pipelines-and-trains-to-api' into 'master'

Allow updating merged results pipelines and merge trains via API [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!56237
parents b477eb98 624d6690
......@@ -39,6 +39,8 @@ module EE
end
expose :issues_template, if: ->(project, _) { project.feature_available?(:issuable_default_templates) }
expose :merge_requests_template, if: ->(project, _) { project.feature_available?(:issuable_default_templates) }
expose :merge_pipelines_enabled?, as: :merge_pipelines_enabled, if: ->(project, _) { project.feature_available?(:merge_pipelines) }
expose :merge_trains_enabled?, as: :merge_trains_enabled, if: ->(project, _) { project.feature_available?(:merge_pipelines) }
end
end
end
......
......@@ -35,6 +35,8 @@ module EE
optional :fallback_approvals_required, type: Integer, desc: 'Overall approvals required when no rule is present'
optional :issues_template, type: String, desc: 'Default description for Issues. Description is parsed with GitLab Flavored Markdown.'
optional :merge_requests_template, type: String, desc: 'Default description for merge requests. Description is parsed with GitLab Flavored Markdown.'
optional :merge_pipelines_enabled, type: Grape::API::Boolean, desc: 'Enable merged results pipelines.'
optional :merge_trains_enabled, type: Grape::API::Boolean, desc: 'Enable merge trains.'
end
end
......@@ -53,7 +55,9 @@ module EE
:fallback_approvals_required,
:import_url,
:issues_template,
:merge_requests_template
:merge_requests_template,
:merge_pipelines_enabled,
:merge_trains_enabled
]
end
end
......
......@@ -83,6 +83,7 @@ module EE
verify_mirror_attrs!(project, attrs)
verify_issuable_default_templates_attrs!(project, attrs)
verify_merge_pipelines_attrs!(project, attrs)
end
def verify_mirror_attrs!(project, attrs)
......@@ -100,6 +101,13 @@ module EE
end
end
def verify_merge_pipelines_attrs!(project, attrs)
return if can?(current_user, :admin_project, project)
attrs.delete(:merge_pipelines_enabled) unless project.feature_available?(:merge_pipelines)
attrs.delete(:merge_trains_enabled) unless project.feature_available?(:merge_trains)
end
def check_audit_events_available!(project)
forbidden! unless project.feature_available?(:audit_events)
end
......
......@@ -303,6 +303,60 @@ RSpec.describe API::Projects do
expect(json_response).not_to have_key 'merge_requests_template'
end
end
context 'merge pipelines feature is available' do
before do
stub_licensed_features(merge_pipelines: true)
end
it 'returns merge pipelines enabled flag' do
subject
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to have_key 'merge_pipelines_enabled'
end
end
context 'merge pipelines feature not available' do
before do
stub_licensed_features(merge_pipelines: false)
end
it 'does not return merge pipelines enabled flag' do
subject
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).not_to have_key 'merge_pipelines_enabled'
end
end
context 'merge trains feature is available' do
before do
stub_licensed_features(merge_pipelines: true, merge_trains: true)
project.update!(merge_pipelines_enabled: true, merge_trains_enabled: true)
stub_feature_flags(disable_merge_trains: false)
end
it 'returns merge trains enabled flag' do
subject
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to have_key 'merge_trains_enabled'
end
end
context 'merge trains feature not available' do
before do
stub_licensed_features(merge_trains: false)
end
it 'does not return merge trains enabled flag' do
subject
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).not_to have_key 'merge_trains_enabled'
end
end
end
# Assumes the following variables are defined:
......@@ -891,6 +945,102 @@ RSpec.describe API::Projects do
end
end
context 'merge pipelines feature is available' do
before do
stub_licensed_features(merge_pipelines: true)
end
let(:project_params) { { merge_pipelines_enabled: true } }
it 'updates the content' do
expect { subject }.to change { project.reload.merge_pipelines_enabled }
expect(response).to have_gitlab_http_status(:ok)
expect(project.merge_pipelines_enabled).to eq(project_params[:merge_pipelines_enabled])
expect(json_response['merge_pipelines_enabled']).to eq(project_params[:merge_pipelines_enabled])
end
context 'when user does not have permission' do
let(:developer_user) { create(:user) }
before do
project.add_developer(developer_user)
end
it 'does not update the content' do
expect do
put api("/projects/#{project.id}", developer_user), params: project_params
end.not_to change { project.reload.merge_pipelines_enabled }
expect(response).to have_gitlab_http_status(:forbidden)
end
end
end
context 'merge pipelines feature feature not available' do
before do
stub_licensed_features(merge_pipelines: false)
end
let(:project_params) { { merge_pipelines_enabled: true } }
it 'does not update the content' do
subject
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).not_to have_key 'merge_pipelines_enabled'
end
end
context 'merge trains feature is available' do
before do
stub_licensed_features(merge_pipelines: true, merge_trains: true)
project.update!(merge_pipelines_enabled: true, merge_trains_enabled: false)
stub_feature_flags(disable_merge_trains: false)
end
let(:project_params) { { merge_trains_enabled: true } }
it 'updates the content' do
expect { subject }.to change { project.reload.merge_trains_enabled }
expect(response).to have_gitlab_http_status(:ok)
expect(project.merge_trains_enabled).to eq(project_params[:merge_trains_enabled])
expect(json_response['merge_trains_enabled']).to eq(project_params[:merge_trains_enabled])
end
context 'when user does not have permission' do
let(:developer_user) { create(:user) }
before do
project.add_developer(developer_user)
end
it 'does not update the content' do
expect do
put api("/projects/#{project.id}", developer_user), params: project_params
end.not_to change { project.reload.merge_trains_enabled }
expect(response).to have_gitlab_http_status(:forbidden)
end
end
end
context 'merge trains feature feature not available' do
before do
stub_licensed_features(merge_trains: false)
end
let(:project_params) { { merge_trains_enabled: true } }
it 'does not update the content' do
expect { subject }.not_to change { project.merge_trains_enabled }
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).not_to have_key 'merge_trains_enabled'
end
end
context 'when updating external classification' do
before do
enable_external_authorization_service_check
......
......@@ -132,7 +132,10 @@ module API
:forking_access_level,
:issues_access_level,
:lfs_enabled,
:merge_pipelines_enabled,
:merge_requests_access_level,
:merge_requests_template,
:merge_trains_enabled,
:merge_method,
:name,
:only_allow_merge_if_all_discussions_are_resolved,
......
......@@ -89,6 +89,8 @@ ci_cd_settings:
- group_runners_enabled
- merge_pipelines_enabled
- merge_trains_enabled
- merge_pipelines_enabled
- merge_trains_enabled
- auto_rollback_enabled
remapped_attributes:
default_git_depth: ci_default_git_depth
......
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