This repository contains an n8n workflow that generates executable unit tests for repository source files using an LLM.
- Automatically generate production-ready unit tests for source files in a GitHub repository.
- Provide a repeatable workflow that can run in bulk (batch) or per-file (individual).
All of these live in the Configuration node in the workflow (node name: Configuration). The node sets initial variables used across the flow.
-
owner(string)- Description: GitHub repository owner/org (e.g.,
wizeline). - Where used: GitHub API requests to form repository URLs and fetch content.
- Default in example:
wizeline.
- Description: GitHub repository owner/org (e.g.,
-
repo(string)- Description: Repository name (e.g.,
BytescribeTeam). - Where used: GitHub API requests to fetch tree and file contents.
- Default in example:
BytescribeTeam.
- Description: Repository name (e.g.,
-
branch(string)- Description: Source branch to read files from (e.g.,
main). - Where used: API calls to read repository tree and file content.
- Default in example:
main.
- Description: Source branch to read files from (e.g.,
-
processingMode(string) —batchorindividual- Description: Choose processing mode.
batch: groups multiple files into a single prompt (fewer AI calls, larger prompts).individual: sends each file in its own prompt (more AI calls, more precise results per file).
- Where used:
Route by Processing Modenode to pick the route. - Default in example:
batch.
- Description: Choose processing mode.
-
batchSize(number)- Description: Number of files included in each batch when
processingModeisbatch. - Where used:
Create Batchesnode slicessourceFilesinto groups ofbatchSize. - Effect: Controls prompt size and number of AI calls.
- Example default in example:
5. - Recommendation: 5–10 as a safe starting point (depends on token limits and file sizes).
- Description: Number of files included in each batch when
-
fetchFileContent(boolean)- Description: When
truethe workflow will fetch raw file content from GitHub (used for detailed generation or individual mode). - Where used:
Fetch File ContentandPrepare Individual Filenodes. - Default in example:
true.
- Description: When
-
maxFilesToProcess(number)- Description: Maximum number of matching source files the workflow will process overall.
- Where used:
Process File Structurenode uses.slice(0, maxFilesToProcess)when building thesourceFileslist. - Effect: Caps work done (useful for large repos and cost control).
- Example default in example:
10.
-
testBranch(string)- Description: Branch name where auto-generated tests will be committed (e.g.,
auto-generated-tests). - Where used: Branch creation and commit nodes (
Prepare Branch Creation Data,Create Test Branch, commit HTTP request). - Default in example:
auto-generated-tests.
- Description: Branch name where auto-generated tests will be committed (e.g.,
Key nodes (by name) and roles:
-
Process File Structure(code node)- Reads the repository tree response and builds
sourceFileslist (appliesmaxFilesToProcess).
- Reads the repository tree response and builds
-
Create Batches(code node)- Uses
batchSizeto slicesourceFilesinto batches (each batch becomes one prompt to the AI in batch mode).
- Uses
-
Prepare Batch Prompt(set node)- Builds the text prompt for a batch including a list of files.
-
AI - Batch Analysis/AI - Individual File Analysis(language model nodes)- Send prompts and receive AI outputs.
-
Format Final Output(code node)- Parses AI responses, aggregates test file metadata and contents, and returns a consolidated JSON structure.
-
Export to JSON File(convertToFile node)- Writes the resulting JSON of generated tests to disk.
-
Prepare Git Commit/Create/Update File on GitHub(code + httpRequest nodes)- Create/commit test files to the
testBranchbranch.
- Create/commit test files to the
This webhook will listen for events from GitHub Actions. When the test results artifact is uploaded successfully, the webhook will be triggered to download the file and send "sample" files to a specific email address.
To set up the connection, you will configure your GitHub repository to use the n8n production webhook URL.
- In your n8n workflow's Webhook node, copy the Production URL (or Test URL, depending on your environment).
- Open the GitHub repository where you want to register these webhook events.
- Click on the "Settings" tab of the repository.
- In the Repo Settings sidebar, click on "Webhooks".
- Click the "Add webhook" button.
- In the "Payload URL" field, paste the link copied in Step 1.
- In the "Which events would you like to trigger this webhook?" section, tick the checkboxes for the following events:
- "Check runs"
- "Pull requests"
- Finally, ensure the "Active" box is ticked (it should be by default) and click "Add webhook" (or "Update webhook" if you are editing).
- Trigger:
When clicking 'Test workflow'— start the flow. Configurationsets runtime variables (owner, repo, branch, processingMode, batchSize, fetchFileContent, maxFilesToProcess, testBranch).Get Branch InfoandGet Repository Treefetch repository metadata and full file tree.Process File Structurefilters potential source files (by extension and excluded folders), setssourceFilesandsourceFilesCount, and appliesmaxFilesToProcess.Route by Processing Mode:- If
individual: split into single-file items and analyze each file separately (Fetch File Content->Prepare Individual File Prompt->AI - Individual File Analysis). - If
batch:Create Batchesgroups files into batches ofbatchSizeand runsAI - Batch Analysis.
- If
Merge All Resultscollects AI outputs (from individual or batch paths).Format Final Outputparses and normalizes AI responses into a well-structured JSON with fields such asrepository,processingMode,summary, andtestFiles(each file includestestFileContent,testFile,runCommand, etc.).- If parsing issues are encountered,
errorsare returned in the summary (the workflow includes robust parsing code to handle template literals and common malformed responses).
- If parsing issues are encountered,
Export to JSON Filewrites consolidated results locally.- (Optional) The flow then enriches each
testFilewith repo context, creates test files locally, and pushes them to the configuredtestBranchon GitHub. - When the workflow complete, the webhook of n8n will be called and send some "sample" files into a predefined email.
- The user can received email should be configurable.
- Send the valuable information of the test result artifact, because currently the attached file in email does not give enough insigt for user.