Automatically generate and update README files using AI when pull requests are merged
DocLoop AI is a GitHub Action that leverages large language models (LLMs) to automatically generate and maintain README documentation for your codebase. It analyzes changes in merged pull requests and creates or updates README files in the affected directories, making documentation maintenance effortless.
- Features
- Prerequisites
- Usage
- Inputs
- How It Works
- Path Scope Configuration
- Examples
- Development
- Testing
- License
- AI-Powered Documentation: Automatically generates or updates README files using large language models (supports all OpenAI models including gpt-4o-mini, gpt-4o, and gpt-4-turbo)
- Monorepo Support: Configure multiple path scopes to handle complex monorepo architectures
- Smart Update Modes: Choose between updating existing READMEs or overwriting them completely
- Configurable Detail Levels: Control the depth and detail of generated documentation (low, medium, high)
- Flexible Deployment: Commit changes directly to the repository or create pull requests for review
- Branch Filtering: Only process PRs merged into specified base branches using glob patterns
- Path-Based Organization: Automatically organizes documentation based on directory structure and path scopes
- GitHub repository with Actions enabled
- OpenAI API key (Get one here)
- GitHub token with
contents: writeandpull-requests: writepermissions (automatically provided viaGITHUB_TOKEN)
Create a workflow file (e.g., .github/workflows/docloop.yml):
name: Update READMEs
on:
pull_request:
types: [closed]
jobs:
update-readmes:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Run DocLoop AI
uses: doorloop/docloop-ai@v1
with:
base_branches: main,develop
path_scopes: src/features/**
doc_root_depth_from_scope: 1
openai_api_key: ${{ secrets.OPENAI_API_KEY }}
create_pr: falseFor monorepo setups with multiple path scopes:
- name: Run DocLoop AI
uses: doorloop/docloop-ai@v1
with:
base_branches: main
path_scopes: |
apps/client/src/features/**
packages/ui/components/**
libs/shared/utils/**
doc_root_depth_from_scope: 1
detail_level: high
openai_model: gpt-4o
openai_api_key: ${{ secrets.OPENAI_API_KEY }}
update_mode: update
create_pr: true| Input | Required | Default | Description |
|---|---|---|---|
base_branches |
Yes | - | Comma or newline separated list of base branch names (supports glob patterns like release/*) |
path_scopes |
Yes | - | One or more glob-like path scopes (comma or newline separated) that define where changes are tracked |
doc_root_depth_from_scope |
No | 1 |
How many path segments below the scope root define a single doc root |
readme_filename |
No | README.md |
Name of the README file to create/update in each doc root |
detail_level |
No | medium |
Controls how detailed the README should be. Options: low, medium, high |
openai_model |
No | gpt-4o-mini |
OpenAI model identifier (e.g., gpt-4o-mini, gpt-4o, gpt-4-turbo) |
openai_api_key |
Yes | - | OpenAI API key (should be stored in GitHub secrets) |
update_mode |
No | update |
update to merge with existing README, overwrite for fresh generation |
commit_message |
No | docs: update READMEs [skip ci] |
Commit message used for the documentation commit |
create_pr |
No | false |
When true, creates a PR instead of committing directly |
- Trigger: The action runs when a pull request is merged (
pull_requestevent withtypes: [closed]) - Validation: Verifies that the PR was actually merged and the base branch matches one of the configured
base_branches - File Detection: Retrieves all changed files from the merged PR using the GitHub API
- Path Mapping: Maps changed files to documentation root folders based on
path_scopesanddoc_root_depth_from_scope - README Generation: For each identified doc root:
- Reads existing README content if present (when
update_mode: update) - Analyzes changed files and PR context
- Uses OpenAI API to generate or update README content
- Writes the updated README file to disk
- Reads existing README content if present (when
- Commit: Stages, commits, and pushes changes either directly to the branch or via a pull request (based on
create_prsetting)
The path_scopes input uses glob-like patterns to define which parts of your codebase should trigger README generation. Combined with doc_root_depth_from_scope, you can control how documentation is organized.
Given the configuration:
path_scopes: apps/client/src/features/**doc_root_depth_from_scope: 1
For a changed file: apps/client/src/features/inspection/components/Button.tsx
- Scope root:
apps/client/src/features - Doc root:
apps/client/src/features/inspection(1 level deep from scope root) - README location:
apps/client/src/features/inspection/README.md
You can define multiple path scopes to handle different parts of your monorepo:
path_scopes: |
apps/client/src/features/**
packages/ui/components/**
libs/shared/utils/**Each scope is processed independently, allowing different documentation strategies for different parts of your codebase.
- uses: doorloop/docloop-ai@v1
with:
base_branches: main
path_scopes: src/features/**
openai_api_key: ${{ secrets.OPENAI_API_KEY }}- uses: doorloop/docloop-ai@v1
with:
base_branches: main,develop
path_scopes: src/**
detail_level: high
openai_model: gpt-4o
openai_api_key: ${{ secrets.OPENAI_API_KEY }}
create_pr: true
commit_message: "docs: auto-update READMEs [skip ci]"- uses: doorloop/docloop-ai@v1
with:
base_branches: main,release/*
path_scopes: packages/**
openai_api_key: ${{ secrets.OPENAI_API_KEY }}- Node.js >= 20.0.0
- npm
npm install
npm run buildnpm run typechecknpm test
npm run test:watch # Watch mode
npm run test:coverage # With coverageFor comprehensive testing instructions, see TESTING.md.
-
Local testing with act (recommended):
# Install act: https://github.com/nektos/act brew install act # Setup secrets cp .secrets.example .secrets # Edit .secrets with your tokens # Build and test npm run build npm run act:test
-
Unit tests:
npm test
For detailed publishing and deployment instructions, see PUBLISHING.md.
This project is licensed under the MIT License - see the LICENSE file for details.