|
| 1 | +# Auto PR Description Generator |
| 2 | + |
| 3 | +A reusable GitHub Action that automatically generates pull request descriptions using AI (Google Gemini) based on the git diff of changes. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- 🤖 **AI-Powered**: Uses Google Gemini to analyze code changes and generate meaningful descriptions |
| 8 | +- 🎯 **Smart Formatting**: Generates structured descriptions with Description, Changes, and Verification sections |
| 9 | +- 🖼️ **Image Preservation**: Maintains existing images at the top of PR descriptions |
| 10 | +- 🎫 **JIRA Integration**: Automatically extracts JIRA ticket IDs and adds ticket links |
| 11 | +- ⚡ **Fast & Lightweight**: Minimal dependencies and quick execution |
| 12 | + |
| 13 | +## Usage |
| 14 | + |
| 15 | +### Basic Usage |
| 16 | + |
| 17 | +```yaml |
| 18 | +- name: Generate PR Description |
| 19 | + uses: ./.github/actions/auto-pr-description |
| 20 | + with: |
| 21 | + gemini-api-key: ${{ secrets.GEMINI_API_KEY }} |
| 22 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 23 | + pr-number: ${{ github.event.pull_request.number }} |
| 24 | + base-sha: ${{ github.event.pull_request.base.sha }} |
| 25 | + head-sha: ${{ github.event.pull_request.head.sha }} |
| 26 | +``` |
| 27 | +
|
| 28 | +### Complete Workflow Example |
| 29 | +
|
| 30 | +```yaml |
| 31 | +name: Auto PR Description |
| 32 | +on: |
| 33 | + pull_request: |
| 34 | + types: [labeled] |
| 35 | + |
| 36 | +jobs: |
| 37 | + update-pr-description: |
| 38 | + name: Update PR Description |
| 39 | + runs-on: ubuntu-latest |
| 40 | + if: | |
| 41 | + github.event_name == 'pull_request' && |
| 42 | + github.base_ref == 'main' && |
| 43 | + (github.event.pull_request.draft == false || github.event.action == 'labeled') && |
| 44 | + (contains(github.event.pull_request.labels.*.name, 'auto-pr-description') || |
| 45 | + contains(github.event.pull_request.labels.*.name, 'test')) |
| 46 | + permissions: |
| 47 | + pull-requests: write |
| 48 | + contents: read |
| 49 | + steps: |
| 50 | + - uses: actions/checkout@v4 |
| 51 | + with: |
| 52 | + fetch-depth: 0 |
| 53 | + |
| 54 | + - name: Generate PR Description |
| 55 | + uses: ./.github/actions/auto-pr-description |
| 56 | + with: |
| 57 | + gemini-api-key: ${{ secrets.GEMINI_API_KEY }} |
| 58 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 59 | + pr-number: ${{ github.event.pull_request.number }} |
| 60 | + base-sha: ${{ github.event.pull_request.base.sha }} |
| 61 | + head-sha: ${{ github.event.pull_request.head.sha }} |
| 62 | + jira-ticket-url-prefix: 'https://yourcompany.atlassian.net/browse/' |
| 63 | +``` |
| 64 | +
|
| 65 | +## Inputs |
| 66 | +
|
| 67 | +| Input | Description | Required | Default | |
| 68 | +|-------|-------------|----------|---------| |
| 69 | +| `gemini-api-key` | The API key for the Gemini API | ✅ | - | |
| 70 | +| `github-token` | GitHub token for PR operations | ✅ | - | |
| 71 | +| `pr-number` | Pull request number | ✅ | - | |
| 72 | +| `base-sha` | Base commit SHA for diff comparison | ✅ | - | |
| 73 | +| `head-sha` | Head commit SHA for diff comparison | ✅ | - | |
| 74 | +| `jira-ticket-url-prefix` | JIRA ticket URL prefix | ❌ | `https://virdocs.atlassian.net/browse/` | |
| 75 | + |
| 76 | +## Outputs |
| 77 | + |
| 78 | +| Output | Description | |
| 79 | +|--------|-------------| |
| 80 | +| `description` | The generated PR description | |
| 81 | +| `updated` | Whether the PR description was updated | |
| 82 | + |
| 83 | +## Generated Description Format |
| 84 | + |
| 85 | +The action generates PR descriptions in this structured format: |
| 86 | + |
| 87 | +```markdown |
| 88 | +## Description |
| 89 | +A concise summary of what the changes accomplish. |
| 90 | +
|
| 91 | +## Changes |
| 92 | +- [ ] Specific change or feature added |
| 93 | +- [ ] Another modification made |
| 94 | +- [ ] Bug fix or improvement |
| 95 | +
|
| 96 | +## Verification |
| 97 | +- [ ] Test that should be performed |
| 98 | +- [ ] Verification step to confirm functionality |
| 99 | +- [ ] Additional checks recommended |
| 100 | +
|
| 101 | +## Ticket |
| 102 | +https://yourcompany.atlassian.net/browse/TICKET-123 |
| 103 | +``` |
| 104 | + |
| 105 | +## JIRA Integration |
| 106 | + |
| 107 | +The action automatically detects JIRA ticket IDs from: |
| 108 | +1. **PR Title**: Extracts patterns like `CORE-1234`, `PAR-567`, etc. |
| 109 | +2. **Branch Name**: Falls back to branch name if not found in title |
| 110 | + |
| 111 | +Example branch names that work: |
| 112 | +- `CORE-1234-feature-description` |
| 113 | +- `PAR-567-bug-fix` |
| 114 | +- `feature/CORE-1234-new-feature` |
| 115 | + |
| 116 | +## Prerequisites |
| 117 | + |
| 118 | +### Required Secrets |
| 119 | + |
| 120 | +1. **GEMINI_API_KEY**: Get your API key from [Google AI Studio](https://makersuite.google.com/app/apikey) |
| 121 | +2. **GITHUB_TOKEN**: Automatically provided by GitHub Actions |
| 122 | + |
| 123 | +### Required Permissions |
| 124 | + |
| 125 | +The workflow must have these permissions: |
| 126 | +```yaml |
| 127 | +permissions: |
| 128 | + pull-requests: write |
| 129 | + contents: read |
| 130 | +``` |
| 131 | + |
| 132 | +## Trigger Patterns |
| 133 | + |
| 134 | +### Label-Based Triggering |
| 135 | +Add these labels to trigger the action: |
| 136 | +- `auto-pr-description`: Specific label for PR description generation |
| 137 | +- `test`: Dual-purpose label that can trigger both testing and description generation |
| 138 | + |
| 139 | +### Draft Mode Handling |
| 140 | +- **Draft PRs**: Action doesn't run automatically to save CI resources |
| 141 | +- **Label Override**: Adding trigger labels to draft PRs will run the action |
| 142 | +- **Ready for Review**: Converting draft to ready automatically triggers the action |
| 143 | + |
| 144 | +## Error Handling |
| 145 | + |
| 146 | +The action handles various error scenarios: |
| 147 | +- Missing or invalid Gemini API key |
| 148 | +- API rate limits and timeouts |
| 149 | +- Large diffs that exceed API limits |
| 150 | +- Network connectivity issues |
| 151 | +- Invalid PR numbers or SHAs |
| 152 | + |
| 153 | +## Customization |
| 154 | + |
| 155 | +### Custom JIRA URL |
| 156 | +```yaml |
| 157 | +- uses: ./.github/actions/auto-pr-description |
| 158 | + with: |
| 159 | + jira-ticket-url-prefix: 'https://mycompany.atlassian.net/browse/' |
| 160 | + # ... other inputs |
| 161 | +``` |
| 162 | + |
| 163 | +### Using Outputs |
| 164 | +```yaml |
| 165 | +- name: Generate PR Description |
| 166 | + id: pr-desc |
| 167 | + uses: ./.github/actions/auto-pr-description |
| 168 | + with: |
| 169 | + # ... inputs |
| 170 | +
|
| 171 | +- name: Use generated description |
| 172 | + run: | |
| 173 | + echo "Generated description: ${{ steps.pr-desc.outputs.description }}" |
| 174 | + echo "Was updated: ${{ steps.pr-desc.outputs.updated }}" |
| 175 | +``` |
| 176 | + |
| 177 | +## Troubleshooting |
| 178 | + |
| 179 | +### Common Issues |
| 180 | + |
| 181 | +1. **Missing API Key**: Ensure `GEMINI_API_KEY` is set in repository secrets |
| 182 | +2. **Permission Denied**: Check that workflow has `pull-requests: write` permission |
| 183 | +3. **Large Diffs**: Very large changes might exceed API limits - consider smaller PRs |
| 184 | +4. **Rate Limits**: Gemini API has rate limits - add delays between calls if needed |
| 185 | + |
| 186 | +### Debug Mode |
| 187 | + |
| 188 | +Enable debug logging by setting: |
| 189 | +```yaml |
| 190 | +env: |
| 191 | + ACTIONS_STEP_DEBUG: true |
| 192 | +``` |
| 193 | + |
| 194 | +## License |
| 195 | + |
| 196 | +MIT License - see LICENSE file for details. |
0 commit comments