Skip to content
代码片段 群组 项目
未验证 提交 2c7f4d65 编辑于 作者: Matthias Käppler's avatar Matthias Käppler 提交者: GitLab
浏览文件

Merge branch 'ph/463539/mergeCommitUnitPrimitive' into 'master'

Added unit primitive for generate AI commit message

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/157432



Merged-by: default avatarMatthias Käppler <mkaeppler@gitlab.com>
Approved-by: default avatarAlex Buijs <abuijs@gitlab.com>
Approved-by: default avatarMatthias Käppler <mkaeppler@gitlab.com>
Reviewed-by: default avatarMatthias Käppler <mkaeppler@gitlab.com>
Co-authored-by: default avatarPhil Hughes <me@iamphill.com>
No related branches found
No related tags found
无相关合并请求
......@@ -198,6 +198,28 @@ module GlobalPolicy
rule { security_policy_bot }.policy do
enable :access_git
end
condition(:generate_commit_message_licensed) do
next false unless ::Feature.enabled?(:generate_commit_message_flag, @user)
::License.feature_available?(:generate_commit_message)
end
condition(:user_allowed_to_use_generate_commit_message) do
if generate_commit_message_data.free_access?
user.any_group_with_ai_available?
else
generate_commit_message_data.allowed_for?(@user)
end
end
rule { generate_commit_message_licensed & user_allowed_to_use_generate_commit_message }.policy do
enable :access_generate_commit_message
end
end
def generate_commit_message_data
CloudConnector::AvailableServices.find_by_name(:generate_commit_message)
end
def duo_chat_free_access_was_cut_off?
......
......@@ -4,9 +4,8 @@ module Llm
class GenerateCommitMessageService < BaseService
def valid?
super &&
Feature.enabled?(:generate_commit_message_flag, user) &&
resource.resource_parent.root_ancestor.licensed_feature_available?(:generate_commit_message) &&
Gitlab::Llm::StageCheck.available?(resource.resource_parent, :generate_commit_message)
Gitlab::Llm::StageCheck.available?(resource.resource_parent, :generate_commit_message) &&
user.can?(:access_generate_commit_message)
end
private
......
......@@ -72,3 +72,9 @@ services: # Cloud connector features (i.e. code_suggestions, duo_chat...)
unit_primitives:
- code_suggestions
- duo_chat
generate_commit_message:
backend: 'gitlab-ai-gateway'
bundled_with:
duo_enterprise:
unit_primitives:
- generate_commit_message
......@@ -56,6 +56,14 @@
}
end
let_it_be(:generate_commit_message_bundled_with) do
{
"duo_enterprise" => %i[
generate_commit_message
]
}
end
include_examples 'access data reader' do
let_it_be(:available_service_data_class) { CloudConnector::SelfSigned::AvailableServiceData }
let_it_be(:arguments_map) do
......@@ -65,7 +73,8 @@
anthropic_proxy: [nil, anthropic_proxy_bundled_with, backend],
vertex_ai_proxy: [nil, vertex_ai_proxy_bundled_with, backend],
resolve_vulnerability: [nil, resolve_vulnerability_bundled_with, backend],
self_hosted_models: [self_hosted_models_cut_off_date, self_hosted_models_bundled_with, backend]
self_hosted_models: [self_hosted_models_cut_off_date, self_hosted_models_bundled_with, backend],
generate_commit_message: [nil, generate_commit_message_bundled_with, backend]
}
end
end
......
......@@ -833,4 +833,36 @@
it { is_expected.to be_disallowed(:manage_ai_settings) }
end
end
describe 'access_generate_commit_message' do
let(:policy) { :access_generate_commit_message }
where(:flag_enabled, :licensed, :free_access, :any_group_with_ai_available, :allowed_for,
:enabled_for_user) do
false | false | false | false | false | be_disallowed(:access_generate_commit_message)
true | false | false | false | false | be_disallowed(:access_generate_commit_message)
true | true | true | false | false | be_disallowed(:access_generate_commit_message)
true | true | false | false | false | be_disallowed(:access_generate_commit_message)
true | true | false | false | true | be_allowed(:access_generate_commit_message)
true | true | true | true | false | be_allowed(:access_generate_commit_message)
end
with_them do
before do
stub_licensed_features(generate_commit_message: licensed)
stub_feature_flags(generate_commit_message_flag: flag_enabled)
service_data = CloudConnector::SelfManaged::AvailableServiceData.new(:generate_commit_message, nil, nil)
allow(CloudConnector::AvailableServices).to receive(:find_by_name)
.with(:generate_commit_message)
.and_return(service_data)
allow(service_data).to receive(:allowed_for?).with(current_user).and_return(allowed_for)
allow(service_data).to receive(:free_access?).and_return(free_access)
allow(current_user).to receive(:any_group_with_ai_available?)
.and_return(any_group_with_ai_available)
end
it { is_expected.to enabled_for_user }
end
end
end
......@@ -25,6 +25,12 @@
stub_ee_application_setting(should_check_namespace_plan: true)
stub_licensed_features(generate_commit_message: true, ai_features: true, experimental_features: true)
group.namespace_settings.update!(experiment_features_enabled: true)
service_data = CloudConnector::SelfManaged::AvailableServiceData.new(:generate_commit_message, nil, nil)
allow(CloudConnector::AvailableServices).to receive(:find_by_name)
.with(:generate_commit_message)
.and_return(service_data)
allow(service_data).to receive(:allowed_for?).with(current_user).and_return(true)
end
it 'successfully performs an generate commit message request' do
......
......@@ -14,19 +14,24 @@
before do
stub_ee_application_setting(should_check_namespace_plan: true)
stub_licensed_features(generate_commit_message: true, ai_features: true, experimental_features: true)
allow(user).to receive(:can?).with("read_merge_request", resource).and_call_original
allow(user).to receive(:can?).with(:access_duo_features, resource.project).and_call_original
allow(user).to receive(:can?).with(:admin_all_resources).and_call_original
group.namespace_settings.update!(experiment_features_enabled: true)
end
describe '#execute' do
before do
project.root_ancestor.namespace_settings.update!(
experiment_features_enabled: true
)
allow(Llm::CompletionWorker).to receive(:perform_for)
end
context 'when the user is permitted to view the merge request' do
before do
group.add_developer(user)
allow(user).to receive(:can?).with(:access_generate_commit_message).and_return(true)
end
it_behaves_like 'schedules completion worker' do
......@@ -62,7 +67,7 @@
describe '#valid?' do
using RSpec::Parameterized::TableSyntax
where(:experiment_features_enabled, :result) do
where(:access_generate_commit_message, :result) do
true | true
false | false
end
......@@ -70,9 +75,8 @@
with_them do
before do
group.add_maintainer(user)
project.root_ancestor.namespace_settings.update!(
experiment_features_enabled: experiment_features_enabled
)
allow(user).to receive(:can?).with(:access_generate_commit_message).and_return(access_generate_commit_message)
end
subject { described_class.new(user, resource, options) }
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册