Skip to content

Auto Documentation & Docstrings

Actions

About

Automatically generate documentation and docstrings for multi-language codebases using AI (Anthropic Claude or Google Gemini)
v2.0.0
Latest
StarΒ (2)

Auto Documentation & Docstrings Action

A GitHub Action that automatically generates comprehensive documentation and docstrings for multi-language codebases using AI models (Anthropic Claude or Google Gemini).

πŸš€ Features

  • Multi-language Support: Works with Go, TypeScript, Python and Java. Easily extensible to other languages.
  • AI-Powered: Uses either Anthropic Claude or Google Gemini for intelligent documentation generation
  • Automatic Detection: Scans your codebase and identifies files that need documentation
  • Smart Documentation: Generates appropriate docstrings following language-specific conventions
  • Repository Analysis: Creates an AI_CONTEXT.md file with comprehensive project context
  • Pull Request Workflow: Creates a new branch with documentation changes for review

🎯 Supported Languages

Language Documentation Style Features
Go // FunctionName does... Exported functions, parameters, return values
TypeScript /** @description */ TSDoc Functions, classes, interfaces with JSDoc tags
Python """Triple quotes""" Functions and classes with Google/NumPy style
Java /** Javadoc */ Public methods and classes with Javadoc tags

πŸ”§ Setup

Prerequisites

You'll need an API key from either:

Repository Secrets

Add your chosen API key to your repository secrets:

ANTHROPIC_API_KEY=your_anthropic_api_key_here
# OR
GEMINI_API_KEY=your_gemini_api_key_here

πŸ“ Usage

Basic Usage (Anthropic Claude)

name: Auto Documentation

on:
  push:
    branches: [main, develop]
  pull_request:
    types: [opened, synchronize]

jobs:
  documentation:
    runs-on: ubuntu-latest
    permissions:
      contents: write
      pull-requests: write
    
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Auto Documentation & Docstrings
        uses: devasy23/auto-documentation-action@v1
        with:
          model_provider: 'anthropic'
          anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}

Using Google Gemini

      - name: Auto Documentation & Docstrings
        uses: devasy23/auto-documentation-action@v1
        with:
          model_provider: 'gemini'
          gemini_api_key: ${{ secrets.GEMINI_API_KEY }}

Advanced Configuration

      - name: Auto Documentation & Docstrings
        uses: devasy23/auto-documentation-action@v1
        with:
          model_provider: 'anthropic'
          anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
          target_branches: 'main,master,develop,staging'
          commit_message: 'docs: Update documentation with AI assistance'

Manual Trigger with Model Selection

name: Auto Documentation

on:
  workflow_dispatch:
    inputs:
      model_provider:
        description: 'AI Model Provider'
        required: true
        default: 'anthropic'
        type: choice
        options:
        - anthropic
        - gemini

jobs:
  documentation:
    runs-on: ubuntu-latest
    permissions:
      contents: write
      pull-requests: write
    
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Auto Documentation & Docstrings
        uses: devasy23/auto-documentation-action@v1
        with:
          model_provider: ${{ github.event.inputs.model_provider }}
          anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
          gemini_api_key: ${{ secrets.GEMINI_API_KEY }}

πŸ“Š Inputs

Input Description Required Default
model_provider AI model provider (anthropic or gemini) No anthropic
anthropic_api_key Anthropic API key for Claude AI No* -
gemini_api_key Google Gemini API key No* -
target_branches Comma-separated list of branches to run on No main,master,develop
commit_message Custom commit message for documentation updates No docs: Auto-generated multi-language documentation

*Required based on selected model_provider

πŸ“€ Outputs

Output Description
files_processed Number of files that were processed
context_md_generated Whether AI_CONTEXT.md was generated (true/false)
branch_created Name of the branch created with changes

🧩 Extending the Action

This action is designed to be easily extensible to support new languages. To add support for a new language, you need to create a new JSON configuration file in the config directory.

For example, to add support for a new language called "MyLang", you would create a file named config/mylang.json with the following structure:

{
  "language": "MyLang",
  "extensions": ["mylang"],
  "detection_logic": {
    "definitions": "regex_to_find_definitions",
    "documented": "regex_to_find_documented_definitions"
  },
  "prompt": [
    "Prompt to generate documentation for MyLang..."
  ]
}
  • language: The name of the language.
  • extensions: An array of file extensions for the language.
  • detection_logic:
    • definitions: A regular expression to find the total number of definitions (functions, classes, etc.) in a file.
    • documented: A regular expression to find the number of already documented definitions.
  • prompt: An array of strings that will be joined to form the prompt for the AI model.

The action will automatically pick up the new configuration file and start processing files for the new language.

πŸ” What It Does

  1. Repository Analysis: Scans your codebase structure and creates a comprehensive AI_CONTEXT.md file
  2. File Detection: Identifies Go, TypeScript, and Python files that lack proper documentation
  3. AI Documentation: Uses your chosen AI provider to generate appropriate docstrings and comments
  4. Quality Validation: Ensures generated content follows language-specific conventions
  5. Branch Creation: Creates a new branch with all documentation changes
  6. Summary Report: Provides a detailed summary of what was processed and updated

🎨 Generated AI_CONTEXT.md

The action automatically creates an AI_CONTEXT.md file containing:

  • Project Overview: Intelligent analysis of your project's purpose
  • Architecture: Inferred structure and design patterns
  • Technology Stack: Detected languages, frameworks, and tools
  • Development Guidelines: Language-specific best practices
  • Build Instructions: Appropriate commands for your project type
  • Testing Strategy: Recommended testing approaches

πŸ”’ Security & Privacy

  • API keys are handled securely through GitHub Secrets
  • All AI API calls are made over HTTPS
  • No code is stored or cached by the AI providers beyond the request
  • Generated documentation is reviewed before merging via pull request workflow

πŸ› Troubleshooting

Common Issues

API Key Not Working

  • Ensure your API key is correctly added to repository secrets
  • Verify the API key has proper permissions and isn't expired
  • Check that you're using the correct provider (anthropic vs gemini)

No Files Processed

  • The action only processes files with undocumented exported functions/classes
  • Ensure your code follows standard conventions for exports
  • Check the action logs for detailed file scanning results

Generated Content Issues

  • AI-generated content is validated but may occasionally need manual review
  • The action creates a review branch specifically for this purpose
  • You can adjust prompts by modifying the action workflow

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ™ Acknowledgments

  • Anthropic for Claude AI
  • Google for Gemini AI
  • The open-source community for inspiration and feedback

Auto Documentation & Docstrings is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.

About

Automatically generate documentation and docstrings for multi-language codebases using AI (Anthropic Claude or Google Gemini)
v2.0.0
Latest

Auto Documentation & Docstrings is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.