Skip to main content

Pull Request Markdown Generator

Project description

PR2MD - Pull Request to Markdown

Python 3.13+ License: CRL

PR2MD is a powerful command-line tool that extracts GitHub Pull Request data and converts it into comprehensive, well-formatted Markdown documents. Perfect for documentation, archiving, code reviews, or offline analysis of pull requests.

Features

  • ๐Ÿ“ฅ Complete PR Data Extraction: Retrieves all PR details including metadata, description, labels, and timestamps
  • ๐Ÿ’ฌ Full Conversation Thread: Captures all comments and discussions in chronological order
  • โœ… Review Information: Includes all code reviews with approval status and reviewer comments
  • ๐Ÿ’ป Code Comments: Extracts inline review comments with their associated code context
  • ๐Ÿ“Š Change Statistics: Displays files changed, additions, deletions, and commit information
  • ๐Ÿ” Complete Diffs: Includes the full unified diff of all changes
  • ๐ŸŽจ Beautiful Formatting: Generates clean, readable Markdown with proper structure and syntax highlighting
  • โšก Fast & Efficient: Uses the official GitHub REST API with proper error handling
  • ๐Ÿ”’ Type-Safe: Written in Python with comprehensive type annotations

Installation

From Source

# Clone the repository
git clone https://github.com/tboy1337/PR2MD.git
cd PR2MD

# Install dependencies
pip install -r requirements.txt

# Install the package
pip install -e .

Requirements

  • Python 3.13 or higher
  • requests library (for GitHub API communication)

Usage

Basic Usage

Extract a PR using its URL:

pr2md https://github.com/owner/repo/pull/123

Or specify the owner, repository, and PR number separately:

pr2md owner repo 123

Save to File

Output the Markdown to a file instead of stdout:

pr2md https://github.com/owner/repo/pull/123 -o pr-details.md
pr2md owner repo 123 --output pr-analysis.md

Verbose Logging

Enable detailed logging for debugging:

pr2md https://github.com/owner/repo/pull/123 --verbose

Help

View all available options:

pr2md --help

Output Format

The generated Markdown document includes:

1. PR Header

  • PR number, title, and status (Open/Closed/Merged)
  • Author information with GitHub profile link
  • Creation, update, closed, and merged timestamps
  • Base and head branch information with commit SHAs
  • Labels (if any)

2. Description

  • The full PR description/body

3. Changes Summary

  • Number of files changed
  • Line additions and deletions

4. Code Diff

  • Complete unified diff of all changes
  • Syntax-highlighted code blocks

5. Conversation Thread

  • All comments from the PR discussion
  • Chronologically sorted
  • Author attribution and timestamps
  • Links back to GitHub

6. Reviews

  • All submitted reviews
  • Review state (Approved โœ…, Changes Requested ๐Ÿ”ด, Commented ๐Ÿ’ฌ, etc.)
  • Review comments and timestamps

7. Review Comments (Code Comments)

  • Inline code review comments
  • Grouped by file
  • Includes code context (diff hunk)
  • Reply chains preserved

Example

# Extract PR #42 from the PR2MD repository
pr2md tboy1337 PR2MD 42 -o pr-42.md

This creates a file pr-42.md containing all the PR information in a beautifully formatted Markdown document.

GitHub API Rate Limiting

The tool uses the GitHub REST API without authentication by default. GitHub imposes rate limits:

  • Unauthenticated requests: 60 requests per hour
  • Authenticated requests: 5,000 requests per hour

For most use cases, unauthenticated access is sufficient as the tool makes only a few API calls per PR. If you encounter rate limiting issues, the tool will provide clear error messages.

Future Enhancement: Authentication support is planned for a future release to enable higher rate limits and access to private repositories.

Development

Setup Development Environment

# Clone the repository
git clone https://github.com/tboy1337/PR2MD.git
cd PR2MD

# Install development dependencies
pip install -r requirements-dev.txt

# Install the package in editable mode
pip install -e .

Running Tests

The project includes comprehensive tests using pytest:

# Run all tests
pytest

# Run with coverage
pytest --cov=pr2md --cov-report=html

# Run specific test file
pytest tests/test_cli.py

# Run with verbose output
pytest -v

Code Quality

The project maintains high code quality standards:

# Type checking with mypy
mypy src/pr2md

# Linting with pylint
pylint src/pr2md

# Code formatting with black
black src/pr2md tests

# Import sorting with isort
isort src/pr2md tests

# Remove trailing whitespace
py -m autopep8 --in-place --select=W291,W293 src tests

Project Structure

