FM
FlowMarket
AI Agents Advanced ⚡ 20 n8n Nodes

Automate GitHub PR linting with Google Gemini AI and auto fix PR

LintGuardian: Automated PR Linting with n8n & AI What It Does LintGuardian is an n8n workflow template that automates code quality enforcement for GitHub rep...

🔌 Nodes & Integrations Used (6)

Agent HTTP Request Convert To File Extract From File Http Request Tool Lm Chat Google Gemini

📖 Implementation & Setup Guide

LintGuardian: Automated PR Linting with n8n & AI

What It Does

LintGuardian is an n8n workflow template that automates code quality enforcement for GitHub repositories. When a pull request is created, the workflow automatically analyzes the changed files, identifies linting issues, fixes them, and submits a new PR with corrections. This eliminates manual code style reviews, reduces back-and-forth comments, and lets your team focus on functionality rather than formatting.

How It Works

The workflow is triggered by a GitHub webhook when a PR is created. It fetches all changed files from the PR using the GitHub API, processes them through an AI-powered linting service (Google Gemini), and automatically generates fixes. The AI agent then creates a new branch with the corrected files and submits a "linting fixes" PR against the original branch. Developers can review and merge these fixes with a single click, keeping code consistently formatted with minimal effort.

Prerequisites

To use this template, you'll need:

  1. **n8n instance**: Either self-hosted or using n8n.cloud
  2. **GitHub repository**: Where you want to enforce linting standards
  3. **GitHub Personal Access Token**: With permissions for repo access (repo, workflow, admin:repo_hook)
  4. **Google AI API Key**: For the Gemini language model that powers the linting analysis
  5. **GitHub webhook**: Configured to send PR creation events to your n8n instance

Setup Instructions

  1. **Import the template** into your n8n instance
  2. **Configure credentials**:
  3. - Add your [GitHub Personal Access Token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic) under Credentials → GitHub API
  4. - Add your [Google AI API key](https://ai.google.dev/tutorials/setup) under Credentials → Google Gemini API
  5. **Update repository information**:
  6. - Locate the "Set Common Fields" code node at the beginning of the workflow
  7. - Change the `gitHubRepoName` and `gitHubOrgName` values to match your repository
  8. ```javascript
  9. const commonFields = {
  10. 'gitHubRepoName': 'your-repo-name',
  11. 'gitHubOrgName': 'your-org-name'
  12. }
  13. ```
  14. **Configure the webhook**:
  15. Create a file named `.github/workflows/lint-guardian.yml` in your repository replacing the `Trigger n8n Workflow` step with your webhook:
  16. ```yaml
  17. name: Lint Guardian
  18. on:
  19. pull_request:
  20. types: [opened, synchronize]
  21. jobs:
  22. trigger-linting:
  23. runs-on: ubuntu-latest
  24. steps:
  25. - name: Trigger n8n Workflow
  26. uses: fjogeleit/http-request-action@v1
  27. with:
  28. url: 'https://your-n8n-instance.com/webhook/1da5a6e1-9453-4a65-bbac-a1fed633f6ad'
  29. method: 'POST'
  30. contentType: 'application/json'
  31. data: |
  32. {
  33. "pull_request_number": ${{ github.event.pull_request.number }},
  34. "repository": "${{ github.repository }}",
  35. "branch": "${{ github.event.pull_request.head.ref }}",
  36. "base_branch": "${{ github.event.pull_request.base.ref }}"
  37. }
  38. preventFailureOnNoResponse: true
  39. ```
  40. **Customize linting rules** (optional):
  41. - Modify the AI Agent's system message to specify your team's linting preferences
  42. - Adjust file handling if you have specific file types to focus on or ignore

Security Considerations

When creating your GitHub Personal Access Token, remember to: - Choose the minimal permissions needed (repo, workflow, admin:repo_hook) - Set an appropriate expiration date - Treat your token like a password and store it securely - Consider using GitHub's fine-grained personal access tokens for more limited scope

As GitHub [documentation](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#keeping-your-personal-access-tokens-secure) notes: "Personal access tokens are like passwords, and they share the same inherent security risks."

Extending the Template

You can enhance this workflow by: - Adding Slack notifications when linting fixes are submitted - Creating custom linting rules specific to your team's needs - Expanding it to handle different types of code quality checks - Adding approval steps for more controlled environments

This template provides an excellent starting point that you can customize to fit your team's exact workflow and code style requirements.

⚡ How to import this workflow into n8n:

  1. Click the Direct Download JSON button above to save Automate_GitHub_PR_linting_with_Google_Gemini_AI_and_auto_fix_PR.json.
  2. Log in to your n8n Cloud or self-hosted n8n instance.
  3. In your workflow canvas, click the menu in top-right and select Import from File (or paste the JSON directly).
  4. Configure your credentials (e.g. API keys, database URLs) in the corresponding node settings.
  5. Click Execute Workflow to test and switch to Active!

Related AI Agents Workflows

View All in AI Agents →