Skip to content
Snippets Groups Projects
Verified Commit 6f58bf75 authored by Lucas Charles's avatar Lucas Charles :speech_balloon: Committed by GitLab
Browse files

Merge branch '468461-support-pipeline-context-in-duo-chat-api' into 'master'

Support pipeline job context in Duo Chat API

See merge request !167731



Merged-by: default avatarLucas Charles <me@lucascharles.me>
Approved-by: default avatarLesley Razzaghian <lrazzaghian@gitlab.com>
Approved-by: default avatarLucas Charles <me@lucascharles.me>
Reviewed-by: default avatarLucas Charles <me@lucascharles.me>
Co-authored-by: default avatarEva Kadlecová <ekadlecova@gitlab.com>
parents f0dcdd84 0c131ec4
No related branches found
No related tags found
2 merge requests!170053Security patch upgrade alert: Only expose to admins 17-4,!167731Support pipeline job context in Duo Chat API
Pipeline #1481474675 failed
......@@ -8,7 +8,8 @@ class Chat < ::API::Base
allow_access_with_scope :ai_features
AVAILABLE_RESOURCES = %w[issue epic group project merge_request commit].freeze
AVAILABLE_RESOURCES = %w[issue epic group project merge_request commit build].freeze
RESOURCE_TYPE_MAPPING = { 'build' => 'Ci::Build' }.freeze
before do
authenticate!
......@@ -26,7 +27,8 @@ def find_resource(parameters)
return current_user unless parameters[:resource_type] && parameters[:resource_id]
return commit_object(parameters) if parameters[:resource_type] == 'commit'
object = parameters[:resource_type].camelize.safe_constantize
resource_type = RESOURCE_TYPE_MAPPING[parameters[:resource_type]] || parameters[:resource_type]
object = resource_type.camelize.safe_constantize
object.find(parameters[:resource_id])
end
......
......@@ -278,6 +278,23 @@
end
end
context 'with a build' do
let_it_be(:ci_build) { create(:ci_build, :failed, :trace_live, project: project) }
let!(:resource) { ci_build }
let(:params) do
{ content: content, resource_type: "build", resource_id: resource.id, project_id: resource.project.id }
end
it 'sends resource to the chat' do
expect(chat_message).to receive(:save!)
expect(Gitlab::Llm::ChatMessage).to receive(:new).with(chat_message_params).and_return(chat_message)
expect(Llm::Internal::CompletionService).to receive(:new).with(chat_message, options).and_return(chat)
expect(chat).to receive(:execute)
post_api
end
end
context 'without resource' do
let(:params) { { content: content } }
let(:resource) { current_user }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment