Automated GitHub Pull Request Linting and Auto-Fixing with AI - n8n Workflow

Use this powerful n8n workflow to automatically lint, fix, and create new Pull Requests on GitHub using a Google Gemini AI Agent. Leverage n8n templates for streamlined DevOps automation.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Markdown-formatted:
DevOps Engineers looking to automate code quality checks.
Software development teams seeking to enforce coding standards automatically.
Users of n8n who want complex, multi-step AI agents for infrastructure tasks.
Anyone interested in using n8n templates for advanced GitHub integration.

Overview

Maintaining code quality across a large team can be challenging. This advanced n8n workflow solves this by providing a hands-free, automated linting bot. The system is designed to trigger automatically upon GitHub Pull Request activity. It uses an AI Agent powered by Google Gemini to analyze, interpret, and fix code based on defined standards. After fixing the code, the n8n workflow leverages a series of HTTP Request Tool nodes to perform sophisticated Git operations—creating blobs, trees, and commits—before ultimately opening a new pull request containing the linting fixes. This specific n8n workflow drastically reduces the time spent on manual code reviews and ensures immediate compliance with code standards, making it one of the most valuable n8n templates for modern software development practices.

How it Works

The automated process initiates with the Listen for Trigger from Github Workflow n8n trigger, an incoming webhook that captures PR details.


  1. Setup & Metadata: The workflow begins by executing a Code n8n node (Set Common Fields) to define necessary repository variables. It then retrieves core GitHub data, including the latest SHA and Tree Hash of the main branch, and the details of the triggered PR.

  2. File Extraction Loop: The n8n workflow fetches a list of changed files (Get PR Files). It then enters a loop: for each file, it fetches the Base64 content, decodes it into readable text (Convert Base64 to Text File and Extract from File), and structures it into a uniform object (Create Code/FilePath Object).

  3. Aggregation & AI Processing: All file objects are combined using the Collect All Files Changed n8n node. This aggregated data, containing the code needing review, is fed into the AI Agent n8n node, which utilizes the Google Gemini Chat Model.

  4. AI-Driven Git Operations: The AI Agent is equipped with specialized n8n node tools (httpRequestTool nodes) that allow it to perform actions based on its findings. It checks for a pre-existing linting fix branch (Get Branch), and if necessary, creates a new one (Create Branch). It then uses the fixes generated by the AI to create new GitHub blobs (Create GitHub Blob), construct a new commit tree (Create GitHub Tree), and finally, execute the commit (Create GitHub Commit).

  5. Final PR Creation: The last step involves using the Create Pull Request n8n node tool to open a new PR containing all the AI-applied fixes, before the n8n workflow concludes by acknowledging the initial webhook.

Installation Guide

Markdown-formatted:


  1. Import: Download the provided n8n workflow JSON and import it into your n8n instance.

  2. Credentials: You need to set up two main credentials:

GitHub API: Configure a GitHub credential with appropriate repository permissions (read/write access is required for creating branches and PRs). This is used by several HTTP Request n8n node tools.
Google Gemini (or PaLM) API: Configure the API key for the Google Gemini Chat Model n8n node.

  1. Code Node Configuration: Edit the Set Common Fields Code n8n node to correctly define your gitHubRepoName and gitHubOrgName.

  2. Webhook Setup: After activating the n8n workflow, note the URL provided by the Listen for Trigger from Github Workflow n8n trigger node. Configure your GitHub repository webhooks or GitHub Action to send PR events (e.g., pull_request types) to this specific URL path.

  3. Testing: Execute the n8n workflow manually or trigger a test PR on your GitHub repository to ensure the AI Agent and the n8n node sequence function correctly.

Node Details

Markdown-formatted:
Listen for Trigger from Github Workflow (Webhook n8n trigger):
Function: Serves as the starting n8n trigger for the entire automation, listening for incoming HTTP requests (specifically GitHub webhook events related to PRs).
Key Configuration: Configured with a unique webhook path to receive the GitHub payload.
Set Common Fields (Code n8n node):
Function: Centralized configuration point to define repository name, organization, and calculate the GitHub API base URI, which is used by subsequent HTTP Request n8n nodes.
Get PR Files & Get File Contents (HTTP Request n8n node):
Function: Handles communication with the GitHub API to fetch the list of files in the PR and then retrieves the content of each individual file.
Convert Base64 to Text File & Extract from File (Converter n8n nodes):
Function: Decodes the file content retrieved from GitHub (which is usually Base64 encoded) so that the raw code can be processed by the AI Agent n8n node.
Google Gemini Chat Model (Language Model n8n node):
Function: Provides the large language model capability (Gemini 2.0 Flash) to the AI Agent for complex reasoning and code manipulation tasks.
AI Agent (Langchain Agent n8n node):
Function: The intelligence core of this n8n workflow. It takes the aggregated code files and, using its configured system prompt, determines the necessary linting fixes and executes appropriate actions via its linked tools.
Create GitHub Blob/Tree/Commit/Branch/Pull Request (HTTP Request Tool n8n nodes):
* Function: These are specialized n8n node tools utilized by the AI Agent. They encapsulate complex, authenticated HTTP POST operations required to manipulate the Git repository structure (e.g., creating a new commit object or defining a new branch reference).

Related n8n Workflows

Free

Nodes: 11 Nodes
Updated: December 26 2025
View all
Created by

Featured*