Implementing trigger merge_request_code_conflict
What does this MR do and why?
Implementing trigger merge_request_conflict.
This is adding a new trigger type (Merge Request Code Conflict) that is triggered when open MRs have code conflict. They can trigger custom flows. See the related issue for more information.
Addressing: #592455 (closed)
Screenshots or screen recordings
How to set up and validate locally
- Enable the FF
Feature.enable(:merge_request_code_conflict_flow_trigger) - Create a flow and enable it on a project. See the reference project later in this MR. You can create your own Flow instead.
- Create an MR on a project
- Modify the project source code to cause a code conflict on the MR that you created before.
- You should see a flow started on the MR and some analysis posted on the MR. See the screenshot
Reference flow
version: "v1"
environment: ambient
flow:
entry_point: "conflict_analyzer"
components:
- name: "conflict_analyzer"
type: AgentComponent
prompt_id: "conflict_analysis_prompt"
inputs:
- from: "context:goal"
as: "mr_iid"
- from: "context:project_id"
as: "project_id"
toolset:
- "get_merge_request"
- "list_merge_request_diffs"
- "list_commits"
- "get_repository_file"
- "list_repository_tree"
- "create_merge_request_note"
ui_log_events:
- "on_agent_final_answer"
- "on_tool_execution_success"
- "on_tool_execution_failed"
routers:
- from: "conflict_analyzer"
to: "end"
prompts:
- name: "MR Conflict Analyzer"
prompt_id: "conflict_analysis_prompt"
unit_primitives: []
prompt_template:
system: |
You are an expert code conflict analyst. Your job is to analyze a GitLab merge request
that has a merge conflict and post a clear, actionable comment explaining why the
conflict occurred and how to resolve it.
Steps:
1. Use get_merge_request with project_id={{project_id}} and mr_iid={{mr_iid}}
2. Use list_merge_request_diffs to get the full diff
3. Use list_commits to understand recent changes on both branches
4. Use get_repository_file on conflicting files if more context is needed
5. Post a comment using create_merge_request_note with the analysis below
The comment MUST follow this structure:
## 🔀 Merge Conflict Analysis
### Conflicting Files
List each file and what changed in both branches.
### Root Cause
Explain clearly why the conflict occurred.
### Resolution Steps
Numbered steps to resolve locally:
- git checkout <source-branch>
- git fetch origin
- git merge origin/<target-branch>
- For each conflicting file: what to keep, remove, or combine
- git add <files>
- git commit && git push
### Tips
Any extra context (e.g. which side should take precedence, or if rebase is preferred).
user: |
Project ID: {{project_id}}
MR IID: {{mr_iid}}MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Related to #592455 (closed)
Edited by Omar Qunsul
