{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "a32a3286-f834-4158-b51f-517d302594b9",
      "name": "Github Trigger",
      "type": "n8n-nodes-base.githubTrigger",
      "position": [
        7808,
        5248
      ],
      "parameters": {
        "owner": {
          "__rl": true,
          "mode": "name",
          "value": ""
        },
        "events": [
          "issues",
          "issue_comment"
        ],
        "options": {},
        "repository": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultUrl": "",
          "cachedResultName": ""
        }
      },
      "typeVersion": 1
    },
    {
      "id": "55bedc64-a3d8-44f7-9248-7d6ca8e22eeb",
      "name": "Edit Fields",
      "type": "n8n-nodes-base.set",
      "position": [
        8256,
        5232
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "0bf058ac-52d0-4271-8c38-3dc1a91974f1",
              "name": "title",
              "type": "string",
              "value": "={{ $json.body.issue.title }}"
            },
            {
              "id": "1a929ff0-0ace-405c-9e4a-0550826dc6aa",
              "name": "description",
              "type": "string",
              "value": "={{ $json.body.issue.body }}"
            },
            {
              "id": "cd33e0db-12ac-48cc-bc2c-01cd96d76fe4",
              "name": "issue_url",
              "type": "string",
              "value": "={{ $json.body.issue.url }}"
            },
            {
              "id": "04f112a1-a29b-4560-9347-6473a15e85b6",
              "name": "author",
              "type": "string",
              "value": "={{ $json.body.issue.user.login }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "87bb4b94-daf3-49fe-b9f2-06023477e942",
      "name": "Information Extractor",
      "type": "@n8n/n8n-nodes-langchain.informationExtractor",
      "position": [
        8496,
        4960
      ],
      "parameters": {
        "text": "=You are an AI issue triage assistant.\n\nSTRICT RULES:\n- Output ONLY valid JSON\n- No explanation\n- No markdown\n- No extra text\n\nClassify the issue:\n\ntype must be one of:\nBug | Feature | Question\n\npriority must be a NUMBER:\n1 = Urgent\n2 = High\n3 = Medium\n4 = Low\n\nAlso generate 2\u20134 short labels.\n\nReturn format:\n\n{\n  \"type\": \"Bug\",\n  \"priority\": 1,\n  \"labels\": [\"crash\", \"login\"]\n}\n\nIssue Title:\n{{ $json.title }}\n\nIssue Description:\n{{ $json.description }}",
        "options": {},
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"type\": {\n      \"type\": \"string\"\n    },\n    \"priority\": {\n      \"type\": \"number\"\n    },\n    \"labels\": {\n      \"type\": \"array\",\n      \"items\": {\n        \"type\": \"string\"\n      }\n    }\n  }\n}"
      },
      "typeVersion": 1.2
    },
    {
      "id": "0b4fd525-0fea-4204-bd81-3ad1f041d70f",
      "name": "Create an issue",
      "type": "n8n-nodes-base.linear",
      "position": [
        9296,
        5216
      ],
      "parameters": {
        "title": "={{$json.title}}",
        "teamId": "YOUR_LINEAR_TEAM_ID",
        "additionalFields": {
          "priorityId": "={{$json.priority}}",
          "description": "={{ $('Merge').item.json.description }}"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "fe7b2e45-9308-48f8-9233-812dc92e5381",
      "name": "Create a comment on an issue",
      "type": "n8n-nodes-base.github",
      "position": [
        9536,
        5216
      ],
      "parameters": {
        "body": "=Thanks for opening this issue!\n\nOur AI triage system classified this as:\n\nType: {{ $('Code in JavaScript').item.json.typeLabel }}\nPriority: {{ $('Code in JavaScript').item.json.priorityLabel }}\n\nA Linear task has been created for the team.",
        "owner": {
          "__rl": true,
          "mode": "name",
          "value": ""
        },
        "operation": "createComment",
        "repository": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultUrl": "",
          "cachedResultName": ""
        },
        "issueNumber": "={{ $('Github Trigger').item.json.body.issue.number }}"
      },
      "typeVersion": 1.1
    },
    {
      "id": "afd1dd04-0226-4d97-9145-6c053ff321a7",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        9056,
        5216
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "combineBy": "combineByPosition"
      },
      "typeVersion": 3.2
    },
    {
      "id": "59743ca0-0d44-4bd1-893c-be0acdce9a9a",
      "name": "Code in JavaScript",
      "type": "n8n-nodes-base.code",
      "position": [
        8832,
        4960
      ],
      "parameters": {
        "jsCode": "let output = $json.output;\n\n// 1. Parse if AI returned string\nif (typeof output === \"string\") {\n  try {\n    output = JSON.parse(output);\n  } catch (e) {\n    throw new Error(\"Invalid JSON from AI\");\n  }\n}\n\n// 2. Normalize values\nconst priorityNum = Number(output.priority);\n\n// 3. Fallback safety\nconst safePriority = [1,2,3,4].includes(priorityNum) ? priorityNum : 3;\n\n// 4. Priority label mapping\nconst priorityMap = {\n  1: \"Urgent\",\n  2: \"High\",\n  3: \"Medium\",\n  4: \"Low\"\n};\n\n\nreturn [{\n  ...$json,\n\n  // Clean structured output\n  output,\n\n  // For Linear (number)\n  priority: safePriority,\n\n  // For UI / GitHub\n  priorityLabel: priorityMap[safePriority],\n  type: output.type,\n  typeLabel: output.type,\n\n  // Labels safe fallback\n  labels: Array.isArray(output.labels) ? output.labels : []\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "dd834e8a-b513-4f54-87ad-1241937c44c1",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        8016,
        5248
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "f2c39860-14f6-4f51-935b-5a2fe295b5ee",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.body.action }}",
              "rightValue": "opened"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "ad461b28-7b67-4052-83d1-3e0b45fb458c",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        8576,
        5152
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "typeVersion": 1.3
    },
    {
      "id": "136dc3dd-569d-43b6-be01-b8683633ce74",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        7040,
        4816
      ],
      "parameters": {
        "width": 656,
        "height": 720,
        "content": "# GitHub Issue \u2192 AI Triage & Task Creation\n\nThis workflow automates the process of analyzing and organizing new GitHub issues using AI. Whenever a new issue is created, the workflow evaluates its content, classifies it (e.g., Bug, Feature, or Question), and prepares structured data such as priority and labels. Based on this analysis, a task is automatically created, helping teams streamline issue management and reduce manual triage effort.\n\nBy leveraging AI, teams can ensure consistent classification, faster response times, and better organization of incoming issues. This is especially useful for growing projects where managing issues manually becomes time-consuming and error-prone.\n\n### How it works\n- Trigger fires when a new GitHub issue is created  \n- Basic filtering ensures only relevant issues are processed  \n- Issue content is cleaned and structured  \n- AI analyzes and classifies the issue type  \n- Code node formats the AI output  \n- Data is merged and used to create a task  \n- A comment is added back to the issue for traceability  \n\n### Setup\n- Connect GitHub credentials  \n- Add AI model credentials (Groq/OpenAI)  \n- Configure classification prompt inside AI node  \n- Map fields for issue title, description, and labels  \n- Set up Linear/GitHub task creation fields properly  "
      },
      "typeVersion": 1
    },
    {
      "id": "bd6928ef-51e7-4231-a18c-738f5e3a8a97",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        7728,
        4816
      ],
      "parameters": {
        "color": 7,
        "width": 672,
        "height": 720,
        "content": "## Step 1 : Capture & Filter Issues\n\nTriggers on new GitHub issues, filters it, and prepares structured data (title, description) for AI processing."
      },
      "typeVersion": 1
    },
    {
      "id": "92aefaef-2876-4b8a-9a45-41cf43518c65",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        8432,
        4816
      ],
      "parameters": {
        "color": 7,
        "width": 752,
        "height": 720,
        "content": "## Step 2 : AI Classification & Formatting\n\nAI classifies the issue (Bug, Feature, Question) and assigns priority. Code node formats this output for downstream task creation."
      },
      "typeVersion": 1
    },
    {
      "id": "689974fc-7543-432d-b00f-2d41e1a10456",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        9216,
        4816
      ],
      "parameters": {
        "color": 7,
        "width": 576,
        "height": 720,
        "content": "## Step 3 : Task Creation & Feedback\n\nProcessed data is merged and used to create a task. A comment is added to the GitHub issue for visibility and tracking."
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Create an issue",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "Information Extractor",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Github Trigger": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create an issue": {
      "main": [
        [
          {
            "node": "Create a comment on an issue",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Information Extractor",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Information Extractor": {
      "main": [
        [
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}