Commit ffecffce authored by Max Woolf's avatar Max Woolf

Adds jira issue enforcement field

Adds a new field to project level settings
behind a default-off feature flag which will
eventually prevent the merging of a merge request
without an associated Jira issue.
parent 1982e005
...@@ -396,6 +396,14 @@ class ProjectsController < Projects::ApplicationController ...@@ -396,6 +396,14 @@ class ProjectsController < Projects::ApplicationController
] ]
end end
def project_setting_attributes
%i[
show_default_award_emojis
squash_option
allow_editing_commit_messages
]
end
def project_params_attributes def project_params_attributes
[ [
:allow_merge_on_skipped_pipeline, :allow_merge_on_skipped_pipeline,
...@@ -433,11 +441,7 @@ class ProjectsController < Projects::ApplicationController ...@@ -433,11 +441,7 @@ class ProjectsController < Projects::ApplicationController
:suggestion_commit_message, :suggestion_commit_message,
:packages_enabled, :packages_enabled,
:service_desk_enabled, :service_desk_enabled,
project_setting_attributes: %i[ project_setting_attributes: project_setting_attributes
show_default_award_emojis
squash_option
allow_editing_commit_messages
]
] + [project_feature_attributes: project_feature_attributes] ] + [project_feature_attributes: project_feature_attributes]
end end
......
...@@ -21,4 +21,4 @@ class ProjectSetting < ApplicationRecord ...@@ -21,4 +21,4 @@ class ProjectSetting < ApplicationRecord
end end
end end
ProjectSetting.prepend_if_ee('EE::ProjectSetting') ProjectSetting.prepend_ee_mod
...@@ -24,3 +24,4 @@ ...@@ -24,3 +24,4 @@
= form.check_box :only_allow_merge_if_all_discussions_are_resolved, class: 'form-check-input', data: { qa_selector: 'allow_merge_if_all_discussions_are_resolved_checkbox' } = form.check_box :only_allow_merge_if_all_discussions_are_resolved, class: 'form-check-input', data: { qa_selector: 'allow_merge_if_all_discussions_are_resolved_checkbox' }
= form.label :only_allow_merge_if_all_discussions_are_resolved, class: 'form-check-label' do = form.label :only_allow_merge_if_all_discussions_are_resolved, class: 'form-check-label' do
= s_('ProjectSettings|All discussions must be resolved') = s_('ProjectSettings|All discussions must be resolved')
= render_if_exists 'projects/merge_request_merge_checks_jira_enforcement', form: form, project: @project
---
title: Adds jira issue enforcement field
merge_request: 52896
author:
type: added
# frozen_string_literal: true
class AddPreventMergeWithoutJiraIssueToProjectSettings < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def up
with_lock_retries do
add_column :project_settings, :prevent_merge_without_jira_issue, :boolean, null: false, default: false
end
end
def down
with_lock_retries do
remove_column :project_settings, :prevent_merge_without_jira_issue
end
end
end
ae84fa35fcc5a0780d86887294a32e250d2ac13dcf607750f834df5828e5bece
\ No newline at end of file
...@@ -16039,6 +16039,7 @@ CREATE TABLE project_settings ( ...@@ -16039,6 +16039,7 @@ CREATE TABLE project_settings (
has_confluence boolean DEFAULT false NOT NULL, has_confluence boolean DEFAULT false NOT NULL,
has_vulnerabilities boolean DEFAULT false NOT NULL, has_vulnerabilities boolean DEFAULT false NOT NULL,
allow_editing_commit_messages boolean DEFAULT false NOT NULL, allow_editing_commit_messages boolean DEFAULT false NOT NULL,
prevent_merge_without_jira_issue boolean DEFAULT false NOT NULL,
CONSTRAINT check_bde223416c CHECK ((show_default_award_emojis IS NOT NULL)) CONSTRAINT check_bde223416c CHECK ((show_default_award_emojis IS NOT NULL))
); );
......
...@@ -73,6 +73,11 @@ module EE ...@@ -73,6 +73,11 @@ module EE
private private
override :project_setting_attributes
def project_setting_attributes
super + [:prevent_merge_without_jira_issue]
end
def project_params_ee def project_params_ee
attrs = %i[ attrs = %i[
approvals_before_merge approvals_before_merge
......
...@@ -232,6 +232,11 @@ module EE ...@@ -232,6 +232,11 @@ module EE
accepts_nested_attributes_for :compliance_framework_setting, update_only: true, allow_destroy: true accepts_nested_attributes_for :compliance_framework_setting, update_only: true, allow_destroy: true
alias_attribute :fallback_approvals_required, :approvals_before_merge alias_attribute :fallback_approvals_required, :approvals_before_merge
def jira_issue_association_required_to_merge_enabled?
::Feature.enabled?(:jira_issue_association_on_merge_request, self) &&
feature_available?(:jira_issue_association_enforcement)
end
end end
class_methods do class_methods do
......
...@@ -152,6 +152,7 @@ class License < ApplicationRecord ...@@ -152,6 +152,7 @@ class License < ApplicationRecord
insights insights
issuable_health_status issuable_health_status
jira_vulnerabilities_integration jira_vulnerabilities_integration
jira_issue_association_enforcement
license_scanning license_scanning
personal_access_token_expiration_policy personal_access_token_expiration_policy
project_activity_analytics project_activity_analytics
......
- project = local_assigns.fetch(:project)
- if project.jira_issue_association_required_to_merge_enabled?
.form-check.gl-mb-3
= form.fields_for :project_setting do |settings|
= settings.check_box :prevent_merge_without_jira_issue, class: 'form-check-input'
= settings.label :prevent_merge_without_jira_issue, class: 'form-check-label' do
= s_('ProjectSettings|Require an associated issue from Jira')
---
name: jira_issue_association_on_merge_request
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/52896
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/300271
milestone: '13.9'
type: development
group: group::compliance
default_enabled: false
...@@ -56,6 +56,28 @@ RSpec.describe Project do ...@@ -56,6 +56,28 @@ RSpec.describe Project do
it { is_expected.to have_many(:incident_management_oncall_schedules).class_name('IncidentManagement::OncallSchedule') } it { is_expected.to have_many(:incident_management_oncall_schedules).class_name('IncidentManagement::OncallSchedule') }
describe '#jira_issue_association_required_to_merge_enabled?' do
using RSpec::Parameterized::TableSyntax
where(:licensed, :feature_flag, :result) do
true | true | true
true | false | false
false | false | false
false | true | false
end
before do
stub_licensed_features(jira_issue_association_enforcement: licensed)
stub_feature_flags(jira_issue_association_on_merge_request: feature_flag)
end
with_them do
it 'returns the correct value' do
expect(project.jira_issue_association_required_to_merge_enabled?).to eq(result)
end
end
end
describe 'approval_rules association' do describe 'approval_rules association' do
let_it_be(:rule, reload: true) { create(:approval_project_rule) } let_it_be(:rule, reload: true) { create(:approval_project_rule) }
let(:project) { rule.project } let(:project) { rule.project }
......
...@@ -23006,6 +23006,9 @@ msgstr "" ...@@ -23006,6 +23006,9 @@ msgstr ""
msgid "ProjectSettings|Require" msgid "ProjectSettings|Require"
msgstr "" msgstr ""
msgid "ProjectSettings|Require an associated issue from Jira"
msgstr ""
msgid "ProjectSettings|Requirements" msgid "ProjectSettings|Requirements"
msgstr "" msgstr ""
......
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