|
1 | 1 | # gh-download-pull-request |
2 | | -A tool to download GitHub pull request for AI to improve or review |
| 2 | + |
| 3 | +[](https://www.npmjs.com/package/gh-download-pull-request) |
| 4 | + |
| 5 | +Download GitHub pull request and convert it to markdown - perfect for AI review and analysis. |
| 6 | + |
| 7 | +## Features |
| 8 | + |
| 9 | +- Download any GitHub pull request as markdown |
| 10 | +- Includes PR metadata, commits, files, reviews, and comments |
| 11 | +- Support for both public and private repositories |
| 12 | +- Multiple input formats for convenience |
| 13 | +- GitHub CLI integration for seamless authentication |
| 14 | +- Output to file or stdout |
| 15 | + |
| 16 | +## Quick Start |
| 17 | + |
| 18 | +```bash |
| 19 | +# Download a PR and display as markdown |
| 20 | +gh-download-pull-request https://github.com/owner/repo/pull/123 |
| 21 | + |
| 22 | +# Using shorthand format |
| 23 | +gh-download-pull-request owner/repo#123 |
| 24 | + |
| 25 | +# Save to file |
| 26 | +gh-download-pull-request owner/repo#123 -o pr.md |
| 27 | + |
| 28 | +# Download private PR (uses gh CLI auth automatically) |
| 29 | +gh-download-pull-request owner/private-repo#456 |
| 30 | +``` |
| 31 | + |
| 32 | +## Installation |
| 33 | + |
| 34 | +### Global Installation (Recommended) |
| 35 | + |
| 36 | +Install globally for system-wide access: |
| 37 | + |
| 38 | +```bash |
| 39 | +# Using bun |
| 40 | +bun install -g gh-download-pull-request |
| 41 | + |
| 42 | +# Using npm |
| 43 | +npm install -g gh-download-pull-request |
| 44 | + |
| 45 | +# After installation, use anywhere: |
| 46 | +gh-download-pull-request --help |
| 47 | +``` |
| 48 | + |
| 49 | +### Uninstall |
| 50 | + |
| 51 | +Remove the global installation: |
| 52 | + |
| 53 | +```bash |
| 54 | +# Using bun |
| 55 | +bun uninstall -g gh-download-pull-request |
| 56 | + |
| 57 | +# Using npm |
| 58 | +npm uninstall -g gh-download-pull-request |
| 59 | +``` |
| 60 | + |
| 61 | +### Local Installation |
| 62 | + |
| 63 | +```bash |
| 64 | +# Clone the repository |
| 65 | +git clone https://github.com/link-foundation/gh-download-pull-request.git |
| 66 | +cd gh-download-pull-request |
| 67 | + |
| 68 | +# Make the script executable |
| 69 | +chmod +x gh-download-pull-request.mjs |
| 70 | + |
| 71 | +# Run it |
| 72 | +./gh-download-pull-request.mjs --help |
| 73 | +``` |
| 74 | + |
| 75 | +## Usage |
| 76 | + |
| 77 | +``` |
| 78 | +Usage: gh-download-pull-request <pr-url> [options] |
| 79 | +
|
| 80 | +Options: |
| 81 | + -t, --token GitHub personal access token (optional for public PRs) |
| 82 | + -o, --output Output file path (default: stdout) |
| 83 | + -h, --help Show help |
| 84 | + --version Show version number |
| 85 | +``` |
| 86 | + |
| 87 | +## Input Formats |
| 88 | + |
| 89 | +The tool supports multiple formats for specifying a pull request: |
| 90 | + |
| 91 | +1. **Full URL**: `https://github.com/owner/repo/pull/123` |
| 92 | +2. **Shorthand with #**: `owner/repo#123` |
| 93 | +3. **Shorthand with /**: `owner/repo/123` |
| 94 | + |
| 95 | +## Authentication |
| 96 | + |
| 97 | +The tool supports multiple authentication methods for accessing private repositories: |
| 98 | + |
| 99 | +### 1. GitHub CLI (Recommended) |
| 100 | + |
| 101 | +If you have [GitHub CLI](https://cli.github.com/) installed and authenticated, the tool will automatically use your credentials: |
| 102 | + |
| 103 | +```bash |
| 104 | +# Authenticate with GitHub CLI (one-time setup) |
| 105 | +gh auth login |
| 106 | + |
| 107 | +# Tool automatically detects and uses gh CLI authentication |
| 108 | +gh-download-pull-request owner/private-repo#123 |
| 109 | +``` |
| 110 | + |
| 111 | +### 2. Environment Variable |
| 112 | + |
| 113 | +Set the `GITHUB_TOKEN` environment variable: |
| 114 | + |
| 115 | +```bash |
| 116 | +export GITHUB_TOKEN=ghp_your_token_here |
| 117 | +gh-download-pull-request owner/repo#123 |
| 118 | +``` |
| 119 | + |
| 120 | +### 3. Command Line Token |
| 121 | + |
| 122 | +Pass the token directly with `--token`: |
| 123 | + |
| 124 | +```bash |
| 125 | +gh-download-pull-request owner/repo#123 --token ghp_your_token_here |
| 126 | +``` |
| 127 | + |
| 128 | +### Authentication Priority |
| 129 | + |
| 130 | +The tool uses this fallback chain: |
| 131 | +1. `--token` command line argument (highest priority) |
| 132 | +2. `GITHUB_TOKEN` environment variable |
| 133 | +3. GitHub CLI authentication (if `gh` is installed and authenticated) |
| 134 | +4. No authentication (public PRs only) |
| 135 | + |
| 136 | +## Output Format |
| 137 | + |
| 138 | +The markdown output includes: |
| 139 | + |
| 140 | +- **Header**: PR title |
| 141 | +- **Metadata**: PR number, author, status, dates, branch info, stats |
| 142 | +- **Description**: Full PR description/body |
| 143 | +- **Commits**: List of all commits with links and authors |
| 144 | +- **Files Changed**: All modified files with change stats |
| 145 | +- **Reviews**: All PR reviews with approval status |
| 146 | +- **Review Comments**: Inline code review comments with diff context |
| 147 | +- **Comments**: General discussion comments |
| 148 | + |
| 149 | +## Examples |
| 150 | + |
| 151 | +```bash |
| 152 | +# Basic usage - download and display PR |
| 153 | +gh-download-pull-request https://github.com/facebook/react/pull/28000 |
| 154 | + |
| 155 | +# Using shorthand format |
| 156 | +gh-download-pull-request facebook/react#28000 |
| 157 | + |
| 158 | +# Save to file |
| 159 | +gh-download-pull-request facebook/react#28000 -o react-pr-28000.md |
| 160 | + |
| 161 | +# Download private PR using gh CLI auth |
| 162 | +gh-download-pull-request myorg/private-repo#42 |
| 163 | + |
| 164 | +# Download with explicit token |
| 165 | +gh-download-pull-request myorg/repo#123 --token ghp_your_token_here |
| 166 | + |
| 167 | +# Pipe to other tools (e.g., AI for review) |
| 168 | +gh-download-pull-request owner/repo#123 | claude-analyze |
| 169 | +``` |
| 170 | + |
| 171 | +## Requirements |
| 172 | + |
| 173 | +- [Bun](https://bun.sh/) (>=1.2.0) or [Node.js](https://nodejs.org/) (>=22.17.0) runtime |
| 174 | +- For private repositories (optional): |
| 175 | + - [GitHub CLI](https://cli.github.com/) (recommended) OR |
| 176 | + - GitHub personal access token (via `--token` or `GITHUB_TOKEN` env var) |
| 177 | + |
| 178 | +## Use Cases |
| 179 | + |
| 180 | +- **AI Code Review**: Download PRs as markdown for analysis by AI assistants |
| 181 | +- **Documentation**: Archive important PRs for future reference |
| 182 | +- **Offline Review**: Review PRs without internet connection |
| 183 | +- **Custom Analysis**: Process PR data with custom scripts |
| 184 | +- **Team Workflows**: Integrate PR data into custom review processes |
| 185 | + |
| 186 | +## Testing |
| 187 | + |
| 188 | +```bash |
| 189 | +# Run all tests |
| 190 | +./tests/test-all.mjs |
| 191 | + |
| 192 | +# Run specific test |
| 193 | +./tests/test-cli.mjs |
| 194 | +``` |
| 195 | + |
| 196 | +## Development |
| 197 | + |
| 198 | +```bash |
| 199 | +# Clone the repository |
| 200 | +git clone https://github.com/link-foundation/gh-download-pull-request.git |
| 201 | +cd gh-download-pull-request |
| 202 | + |
| 203 | +# Make executable |
| 204 | +chmod +x gh-download-pull-request.mjs |
| 205 | + |
| 206 | +# Test locally |
| 207 | +./gh-download-pull-request.mjs owner/repo#123 |
| 208 | + |
| 209 | +# Bump version |
| 210 | +./version.mjs patch # or minor, major |
| 211 | +``` |
| 212 | + |
| 213 | +## Related Projects |
| 214 | + |
| 215 | +- [gh-pull-all](https://github.com/link-foundation/gh-pull-all) - Efficiently sync all repositories from a GitHub organization or user |
| 216 | + |
| 217 | +## License |
| 218 | + |
| 219 | +This project is released into the public domain under The Unlicense - see [LICENSE](LICENSE) file for details. |
0 commit comments