PR2MD/
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ pr2md/
โ”‚       โ”œโ”€โ”€ __init__.py
โ”‚       โ”œโ”€โ”€ __main__.py      # Entry point
โ”‚       โ”œโ”€โ”€ cli.py           # Command-line interface
โ”‚       โ”œโ”€โ”€ models.py        # Data models
โ”‚       โ”œโ”€โ”€ pr_extractor.py  # GitHub API client
โ”‚       โ”œโ”€โ”€ formatter.py     # Markdown formatter
โ”‚       โ””โ”€โ”€ py.typed         # Type checking marker
โ”œโ”€โ”€ tests/                   # Comprehensive test suite
โ”œโ”€โ”€ pyproject.toml          # Project configuration
โ”œโ”€โ”€ requirements.txt        # Runtime dependencies
โ”œโ”€โ”€ requirements-dev.txt    # Development dependencies
โ”œโ”€โ”€ mypy.ini               # Type checking configuration
โ”œโ”€โ”€ pytest.ini             # Test configuration
โ””โ”€โ”€ README.md              # This file

Architecture

Core Components

  1. CLI Module (cli.py): Handles command-line argument parsing, logging setup, and orchestrates the extraction and formatting process.

  2. PR Extractor (pr_extractor.py): Communicates with the GitHub REST API to fetch PR data, comments, reviews, and diffs. Includes comprehensive error handling.

  3. Models (models.py): Type-safe data classes representing GitHub entities (PullRequest, Comment, Review, ReviewComment, User, Label).

  4. Formatter (formatter.py): Converts structured PR data into beautifully formatted Markdown with proper sections and syntax highlighting.

Design Principles

  • Type Safety: Full type annotations throughout the codebase
  • Error Handling: Graceful handling of API errors and edge cases
  • Logging: Comprehensive logging for debugging and monitoring
  • Testability: Modular design with clear separation of concerns
  • Extensibility: Easy to add new features or output formats

Use Cases

  • Code Review Documentation: Archive code reviews for compliance or historical reference
  • Offline Analysis: Review PRs without internet connectivity
  • Pull Request Templates: Learn from well-structured PRs
  • Change Management: Document significant changes in projects
  • Training Materials: Create educational resources from real-world code reviews
  • Audit Trails: Maintain records of development decisions
  • Report Generation: Include PR details in project reports

Limitations

  • Currently supports only public GitHub repositories (authentication coming soon)
  • Rate limited by GitHub API (60 requests/hour without authentication)
  • Requires internet connection to fetch data
  • Large PRs with extensive diffs may generate very large Markdown files

Roadmap

  • GitHub authentication support (personal access tokens)
  • Support for GitHub Enterprise
  • Private repository access
  • Batch processing of multiple PRs
  • Custom output templates
  • Additional output formats (HTML, PDF)
  • Diff filtering and summarization
  • PR comparison tool
  • Integration with CI/CD pipelines

Contributing

This project is maintained by tboy1337. Contributions, issues, and feature requests are welcome! Feel free to check the issues page.

License

This project is licensed under the Commercial Restricted License (CRL) Version 1.1.

Summary:

  • โœ… Free for non-commercial use (personal, educational, research, open source)
  • โŒ Commercial use requires a separate commercial license
  • ๐Ÿ“ง Contact the copyright holder for commercial licensing inquiries

See the LICENSE.md file for the complete license text.

Author

tboy1337

Acknowledgments

  • Built with Python 3.13+
  • Uses the GitHub REST API
  • Inspired by the need for better PR documentation tools

Made with โค๏ธ for the developer community

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pr2md-1.0.1.tar.gz (25.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pr2md-1.0.1-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

Details for the file pr2md-1.0.1.tar.gz.

File metadata

  • Download URL: pr2md-1.0.1.tar.gz
  • Upload date:
  • Size: 25.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for pr2md-1.0.1.tar.gz
Algorithm Hash digest
SHA256 a7662a2d12d27451f1ef5fb1045d7c476447b8e233c751ac25a08b5e336b3efb
MD5 a559ad8b9dee5bbb40c5b60b99c12ef0
BLAKE2b-256 a7363f365ad2c0dfd8f7a4f0e67e7cd82d962e30657204bf1cfcfe5a56c87c6d

See more details on using hashes here.

File details

Details for the file pr2md-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: pr2md-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 14.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for pr2md-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5981bf8ff475e9ef4f6d72c934c018cf0f7a750a7cb499427fdf290e2e49bbc4
MD5 b73bd6da02d3a5def2f74899850fab66
BLAKE2b-256 dca5430588d0432e9aa80804f984d75dc737b3a19818d6c0734e827b686f2c70

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page