{
  "name": "TestNeo \u2014 Record release outcome (Template 3)",
  "nodes": [
    {
      "id": "m3",
      "name": "When clicking Test workflow",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        200
      ],
      "parameters": {}
    },
    {
      "id": "c3",
      "name": "Edit Config",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        260,
        200
      ],
      "parameters": {
        "mode": "manual",
        "duplicateItem": false,
        "assignments": {
          "assignments": [
            {
              "id": "c1",
              "name": "baseUrl",
              "value": "={{ $env.TESTNEO_BASE_URL || 'https://app.testneo.ai' }}",
              "type": "string"
            },
            {
              "id": "c2",
              "name": "apiKey",
              "value": "={{ $env.TESTNEO_API_KEY || '' }}",
              "type": "string"
            },
            {
              "id": "c3",
              "name": "projectId",
              "value": "={{ Number($env.TESTNEO_PROJECT_ID || $json.project_id || 0) }}",
              "type": "number"
            },
            {
              "id": "c4",
              "name": "outcomeId",
              "value": "={{ $json.outcome_id || $env.OUTCOME_ID || '' }}",
              "type": "string"
            },
            {
              "id": "c5",
              "name": "bundleId",
              "value": "={{ $json.bundle_id || '' }}",
              "type": "string"
            },
            {
              "id": "c6",
              "name": "markDeployed",
              "value": "={{ Boolean($json.mark_deployed) }}",
              "type": "boolean"
            },
            {
              "id": "c7",
              "name": "rollback",
              "value": "={{ Boolean($json.rollback) }}",
              "type": "boolean"
            },
            {
              "id": "c8",
              "name": "incident7d",
              "value": "={{ Boolean($json.incident_within_7d) }}",
              "type": "boolean"
            },
            {
              "id": "c9",
              "name": "incident30d",
              "value": "={{ Boolean($json.incident_within_30d) }}",
              "type": "boolean"
            },
            {
              "id": "c10",
              "name": "hotfixPrCount",
              "value": "={{ Number($json.hotfix_pr_count || 0) }}",
              "type": "number"
            },
            {
              "id": "c11",
              "name": "outcomeNotes",
              "value": "={{ $json.outcome_notes || 'Recorded via n8n Template 3' }}",
              "type": "string"
            },
            {
              "id": "c12",
              "name": "releaseName",
              "value": "={{ $json.release_name || '' }}",
              "type": "string"
            },
            {
              "id": "c13",
              "name": "confidenceAtShip",
              "value": "={{ Number($json.confidence_at_ship || 0) }}",
              "type": "number"
            },
            {
              "id": "c14",
              "name": "gateStatusAtShip",
              "value": "={{ $json.gate_status_at_ship || 'manual' }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "if_mark",
      "name": "Mark deployed first?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        520,
        200
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose"
          },
          "conditions": [
            {
              "id": "x1",
              "leftValue": "={{ $json.markDeployed === true && !!$json.bundleId }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      }
    },
    {
      "id": "http_mark",
      "name": "POST Mark deployed",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        780,
        40
      ],
      "parameters": {
        "method": "POST",
        "url": "={{ ($('Edit Config').item.json.baseUrl || '').replace(/\\/$/, '') }}/api/web/v1/release-readiness/outcome",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('Edit Config').item.json.apiKey }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ project_id: $('Edit Config').item.json.projectId, bundle_id: $('Edit Config').item.json.bundleId, release_name: $('Edit Config').item.json.releaseName || undefined, confidence_at_ship: $('Edit Config').item.json.confidenceAtShip || undefined, gate_status_at_ship: $('Edit Config').item.json.gateStatusAtShip }) }}",
        "options": {
          "timeout": 60000
        }
      }
    },
    {
      "id": "http_list",
      "name": "GET outcomes",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        780,
        280
      ],
      "parameters": {
        "method": "GET",
        "url": "={{ ($('Edit Config').item.json.baseUrl || '').replace(/\\/$/, '') }}/api/web/v1/release-readiness/outcomes?project_id={{ $('Edit Config').item.json.projectId }}&limit=30",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('Edit Config').item.json.apiKey }}"
            },
            {
              "name": "Accept",
              "value": "application/json"
            }
          ]
        },
        "options": {
          "timeout": 60000
        }
      }
    },
    {
      "id": "resolve",
      "name": "Resolve outcome_id",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1040,
        200
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const cfg = $('Edit Config').first().json;\nlet outcomeId = cfg.outcomeId;\nconst payload = items[0].json;\nif (!outcomeId && payload.outcome && payload.outcome.id) {\n  outcomeId = payload.outcome.id;\n}\nif (!outcomeId && Array.isArray(payload.outcomes)) {\n  const pending = payload.outcomes.find(o => o.outcome_pending);\n  const first = payload.outcomes[0];\n  outcomeId = (pending || first || {}).id;\n}\nif (!outcomeId) {\n  throw new Error('No outcome_id. Set OUTCOME_ID, pass outcome_id, or mark_deployed+bundle_id first.');\n}\nreturn [{\n  json: {\n    ...cfg,\n    outcomeId: String(outcomeId),\n  }\n}];\n"
      }
    },
    {
      "id": "http_patch",
      "name": "PATCH Record outcome",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1300,
        200
      ],
      "parameters": {
        "method": "PATCH",
        "url": "={{ ($json.baseUrl || '').replace(/\\/$/, '') }}/api/web/v1/release-readiness/outcome/{{ $json.outcomeId }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $json.apiKey }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ rollback: $json.rollback, incident_within_7d: $json.incident7d, incident_within_30d: $json.incident30d, hotfix_pr_count: $json.hotfixPrCount, outcome_notes: $json.outcomeNotes }) }}",
        "options": {
          "timeout": 60000
        }
      }
    },
    {
      "id": "out3",
      "name": "Result",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1560,
        200
      ],
      "parameters": {
        "mode": "manual",
        "assignments": {
          "assignments": [
            {
              "id": "o1",
              "name": "ok",
              "value": true,
              "type": "boolean"
            },
            {
              "id": "o2",
              "name": "outcome",
              "value": "={{ $json.outcome || $json }}",
              "type": "object"
            }
          ]
        },
        "options": {}
      }
    }
  ],
  "connections": {
    "When clicking Test workflow": {
      "main": [
        [
          {
            "node": "Edit Config",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Config": {
      "main": [
        [
          {
            "node": "Mark deployed first?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mark deployed first?": {
      "main": [
        [
          {
            "node": "POST Mark deployed",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "GET outcomes",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "POST Mark deployed": {
      "main": [
        [
          {
            "node": "Resolve outcome_id",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GET outcomes": {
      "main": [
        [
          {
            "node": "Resolve outcome_id",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Resolve outcome_id": {
      "main": [
        [
          {
            "node": "PATCH Record outcome",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "PATCH Record outcome": {
      "main": [
        [
          {
            "node": "Result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "1",
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": [
    {
      "name": "testneo"
    },
    {
      "name": "ai-agent-verification"
    }
  ],
  "pinData": {}
}
