Use CasestutorialNovember 28, 20258 min read

Automatically Generate Documentation on Every PR

Use AI-powered PR hooks to keep your API docs, changelogs, and README files in sync with your code changes - automatically, on every pull request.

Documentation that's out of sync with code is worse than no documentation at all. It misleads developers and erodes trust. When the README says one thing and the code does another, everyone wastes time.

PR hooks solve this by automatically updating docs whenever code changes. The documentation stays current because it updates itself.

What Are PR Hooks?

PR hooks are tasks that trigger automatically when pull requests are opened or updated. They run in the context of your changes and can add commits to the same PR.

Instead of remembering to update docs after changing code, the docs update themselves. Instead of changelog entries written weeks after the fact, they're generated from the actual changes.

Think of PR hooks as automated teammates who review every PR for specific concerns. One hook watches for API changes and updates the OpenAPI spec. Another generates changelog entries. Another verifies that examples in the README still work. They run in parallel, each doing their job without you having to remember to ask.

Documentation Tasks You Can Automate

API documentation:

When API endpoints change, the documentation should too:

@devonair on PR: if files in /src/api changed, update the OpenAPI spec to match
@devonair on PR: regenerate API reference documentation from source code comments

Changelogs:

Generate changelog entries from commit messages or PR descriptions:

@devonair on PR: generate a changelog entry based on the commits in this PR
@devonair on PR: add this PR's changes to CHANGELOG.md under the "Unreleased" section

README updates:

Keep usage examples and installation instructions current:

@devonair on PR: if the CLI interface changed, update the usage examples in README.md
@devonair on PR: verify code examples in README still work after these changes

Type documentation:

Regenerate TypeScript or other type documentation from source:

@devonair on PR: regenerate TypeScript documentation in /docs/api from source files
@devonair on PR: update the type reference documentation if any exported types changed

Configuration documentation:

Keep config file documentation in sync:

@devonair on PR: if environment variables were added or changed, update the .env.example file
@devonair on PR: update the configuration reference if any config options changed

Setting Up PR Hooks

PR hooks are configured per repository. You define what triggers them and what they do.

Trigger on specific file changes:

@devonair on PR: if files matching "src/api/**" changed, update docs/api-reference.md

This only runs when API files are modified, not on every PR.

Trigger on any change:

@devonair on PR: generate changelog entry from commit messages

This runs on every PR to your repository.

Chain multiple hooks:

@devonair on PR: if API changed, update OpenAPI spec
@devonair on PR: if OpenAPI spec changed, regenerate client SDKs

Hooks can trigger other hooks, creating documentation pipelines that stay in sync automatically.

The Result

Teams using documentation hooks report:

  • Documentation stays accurate - When code changes, docs change in the same PR
  • Faster PR reviews - Reviewers trust that docs are current
  • Faster onboarding - New team members find accurate documentation
  • Less maintenance burden - Nobody has to remember to update docs

The best documentation is documentation that updates itself.

Best Practices

Keep hooks focused

One hook, one job. Don't create a hook that "updates all documentation" - create specific hooks for specific doc types. This makes failures easier to diagnose and changes easier to review.

Review hook output

PR hooks add commits to your PR. Review these changes like you'd review any other code. The automation saves time writing docs, but human review ensures quality.

Use conditional triggers

Don't run expensive documentation generation on every PR. Trigger hooks based on what actually changed:

@devonair on PR: if files in /src/api/** changed, regenerate API docs

vs.

@devonair on PR: regenerate API docs

The first only runs when relevant. The second runs on every PR, even if only a README was updated.

Document your hooks

Add a section to your contributing guide explaining what PR hooks run and what to expect. Developers should know why new commits appeared on their PR.

Common Documentation Pipelines

API-first development:

@devonair on PR: if files in /src/api changed, update openapi.yaml
@devonair on PR: if openapi.yaml changed, regenerate API reference docs
@devonair on PR: if openapi.yaml changed, regenerate TypeScript types in /src/types/api

Library documentation:

@devonair on PR: regenerate TypeDoc documentation from source
@devonair on PR: verify README examples still compile and run
@devonair on PR: update the changelog with a summary of changes

Monorepo documentation:

@devonair on PR: if packages/core changed, regenerate packages/core/README.md
@devonair on PR: if any package.json changed, update the dependency graph in docs/
@devonair on PR: generate changelog entries for each package that changed

Why Documentation Drifts

Understanding why documentation falls out of sync helps you design better hooks.

Time pressure: When deadlines loom, documentation is the first thing cut. "Ship now, document later" becomes "document never."

Separate workflows: Code lives in one place, docs in another. There's no forcing function to keep them aligned.

No ownership: Everyone's responsible means no one's responsible. Documentation becomes an orphan.

Invisible rot: Unlike broken code, broken docs don't fail the build. You don't notice the problem until someone complains.

PR hooks solve all of these by making documentation updates automatic and immediate. The docs update in the same PR as the code. There's no separate step to forget.

Real-World Documentation Pipelines

Here are complete documentation setups teams use with Devonair:

Full API documentation pipeline:

@devonair on PR: if files in /src/api changed, update openapi.yaml
@devonair on PR: if openapi.yaml changed, regenerate docs/api-reference.md
@devonair on PR: if openapi.yaml changed, update the Postman collection
@devonair on PR: if any API response types changed, regenerate TypeScript client types

Component library documentation:

@devonair on PR: if files in /src/components changed, update Storybook stories
@devonair on PR: regenerate component prop documentation from TypeScript interfaces
@devonair on PR: update the component changelog with changes from this PR

CLI tool documentation:

@devonair on PR: if CLI commands changed, update README usage examples
@devonair on PR: if any --help text changed, regenerate docs/cli-reference.md
@devonair on PR: verify all CLI examples in documentation actually work

Getting Started

Pick the documentation that drifts most often in your project. The docs that are always out of date, that nobody wants to update, that new team members complain about.

Set up a hook:

@devonair on PR: [describe what should update and when]

Watch the next few PRs. Review the generated documentation. Adjust the hook if needed.

Documentation that stays in sync with code isn't a discipline problem - it's an automation problem. Solve it once, and it stays solved.


FAQ

Can PR hooks modify files outside the PR's changes?

Yes. PR hooks can update any file in the repository. They add commits to your PR branch, which you review before merging.

What if a PR hook generates incorrect documentation?

Review the hook's changes like any other code. If the generated docs are wrong, you can edit them manually in the same PR, or adjust the hook configuration to improve future runs.

Do PR hooks run on draft PRs?

By default, hooks run when PRs are opened or updated, including drafts. You can configure hooks to skip draft PRs if you prefer.

Can I have different hooks for different branches?

Yes. You can configure hooks to only run on PRs targeting specific branches. For example, you might want changelog generation only on PRs to main, not on feature branch PRs.

What if my documentation requires human judgment?

Some documentation needs human input - like writing conceptual explanations or deciding what to emphasize. PR hooks work best for mechanical documentation: API references, changelogs, type docs, and examples. Use hooks for the mechanical parts and let humans handle the narrative.

How do I debug a hook that's not working?

Check the Devonair dashboard for task logs. You'll see what the hook attempted, what files it looked at, and any errors. Common issues: file patterns that don't match, missing dependencies, or permissions problems.

Are PR hook changes included in the PR's commit history?

Yes. PR hooks add commits to your PR branch. These commits are visible in the PR's commit history and are included when the PR is merged.