{"id": "jzcvnlV8g6aseE4A", "name": "GitLab MR Auto-Review & Risk Assessment", "nodes": [{"id": "a82f2b02-538b-4531-921c-d25f1edb97ef", "name": "Extract Diff", "type": "n8n-nodes-base.httpRequest", "position": [860, 320], "parameters": {"url": "= https://gitlab.com/api/v4/projects/{{ encodeURIComponent($json.body.project.path_with_namespace) }}/merge_requests/{{ $json.body.object_attributes.iid }}/changes", "options": {}, "jsonHeaders": "{\n \"Authorization\": \"Bearer glpat-xxxxxxxxxxxxxxxxxxxxxxxxxxxx\"\n}", "sendHeaders": true, "specifyHeaders": "json"}, "typeVersion": 4.2}, {"id": "cd028c77-23e7-46d6-964d-af5afe468176", "name": "Distribution List Generator", "type": "n8n-nodes-base.code", "position": [2040, 160], "parameters": {"jsCode": "const ProjectLeads = {\n \"alpha_backend\": {\n \"dev\": [\"dev1@example.com\", \"dev2@example.com\"],\n \"qa\": [\"qa1@example.com\", \"qa2@example.com\"]\n },\n \"beta_webapp\": {\n \"dev\": [\"dev3@example.com\", \"dev4@example.com\"],\n \"qa\": [\"qa3@example.com\", \"qa4@example.com\"]\n },\n \"gamma_mobile\": {\n \"dev\": [\"dev5@example.com\", \"dev6@example.com\"],\n \"qa\": [\"qa5@example.com\", \"qa6@example.com\", \"qa7@example.com\"]\n },\n \"delta_api\": {\n \"dev\": [\"dev7@example.com\", \"dev8@example.com\", \"dev9@example.com\"],\n \"qa\": [\"qa8@example.com\", \"qa9@example.com\", \"qa10@example.com\"]\n },\n \"epsilon_service\": {\n \"dev\": [\"dev10@example.com\"],\n \"qa\": [\"qa11@example.com\", \"qa12@example.com\"]\n },\n \"zeta_scraper\": {\n \"dev\": [\"dev11@example.com\"],\n \"qa\": [\"qa13@example.com\", \"qa14@example.com\"]\n },\n \"theta_ui\": {\n \"dev\": [\"dev12@example.com\", \"dev13@example.com\"],\n \"qa\": [\"qa15@example.com\", \"qa16@example.com\"]\n },\n \"iota_backend\": {\n \"dev\": [\"dev14@example.com\", \"dev15@example.com\"],\n \"qa\": [\"qa17@example.com\", \"qa18@example.com\"]\n },\n \"kappa_admin\": {\n \"dev\": [\"dev16@example.com\", \"dev17@example.com\"],\n \"qa\": [\"qa19@example.com\", \"qa20@example.com\"]\n }\n};\n\n// Define the GlobalList\nconst GlobalList = [\n \"admin1@example.com\",\n \"admin2@example.com\",\n \"admin3@example.com\"\n];\n\n// Retrieve the project name from the input data and convert it to lowercase\nconst fullName = $('Merge').first().json.body.project.path_with_namespace.toLowerCase();\nconst projectName = fullName.split('/')[1];\n\nlet emails = [];\n\nif (projectName && ProjectLeads[projectName]) {\n // Extract the emails for the given project\n const projectEmails = [\n ...ProjectLeads[projectName].dev,\n ...ProjectLeads[projectName].qa\n ];\n\n // Combine project-specific emails with GlobalList\n emails = [...projectEmails, ...GlobalList];\n} else {\n // Default to GlobalList only if project name is not found or is undefined\n emails = [...GlobalList];\n}\n\n// Handle sender email replacement\nconst senderemail = $('Merge').first().json.body.object_attributes.last_commit.author.email;\nconst oldEmail = \"86149715+user@users.noreply.github.com\";\nconst newEmail = \"user@example.com\";\nconst senderEmail = senderemail.replace(oldEmail, newEmail);\n\n// Add senderEmail to emails list\nemails.push(senderEmail);\n\n// Remove duplicate emails\nemails = [...new Set(emails)];\n\n// Join all emails into a single string\nconst emailsString = emails.join(\", \");\n\n// Return the result\nreturn {\n json: {\n emails: emailsString\n }\n};\n"}, "typeVersion": 2}, {"id": "922c9f5f-2db2-4034-8491-33208f04e580", "name": "If Some Change", "type": "n8n-nodes-base.if", "position": [1100, 320], "parameters": {"options": {}, "conditions": {"options": {"version": 2, "leftValue": "", "caseSensitive": true, "typeValidation": "loose"}, "combinator": "and", "conditions": [{"id": "3c3e0e8b-7469-4394-ab99-a9ac5053197a", "operator": {"type": "array", "operation": "lengthGt", "rightType": "number"}, "leftValue": "={{ $json.changes }}", "rightValue": 0}]}, "looseTypeValidation": true}, "typeVersion": 2.2}, {"id": "e41fc6b0-ccc7-46c9-9667-79b199aaefc8", "name": "Merge", "type": "n8n-nodes-base.merge", "position": [600, 320], "parameters": {}, "executeOnce": true, "typeVersion": 3}, {"id": "1bf7f593-a7d9-48f5-be20-d73e97b030bb", "name": "AI Agent", "type": "@n8n/n8n-nodes-langchain.agent", "position": [1400, 300], "parameters": {"text": "={\n \"model\": \"claude-3-5-haiku-20241022\",\n \"max_tokens\": 1000,\n \"temperature\": 0.7,\n \"tools\": [\n {\n \"name\": \"record_summary\",\n \"description\": \"Record a structured summary of a git diff using well-defined JSON.\",\n \"input_schema\": {\n \"type\": \"object\",\n \"properties\": {\n \"RiskLevel\": {\n \"type\": \"string\",\n \"description\": \"Overall risk assessment of the changes: High/Medium/Low.\"\n },\n \"Summary\": {\n \"type\": \"string\",\n \"description\": \"One-line summary of the git diff analysis\"\n },\n \"Recommendations\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"object\",\n \"properties\": {\n \"Recommendation\": {\n \"type\": \"string\",\n \"description\": \"Specific recommendation in HTML format.\"\n },\n \"CodeSnippet\": {\n \"type\": \"string\",\n \"description\": \"Relevant code full snippet formatted in HTML.\"\n }\n },\n \"required\": [\"Recommendation\", \"CodeSnippet\"]\n }\n },\n \"Issues\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"object\",\n \"properties\": {\n \"File\": {\n \"type\": \"string\",\n \"description\": \"HTML-formatted name of the file where the issue exists.\"\n },\n \"PotentialIssue\": {\n \"type\": \"string\",\n \"description\": \"HTML-formatted description of the issue.\"\n },\n \"Severity\": {\n \"type\": \"string\",\n \"description\": \"Severity of the issue: High/Medium/Low in HTML.\"\n }\n },\n \"required\": [\"File\", \"PotentialIssue\", \"Severity\"]\n }\n },\n \"URL\": {\n \"type\": \"string\",\n \"description\": \"Link to the repository in HTML.\"\n },\n \"DiffTable\": {\n \"type\": \"object\",\n \"properties\": {\n \"FileName\": {\n \"type\": \"string\",\n \"description\": \"HTML-formatted name of the file.\"\n },\n \"Changes\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"object\",\n \"properties\": {\n \"Line\": {\n \"type\": \"string\",\n \"description\": \"HTML-formatted line number.\"\n },\n \"Before\": {\n \"type\": \"string\",\n \"description\": \"Code before the change formatted in HTML.\"\n },\n \"After\": {\n \"type\": \"string\",\n \"description\": \"Code after the change formatted in HTML.\"\n }\n },\n \"required\": [\"Line\", \"Before\", \"After\"]\n }\n }\n }\n },\n \"TestCases\": {\n \"type\": \"array\",\n \"description\": \"List of test cases the QA team must check.\",\n \"items\": {\n \"type\": \"object\",\n \"properties\": {\n \"TestFor\": {\n \"type\": \"string\",\n \"description\": \"Description of the functionality or area to test.\"\n },\n \"Steps\": {\n \"type\": \"string\",\n \"description\": \"HTML-formatted steps to test the functionality.\"\n },\n \"ExpectedOutcome\": {\n \"type\": \"string\",\n \"description\": \"HTML-formatted description of the expected result of the test.\"\n }\n },\n \"required\": [\"TestFor\", \"Steps\", \"ExpectedOutcome\"]\n }\n }\n },\n \"required\": [\"RiskLevel\", \"Summary\", \"Recommendations\", \"Issues\", \"URL\", \"DiffTable\", \"TestCases\"]\n }\n }\n ],\n \"tool_choice\": {\n \"type\": \"tool\",\n \"name\": \"record_summary\"\n },\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": [\n {\n \"type\": \"text\",\n \"text\": \"Analyze the following git diff, highlight potential issues, provide recommendations with code snippets (using HTML formatting for all values), and include the URL. Ensure proper risk evaluation. Mark issues that may break the build or reveal a security risk as High':\"\n },\n {\n \"type\": \"text\",\n \"text\": \"{{ $json.changes.map(change => JSON.stringify(change.diff).slice(1, -1).replace(/[\\r]/g, '')).join(' ') }}\"\n },\n {\n \"type\": \"text\",\n \"text\": \"URL: {{ $json.web_url }}\"\n },\n {\n \"type\": \"text\",\n \"text\": \"Provide a table of test cases for the QA team under the 'TestCases' field.\"\n }\n ]\n }\n ]\n}", "options": {}, "promptType": "define", "hasOutputParser": true}, "typeVersion": 1.7}, {"id": "f888ea7c-04d4-4192-aa72-10c341da80c8", "name": "Auto-fixing Output Parser", "type": "@n8n/n8n-nodes-langchain.outputParserAutofixing", "position": [1540, 600], "parameters": {"options": {}}, "typeVersion": 1}, {"id": "e52227f3-e606-4ec9-b338-c36fe7ca4b6d", "name": "Structured Output Parser", "type": "@n8n/n8n-nodes-langchain.outputParserStructured", "position": [1760, 940], "parameters": {"schemaType": "manual", "inputSchema": "{\n \"type\": \"object\",\n \"properties\": {\n \"RiskLevel\": {\n \"type\": \"string\",\n \"description\": \"Overall risk assessment of the changes: High/Medium/Low.\"\n },\n \"Summary\": {\n \"type\": \"string\",\n \"description\": \"One-line summary of the git diff analysis in HTML.\"\n },\n \"Recommendations\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"object\",\n \"properties\": {\n \"Recommendation\": {\n \"type\": \"string\",\n \"description\": \"Specific recommendation in HTML format.\"\n },\n \"CodeSnippet\": {\n \"type\": \"string\",\n \"description\": \"Relevant code snippet formatted in HTML.\"\n }\n },\n \"required\": [\"Recommendation\", \"CodeSnippet\"]\n }\n },\n \"Issues\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"object\",\n \"properties\": {\n \"File\": {\n \"type\": \"string\",\n \"description\": \"HTML-formatted name of the file where the issue exists.\"\n },\n \"PotentialIssue\": {\n \"type\": \"string\",\n \"description\": \"HTML-formatted description of the issue.\"\n },\n \"Severity\": {\n \"type\": \"string\",\n \"description\": \"Severity of the issue: High/Medium/Low in HTML.\"\n }\n },\n \"required\": [\"File\", \"PotentialIssue\", \"Severity\"]\n }\n },\n \"URL\": {\n \"type\": \"string\",\n \"description\": \"Link to the repository in HTML.\"\n },\n \"DiffTable\": {\n \"type\": \"object\",\n \"properties\": {\n \"FileName\": {\n \"type\": \"string\",\n \"description\": \"HTML-formatted name of the file.\"\n },\n \"Changes\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"object\",\n \"properties\": {\n \"Line\": {\n \"type\": \"string\",\n \"description\": \"HTML-formatted line number.\"\n },\n \"Before\": {\n \"type\": \"string\",\n \"description\": \"Code before the change formatted in HTML.\"\n },\n \"After\": {\n \"type\": \"string\",\n \"description\": \"Code after the change formatted in HTML.\"\n }\n },\n \"required\": [\"Line\", \"Before\", \"After\"]\n }\n }\n }\n },\n \"TestCases\": {\n \"type\": \"array\",\n \"description\": \"List of test cases the QA team must check.\",\n \"items\": {\n \"type\": \"object\",\n \"properties\": {\n \"TestFor\": {\n \"type\": \"string\",\n \"description\": \"Description of the functionality or area to test.\"\n },\n \"Steps\": {\n \"type\": \"string\",\n \"description\": \"HTML-formatted steps to test the functionality.\"\n },\n \"ExpectedOutcome\": {\n \"type\": \"string\",\n \"description\": \"HTML-formatted description of the expected result of the test.\"\n }\n },\n \"required\": [\"TestFor\", \"Steps\", \"ExpectedOutcome\"]\n }\n }\n },\n \"required\": [\"RiskLevel\", \"Summary\", \"Recommendations\", \"Issues\", \"URL\", \"DiffTable\", \"TestCases\"]\n}"}, "typeVersion": 1.2}, {"id": "360985e5-1195-4411-ab5e-daf182f3be9b", "name": "Anthropic Chat Model", "type": "@n8n/n8n-nodes-langchain.lmChatAnthropic", "position": [1560, 940], "parameters": {"model": "claude-3-5-haiku-20241022", "options": {}}, "credentials": {"anthropicApi": {"id": "9ZxBT7yu9DmfOCQi", "name": "Anthropic account Vishal"}}, "typeVersion": 1.2}, {"id": "e912886a-2a4c-4f82-b14b-71db3ee2b616", "name": "Anthropic Chat Model1", "type": "@n8n/n8n-nodes-langchain.lmChatAnthropic", "position": [1400, 940], "parameters": {"model": "claude-3-5-haiku-20241022", "options": {}}, "credentials": {"anthropicApi": {"id": "9ZxBT7yu9DmfOCQi", "name": "Anthropic account Vishal"}}, "typeVersion": 1.2}, {"id": "320b0fa4-f864-4a3c-8d25-f2cac2512fbf", "name": "Comment Back on MR", "type": "n8n-nodes-base.httpRequest", "position": [2040, 480], "parameters": {"url": "= https://gitlab.com/api/v4/projects/{{ encodeURIComponent( $('Merge').item.json.body.project.path_with_namespace) }}/merge_requests/{{ $('Merge').item.json.body.object_attributes.iid }}/notes", "method": "POST", "options": {}, "sendBody": true, "jsonHeaders": "{\n \"Authorization\": \"Bearer glpatdemo -1234567890abcdef1234567890demo\"\n}\n", "sendHeaders": true, "bodyParameters": {"parameters": [{"name": "body", "value": "=# CodeSnape by Quantana\n\n**Summary**