{
  "name": "DocuWriter.ai Generation Created Automation",
  "nodes": [
    {
      "parameters": {
        "event": "generation.created",
        "filterByGenerationType": true,
        "generationTypes": [
          "Documentation",
          "Tests"
        ]
      },
      "id": "webhook-trigger",
      "name": "Generation Created",
      "type": "n8n-nodes-docuwriter-ai.docuWriterTrigger",
      "typeVersion": 1,
      "position": [
        240,
        300
      ],
      "credentials": {
        "docuWriterApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$json.data.generation_type}}",
              "operation": "equal",
              "value2": "Documentation"
            }
          ]
        }
      },
      "id": "check-is-documentation",
      "name": "Is Documentation?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        460,
        300
      ]
    },
    {
      "parameters": {
        "resource": "generations",
        "operation": "get",
        "generationId": "={{$node['Generation Created'].json['data']['id']}}"
      },
      "id": "fetch-generation-details",
      "name": "Fetch Generation Details",
      "type": "n8n-nodes-docuwriter-ai.docuWriter",
      "typeVersion": 1,
      "position": [
        680,
        200
      ],
      "credentials": {
        "docuWriterApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "authentication": "serviceAccount",
        "resource": "document",
        "operation": "create",
        "folderId": "YOUR_GOOGLE_DRIVE_FOLDER_ID",
        "name": "Documentation - {{$node['Generation Created'].json['data']['filename']}}",
        "options": {
          "bodyContentType": "text/html"
        },
        "bodyData": "<h1>{{$node['Generation Created'].json['data']['filename']}}</h1>\n\n<p><strong>Generated by:</strong> {{$node['Generation Created'].json['data']['generated_by_user']}}</p>\n<p><strong>Created:</strong> {{$node['Generation Created'].json['data']['created_at']}}</p>\n\n<div>{{$node['Fetch Generation Details'].json['data']['generated']}}</div>"
      },
      "id": "save-to-google-docs",
      "name": "Save to Google Docs",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        900,
        200
      ]
    },
    {
      "parameters": {
        "resource": "codeTests",
        "operation": "generate",
        "sourceCode": "={{$node['Generation Created'].json['data']['source']}}",
        "filename": "={{$node['Generation Created'].json['data']['filename']}}",
        "testFramework": "auto-detect"
      },
      "id": "generate-tests",
      "name": "Generate Tests",
      "type": "n8n-nodes-docuwriter-ai.docuWriter",
      "typeVersion": 1,
      "position": [
        680,
        400
      ],
      "credentials": {
        "docuWriterApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "resource": "file",
        "operation": "create",
        "owner": "YOUR_GITHUB_USERNAME",
        "repository": "YOUR_GITHUB_REPOSITORY",
        "filePath": "tests/{{$node['Generation Created'].json['data']['filename']}}.test.js",
        "fileContent": "={{$node['Generate Tests'].json['data']['tests']}}",
        "commitMessage": "Add automated tests for {{$node['Generation Created'].json['data']['filename']}}"
      },
      "id": "commit-tests-to-github",
      "name": "Commit Tests to GitHub",
      "type": "n8n-nodes-base.github",
      "typeVersion": 1,
      "position": [
        900,
        400
      ]
    },
    {
      "parameters": {
        "channel": "#dev-team",
        "text": "\ud83d\udcc4 New documentation generated!",
        "attachments": [
          {
            "color": "good",
            "title": "{{$node['Generation Created'].json['data']['filename']}}",
            "text": "Documentation has been automatically generated and saved to Google Drive.",
            "fields": [
              {
                "title": "File",
                "value": "{{$node['Generation Created'].json['data']['filename']}}",
                "short": true
              },
              {
                "title": "Type",
                "value": "{{$node['Generation Created'].json['data']['generation_type']}}",
                "short": true
              },
              {
                "title": "Generated by",
                "value": "{{$node['Generation Created'].json['data']['generated_by_user']}}",
                "short": true
              },
              {
                "title": "Created",
                "value": "{{$node['Generation Created'].json['data']['created_at']}}",
                "short": true
              }
            ],
            "actions": [
              {
                "type": "button",
                "text": "View in Drive",
                "url": "{{$node['Save to Google Docs'].json['webViewLink']}}"
              }
            ]
          }
        ]
      },
      "id": "notify-team-slack",
      "name": "Notify Team (Slack)",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 1,
      "position": [
        1120,
        200
      ]
    },
    {
      "parameters": {
        "channel": "#dev-team",
        "text": "\ud83e\uddea Tests generated and committed!",
        "attachments": [
          {
            "color": "warning",
            "title": "{{$node['Generation Created'].json['data']['filename']}} Tests",
            "text": "Test cases have been automatically generated and committed to the repository.",
            "fields": [
              {
                "title": "File",
                "value": "{{$node['Generation Created'].json['data']['filename']}}",
                "short": true
              },
              {
                "title": "Repository",
                "value": "YOUR_GITHUB_REPOSITORY",
                "short": true
              }
            ]
          }
        ]
      },
      "id": "notify-tests-slack",
      "name": "Notify Tests (Slack)",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 1,
      "position": [
        1120,
        400
      ]
    }
  ],
  "connections": {
    "Generation Created": {
      "main": [
        [
          {
            "node": "Is Documentation?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Documentation?": {
      "main": [
        [
          {
            "node": "Fetch Generation Details",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Generate Tests",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Generation Details": {
      "main": [
        [
          {
            "node": "Save to Google Docs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save to Google Docs": {
      "main": [
        [
          {
            "node": "Notify Team (Slack)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Tests": {
      "main": [
        [
          {
            "node": "Commit Tests to GitHub",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Commit Tests to GitHub": {
      "main": [
        [
          {
            "node": "Notify Tests (Slack)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": {},
  "tags": [
    {
      "id": "docuwriter",
      "name": "DocuWriter.ai"
    },
    {
      "id": "webhook",
      "name": "Webhook"
    },
    {
      "id": "automation",
      "name": "Automation"
    }
  ],
  "meta": {
    "templateCredsSetupCompleted": false
  }
}