mvp-factory-openhands/MANUAL_N8N_FIX.md

157 lines
4.3 KiB
Markdown

# 🔧 MANUAL FIX - Follow These EXACT Steps
## The Problem:
`Cannot set properties of undefined (setting 'repo_info')`
**Root Cause:** `$workflow.staticData` doesn't work in n8n code nodes the way we're using it.
---
## SOLUTION: Remove staticData Completely
### Step 1: Open n8n Workflow
1. Go to: https://n8n.oky.sh
2. Open: **"Gitea → OpenHands Enhanced CI/CD"** workflow
3. You should see all the nodes in a flow
### Step 2: Fix Node 2 - "Extract Repo Info"
1. **Click on Node 2** (the blue code node)
2. **Find the JavaScript code** (should be in a text area)
3. **REPLACE THE ENTIRE CODE** with this:
```javascript
// Extract repository and commit information from Gitea webhook
const payload = $input.item.json;
// Extract key information
const repoName = payload.repository?.name || 'unknown';
const repoFullName = payload.repository?.full_name || 'unknown';
const repoCloneUrl = payload.repository?.clone_url || '';
const branch = payload.ref?.replace('refs/heads/', '') || 'main';
const commitSha = payload.after || '';
const commitMessage = payload.commits?.[0]?.message || 'No message';
const pusher = payload.pusher?.username || 'unknown';
// Create task message for OpenHands SDK
const task = 'Build and test project ' + repoFullName + ' on branch ' + branch + '. ' +
'Latest commit: "' + commitMessage + '". ' +
'Clone the repository from ' + repoCloneUrl + ' and run: npm install && npm test && npm build. ' +
'Report any errors found.';
// IMPORTANT: Just return the data - it will flow to the next node
return {
repo_name: repoName,
repo_full_name: repoFullName,
repo_clone_url: repoCloneUrl,
branch: branch,
commit_sha: commitSha,
commit_message: commitMessage,
pusher: pusher,
task: task,
timestamp: new Date().toISOString(),
status: 'PENDING',
retry_count: 0
};
```
4. **Click "Update"** or **Save**
### Step 3: Fix Node 7 - "Format Build Response"
1. **Click on Node 7** (later in the flow)
2. **Find the JavaScript code**
3. **REPLACE THE ENTIRE CODE** with this:
```javascript
// Use the data from $json (which has everything from previous nodes)
const item = $json;
const result = {
status: item.status || 'SUCCESS',
repo: item.repo_full_name || 'unknown',
branch: item.branch || 'main',
commit: item.commit_sha ? item.commit_sha.substring(0, 8) : 'N/A',
message: item.message || 'Build completed',
timestamp: new Date().toISOString(),
retry_count: 0
};
// Add emoji based on status
if (result.status === 'SUCCESS') {
result.emoji = '✅';
} else if (result.status === 'FAILED') {
result.emoji = '❌';
} else {
result.emoji = '⚠️';
}
return result;
```
4. **Click "Update"** or **Save**
### Step 4: Save the Entire Workflow
1. Click **"Save"** (top-right of the workflow editor)
2. Make sure the workflow is **ACTIVE** (toggle switch should be green/blue)
### Step 5: Test It
1. Click **"Execute Workflow"** button (top-right)
2. Use this test data:
```json
{
"repository": {
"name": "test-repo",
"full_name": "gitadmin/test-repo",
"clone_url": "https://git.oky.sh/gitadmin/test-repo.git"
},
"ref": "refs/heads/main",
"after": "abc123def456",
"commits": [{"message": "Test webhook with real data"}],
"pusher": {"username": "gitadmin"}
}
```
3. **Click "Execute Workflow"**
### Step 6: Check the Result
Look at **Node 7 "Format Build Response"** output. You should see:
```json
{
"status": "SUCCESS",
"repo": "gitadmin/test-repo", REAL REPO NAME!
"branch": "main",
"commit": "abc12345", REAL COMMIT!
"message": "Build completed successfully",
"timestamp": "2025-12-01T19:xx:xx.xxxZ",
"retry_count": 0,
"emoji": "✅"
}
```
### Step 7: Export the Working Workflow
1. In n8n, go to the workflow editor
2. Click **"..." menu** (three dots, top-right)
3. Select **"Export"**
4. Download the JSON file
5. **Upload it to the repository** as `openhands-enhanced-WORKING.json`
---
## What Changed:
**BEFORE (Broken):**
- Node 2: Tried to use `$workflow.staticData.repo_info = {...}`
- Node 7: Tried to read `$workflow.staticData.repo_info`
**AFTER (Working):**
- Node 2: Just returns data (flows to next node) ✅
- Node 7: Reads data from `$json`
**The Fix:** Data flows through nodes normally using `$json`, no staticData needed!
---
## Need Help?
After testing, export the working workflow and I'll add it to the repository for you!