{
  "name": "PR_Automation",
  "nodes": [
    {
      "parameters": {
        "authentication": "oAuth2",
        "owner": {
          "__rl": true,
          "value": "HemaKumar0077",
          "mode": "list",
          "cachedResultName": "HemaKumar0077",
          "cachedResultUrl": "https://github.com/HemaKumar0077"
        },
        "repository": {
          "__rl": true,
          "value": "ID-Card_Generator",
          "mode": "list",
          "cachedResultName": "ID-Card_Generator",
          "cachedResultUrl": "https://github.com/HemaKumar0077/ID-Card_Generator"
        },
        "events": [
          "pull_request"
        ],
        "options": {}
      },
      "type": "n8n-nodes-base.githubTrigger",
      "typeVersion": 1,
      "position": [
        -1616,
        -608
      ],
      "id": "f4c05b30-6699-4644-96ce-377bb72f1263",
      "name": "Github Trigger"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list",
          "cachedResultName": "gpt-4o-mini"
        },
        "options": {}
      },
      "id": "c5da4ba6-5e52-46be-9bb3-5bd0a84b3238",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -864,
        -432
      ],
      "typeVersion": 1.2
    },
    {
      "parameters": {
        "url": "=https://api.github.com/repos/{{$json.body.sender.login}}/{{$json.body.repository.name}}/pulls/{{$json.body.number}}/files",
        "options": {}
      },
      "id": "12b682e4-652e-4841-ac39-d2e751b23ca7",
      "name": "Get file's Diffs from PR",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1280,
        -640
      ],
      "typeVersion": 4.2
    },
    {
      "parameters": {
        "jsCode": "const files = $input.all().map(item => item.json);\n\nlet diffs = '';\n\nfor (const file of files) {\n  diffs += `### Fichier : ${file.filename}\\n\\n`;\n\n  if (file.patch) {\n    \n    const safePatch = file.patch.replace(/```/g, \"''\");\n\n    diffs += \"```diff\\n\";\n    diffs += safePatch;\n    diffs += \"\\n```\\n\";\n  } else {\n    diffs += \"_Pas de patch disponible (probablement fichier binaire)._\";\n  }\n\n  diffs += \"\\n---\\n\\n\";\n}\n\nconst userMessage = `\nYou are a senior developer. \nPlease review the following code changes in these files :\n\n${diffs}\n\n---\n\nYour mission:\n\n- Review the proposed code changes file by file and by significant modification.\n\n- Generate inline comments on the relevant lines of code.\n\n- Ignore files without patches.\n\n- Do not repeat the code snippet or the filename.\n\n- Write the comments directly, without introducing the context.\n`;\n\nreturn [\n  {\n    json: {\n      user_message: userMessage.trim()\n    }\n  }\n];"
      },
      "id": "ecbfb077-6baf-4985-8c70-4fbfce4c7818",
      "name": "Create target Prompt from PR Diffs",
      "type": "n8n-nodes-base.code",
      "position": [
        -1056,
        -640
      ],
      "typeVersion": 2
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "resource": "review",
        "owner": {
          "__rl": true,
          "value": "HemaKumar0077",
          "mode": "list",
          "cachedResultName": "HemaKumar0077",
          "cachedResultUrl": "https://github.com/HemaKumar0077"
        },
        "repository": {
          "__rl": true,
          "value": "ID-Card_Generator",
          "mode": "list",
          "cachedResultName": "ID-Card_Generator",
          "cachedResultUrl": "https://github.com/HemaKumar0077/ID-Card_Generator"
        },
        "pullRequestNumber": "={{ $('Github Trigger').first().json.body.number}}",
        "event": "comment",
        "body": "={{ $json.output }}",
        "additionalFields": {}
      },
      "id": "6c8266ee-3462-4e3e-8ed4-d3843b1d8bfa",
      "name": "GitHub Robot",
      "type": "n8n-nodes-base.github",
      "position": [
        -464,
        -640
      ],
      "typeVersion": 1.1
    },
    {
      "parameters": {
        "content": "**1-The GitHub Trigger** node initiates the workflow whenever a pull request event occurs on a specified repository. It enables real-time automation based on GitHub activity.\n"
      },
      "id": "eddffca3-c389-4c06-b264-ad295af8d0dc",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1648,
        -832
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "content": "**2-Get PR Diffs**\nThe HTTP Request node fetches the list of changed files and their diffs from the pull request that triggered the workflow. It uses the GitHub REST API to retrieve this data dynamically based on the trigger payload.\n\nhttps://api.github.com/repos/{{$json.body.sender.login}}/{{$json.body.repository.name}}/pulls/{{$json.body.number}}/files",
        "height": 220,
        "width": 340,
        "color": 3
      },
      "id": "7ff04ca0-10fa-493b-a0f3-bffd0538d5fc",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1440,
        -464
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "content": "**3-Create Prompt from diffs**\nThis Code node runs a JavaScript snippet to:\n-Parse file diffs from the previous HTTP Request node\n-Format each diff with its file name\n-Build a structured natural language prompt for the AI agent\n\nThe final output is a clear, contextual instruction like:\n*\"You are a senior iOS developer. Please review the following code changes in these files...\"*\n",
        "height": 240,
        "width": 360,
        "color": 2
      },
      "id": "4b1f62c9-d501-47cc-9ebd-3c42dbebaf47",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1184,
        -912
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "content": "**Github Comment Poster**\nPosts the AI-generated review as a comment on the pull request using GitHub API.",
        "color": 5
      },
      "id": "9c9f14a7-2971-4c14-820f-ed2b622dad18",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -560,
        -832
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.user_message }}",
        "options": {}
      },
      "id": "044304ac-10aa-4a58-8355-1ff388ed8652",
      "name": "Code Review Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -832,
        -640
      ],
      "typeVersion": 1.9
    },
    {
      "parameters": {
        "content": "**PR Labeler (optional)**\nAutomatically adds a label like *ReviewedByAI* to the pull request once the AI comment is posted.",
        "height": 120,
        "color": 7
      },
      "id": "0629550f-09c4-49c4-94cb-97f4d3dfce1d",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -304,
        -784
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "content": "**Google Sheet Best Practices**\nEnables the AI agent to reference to your team coding guidelines stored in a Google Sheet for more accurate and opinionated reviews.\nYou can replace Google Sheets with any other database or tool.",
        "width": 260,
        "color": 6
      },
      "id": "bf6ea06f-b58e-459c-a19d-7061ac129dec",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -576,
        -448
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "operation": "edit",
        "owner": {
          "__rl": true,
          "value": "HemaKumar0077",
          "mode": "list",
          "cachedResultName": "HemaKumar0077",
          "cachedResultUrl": "https://github.com/HemaKumar0077"
        },
        "repository": {
          "__rl": true,
          "value": "ID-Card_Generator",
          "mode": "list",
          "cachedResultName": "ID-Card_Generator",
          "cachedResultUrl": "https://github.com/HemaKumar0077/ID-Card_Generator"
        },
        "issueNumber": "={{ $('Github Trigger').first().json.body.number }}",
        "editFields": {
          "labels": [
            {
              "label": "ReviewedByAI"
            }
          ]
        }
      },
      "id": "1e21cffe-3163-4a54-90be-8ac98e78e71c",
      "name": "Add Label to PR",
      "type": "n8n-nodes-base.github",
      "position": [
        -240,
        -640
      ],
      "typeVersion": 1
    }
  ],
  "connections": {
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Code Review Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Get file's Diffs from PR": {
      "main": [
        [
          {
            "node": "Create target Prompt from PR Diffs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create target Prompt from PR Diffs": {
      "main": [
        [
          {
            "node": "Code Review Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GitHub Robot": {
      "main": [
        [
          {
            "node": "Add Label to PR",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code Review Agent": {
      "main": [
        [
          {
            "node": "GitHub Robot",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Github Trigger": {
      "main": [
        [
          {
            "node": "Get file's Diffs from PR",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "tags": []
}