# Bitbucket PR Workflow

Use this reference after an AI agent completes a crash fix.
Only applicable if `bitbucket` is present in `crash-to-vibe.json`.

**Config values to substitute at runtime** (from `crash-to-vibe.json`):
- `[WORKSPACE]` → `bitbucket.workspace`
- `[REPO_SLUG]` → `bitbucket.repoSlug`
- `[TARGET_BRANCH]` → `bitbucket.targetBranch` (default: `develop`)
- `[REVIEWERS]` → `bitbucket.reviewers` (array)
- `[JIRA_PROJECT_KEY]` → `jira.projectKey`

---

## Create Pull Request

```
Use mcp_bitbucket_createPullRequest (or create_pull_request):

- workspace: "[WORKSPACE]"
- repository: "[REPO_SLUG]"
- title: "[JIRA_PROJECT_KEY]-[ISSUE-NUMBER] Fix: [Crash Title]"
- description: [see template below]
- source_branch: "bugfix/[JIRA_PROJECT_KEY]-[ISSUE-NUMBER]_[brief-description]"
- destination_branch: "[TARGET_BRANCH]"
- reviewers: [[REVIEWERS]]
```

---

## PR Description Template

```markdown
## 🔥 Crash Fix: [Issue Title]

### 🎫 Related Ticket
- **Jira**: [JIRA_PROJECT_KEY]-[ISSUE-NUMBER]
- **Branch**: bugfix/[JIRA_PROJECT_KEY]-[ISSUE-NUMBER]_[brief-description]

### 📊 Crash Context
- **Firebase Issue**: [Firebase Console Link]
- **Jira Ticket**: [Jira Ticket Link]
- **Crash Type**: FATAL / NON-FATAL
- **Impact**: [X] crashes affecting [Y] users ([Z]% crash-free rate)
- **Affected Versions**: [Version range]
- **Affected Devices**: [Device models and OS versions]

### 🐛 Root Cause Analysis
[AI-generated analysis of the crash cause]

**Stacktrace Summary**:
\`\`\`
[Key stacktrace lines showing crash location]
\`\`\`

### ✅ Solution Implemented
[Detailed description of the fix approach]

### 🧪 Testing Performed
- [ ] Unit tests added/updated: [Test file paths] OR "N/A - UI/View class changes only"
- [ ] Manual testing completed: [Test scenarios] — MANDATORY
- [ ] Regression testing: [Scope covered]
- [ ] Performance impact: [Memory/CPU measurements]
- [ ] Crash reproduction verified: [Steps tested]

**Unit Test Exclusion Note** (if applicable):
If unit tests skipped because changes are in UI/View classes:
- [ ] Changes are purely UI/View-related (Activity/Fragment/Adapter/ViewHolder/Custom Views)
- [ ] Manual testing documented above covers all scenarios
- [ ] UI/Espresso tests added where applicable

### 📈 Expected Impact
- Target crash-free percentage: >99.5%
- Resolution confidence: [High/Medium based on testing]

### 📝 Commit Convention
All commits follow: `[JIRA_PROJECT_KEY]-[ISSUE-NUMBER] [description]`

Example commits:
- [JIRA_PROJECT_KEY]-[ISSUE-NUMBER] fix crash on [component]
- [JIRA_PROJECT_KEY]-[ISSUE-NUMBER] add null safety checks
- [JIRA_PROJECT_KEY]-[ISSUE-NUMBER] add unit tests

### 🤖 AI Agent Information
- **Generated by**: [Claude Code / Copilot / Gemini / Codex]
- **Execution time**: [Duration]
- **Files modified**: [List of changed files]

---
⚠️ AI-Generated Fix: Please review thoroughly before merging.
```

---

## Merge Pull Request (after review)

```
Use mcp_bitbucket_mergePullRequest (or merge_pull_request):

- workspace: "[WORKSPACE]"
- repository: "[REPO_SLUG]"
- pull_request_id: [PR ID from creation response]
- merge_strategy: "squash"       # or "merge_commit" / "fast_forward"
- close_source_branch: true
```

**Note**: Review and approve the PR before merging to `[TARGET_BRANCH]`.
