Quick Overview
This workflow takes a published workflow from a staging n8n instance, cleans noisy metadata, commits the JSON to a GitHub repository on a new branch, and opens a pull request against a base branch so workflow changes can be promoted via a standard GitHub review and merge process.
How it works
- Triggers when the workflow is activated or updated in n8n, or when another workflow calls it with a
workflow_id input.
- Fetches the target workflow JSON from the staging n8n API using the provided workflow ID.
- Removes workflow metadata fields (such as IDs and timestamps) to keep Git diffs focused on real changes, then converts the cleaned JSON into a formatted file payload.
- Ensures the target GitHub repository exists, retrieves the base branch commit SHA, and creates a new branch named from the workflow name and version counter.
- Checks whether a JSON file for the workflow already exists in the repository and then creates or updates that file on the new branch by committing the base64-encoded JSON.
- Opens a GitHub pull request from the new branch into the configured base branch.
Setup
- Create a GitHub OAuth2 credential with access to the target repository (repo scope) and select it for the GitHub and GitHub API HTTP requests.
- Create an n8n API credential for your staging instance and set
stagingN8nBaseUrl to your staging n8n URL.
- Update the publish variables to your
repoOwner, repoName, baseBranch, and whether the repository should be private.
- Ensure this workflow receives the correct workflow ID (via the
workflow_id input when executed by another workflow, or by adjusting the trigger/input mapping to your publish event source).