Skip to content

Commit 1eb12e1

Browse files
committed
Merge branch 'ym/fiewjfe': Add PR approve command
2 parents dfee152 + 411b7bf commit 1eb12e1

File tree

18 files changed

+3338
-42
lines changed

18 files changed

+3338
-42
lines changed

go-version/CHANGELOG_PR_APPROVE.md

Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
# Changelog - PR Approve Feature
2+
3+
## [New Feature] PR Approve Command with URL Support
4+
5+
Added `qkflow pr approve` command to streamline PR approval workflow, with full support for GitHub PR URLs!
6+
7+
### What's New
8+
9+
#### 🎯 PR Approve Command
10+
11+
Quickly approve pull requests with optional auto-merge capability.
12+
13+
**Basic Usage:**
14+
```bash
15+
# Approve PR by number (default comment: 👍)
16+
qkflow pr approve 123
17+
18+
# 🆕 Approve PR by URL (works from anywhere!)
19+
qkflow pr approve https://github.com/brain/planning-api/pull/2001
20+
21+
# 🆕 Works with /files, /commits, /checks URLs too!
22+
qkflow pr approve https://github.com/brain/planning-api/pull/2001/files
23+
24+
# Auto-detect from current branch
25+
qkflow pr approve
26+
27+
# Custom comment
28+
qkflow pr approve 123 --comment "LGTM! 🎉"
29+
qkflow pr approve 123 -c "Looks good!"
30+
31+
# 🆕 Approve by URL with comment
32+
qkflow pr approve https://github.com/owner/repo/pull/456 -c "Great work!"
33+
34+
# Approve and auto-merge (with default 👍)
35+
qkflow pr approve 123 --merge
36+
qkflow pr approve 123 -m
37+
38+
# 🆕 Approve by URL and merge
39+
qkflow pr approve https://github.com/owner/repo/pull/789 -c "Ship it! 🚀" -m
40+
```
41+
42+
### Features
43+
44+
1. **🆕 URL Support**
45+
- Approve PRs from **any repository** using GitHub URLs
46+
- No need to be in the git directory
47+
- Copy URL from browser and approve instantly
48+
- Works with: `https://github.com/owner/repo/pull/NUMBER`
49+
- **🆕 Also works with tab-specific URLs:**
50+
- `/files` - Files tab
51+
- `/commits` - Commits tab
52+
- `/checks` - Checks tab
53+
- Also supports PR numbers for local repos
54+
55+
2. **🆕 Default Comment**
56+
- All approvals use 👍 as default comment
57+
- Customize with `-c` flag if needed
58+
- No more empty approvals!
59+
60+
3. **Auto-Detection**
61+
- Automatically finds PR from current branch if no argument provided
62+
- Interactive selection if multiple PRs exist
63+
64+
4. **Smart Approval**
65+
- Approves PR on GitHub
66+
- Optional comment customization
67+
- Validates PR state before approval
68+
69+
5. **Auto-Merge (Optional)**
70+
- `--merge` flag enables automatic merging after approval
71+
- Checks if PR is mergeable before proceeding
72+
- Confirms with user before merging
73+
- Cleans up branches after successful merge
74+
75+
6. **Interactive Mode**
76+
- Asks for confirmation before merge
77+
- Lists all open PRs for selection
78+
79+
### Command Flags
80+
81+
- `-c, --comment string`: Add a comment with the approval
82+
- `-m, --merge`: Automatically merge the PR after approval
83+
- `-h, --help`: Display help information
84+
85+
### Workflow Examples
86+
87+
**Quick Approve:**
88+
```bash
89+
# In a branch with PR
90+
qkflow pr approve
91+
# → Finds PR automatically → Approves → Done!
92+
```
93+
94+
**🆕 Approve by URL (Cross-Repo):**
95+
```bash
96+
# Someone shares a PR link in Slack/Email
97+
qkflow pr approve https://github.com/brain/planning-api/pull/2001 -c "LGTM!"
98+
# → Works from anywhere! → Approves → Done!
99+
```
100+
101+
**Approve with Comment:**
102+
```bash
103+
qkflow pr approve 123 -c "Great work! Ship it! 🚀"
104+
# → Approves with comment → Done!
105+
```
106+
107+
**Approve and Merge:**
108+
```bash
109+
qkflow pr approve 123 --merge
110+
# → Approves → Checks mergeability → Confirms → Merges → Cleans up branches
111+
```
112+
113+
**🆕 Cross-Repository Workflow:**
114+
```bash
115+
# Approve multiple PRs from different repos
116+
qkflow pr approve https://github.com/team/frontend/pull/100 -c "Approved"
117+
qkflow pr approve https://github.com/team/backend/pull/200 -c "Approved"
118+
qkflow pr approve https://github.com/team/mobile/pull/300 -c "Approved"
119+
# → No directory changes needed!
120+
```
121+
122+
**Code Review Workflow:**
123+
```bash
124+
# Review someone's PR
125+
qkflow pr approve 456 -c "Reviewed and approved. Minor suggestions in comments."
126+
127+
# Or review and merge immediately
128+
qkflow pr approve 456 -c "LGTM!" --merge
129+
```
130+
131+
### Technical Details
132+
133+
#### New Functions in `internal/github/client.go`
134+
135+
- `ApprovePullRequest(owner, repo, number, body)`: Approve a PR with optional comment
136+
- `IsPRMergeable(owner, repo, number)`: Check if a PR can be merged
137+
- `ParsePRFromURL(url)`: 🆕 Parse owner, repo, and PR number from GitHub URL
138+
- `IsPRURL(s)`: 🆕 Check if a string is a GitHub PR URL
139+
140+
#### Updated Functions
141+
142+
- `pr_approve.go`: Added URL parsing support at the start of command execution
143+
- `pr_merge.go`: Added URL parsing support for consistency
144+
145+
#### New Files
146+
147+
- `cmd/qkflow/commands/pr_approve.go`: PR approve command implementation
148+
- `internal/git/operations.go`: Added `CheckoutBranch()` function
149+
150+
#### Supported URL Formats
151+
152+
```bash
153+
# Full HTTPS URL
154+
https://github.com/owner/repo/pull/123
155+
156+
# With tab suffixes (NEW!)
157+
https://github.com/brain/planning-api/pull/2001/files
158+
https://github.com/owner/repo/pull/123/commits
159+
https://github.com/owner/repo/pull/123/checks
160+
161+
# HTTP URL
162+
http://github.com/owner/repo/pull/123
163+
164+
# Without protocol
165+
github.com/owner/repo/pull/123
166+
167+
# With query parameters (parsed correctly)
168+
https://github.com/owner/repo/pull/123?comments=all
169+
https://github.com/owner/repo/pull/123/files?file-filters%5B%5D=.js
170+
171+
# With URL fragments (parsed correctly)
172+
https://github.com/owner/repo/pull/123#discussion_r123456
173+
```
174+
175+
**Pro Tip:** Copy URL from any PR tab and it just works! 🎉
176+
177+
### Integration
178+
179+
The approve command integrates seamlessly with existing PR workflow:
180+
181+
```bash
182+
# Full PR workflow
183+
qkflow pr create # Create PR
184+
qkflow pr approve 123 -m # Review and merge
185+
# Done! 🎉
186+
```
187+
188+
### Error Handling
189+
190+
- ✅ Validates PR exists and is open
191+
- ✅ Checks GitHub authentication
192+
- ✅ Verifies PR is mergeable before merge
193+
- ✅ Handles branch cleanup failures gracefully
194+
- ✅ Provides clear error messages
195+
196+
### Comparison with GitHub CLI
197+
198+
**Before (with gh):**
199+
```bash
200+
# For local repo PR
201+
gh pr review 123 --approve --body "LGTM"
202+
gh pr merge 123
203+
git checkout main
204+
git branch -D feature-branch
205+
206+
# For different repo (need to specify owner/repo)
207+
gh pr review 123 --approve --body "LGTM" --repo owner/repo
208+
gh pr merge 123 --repo owner/repo
209+
```
210+
211+
**After (with qkflow):**
212+
```bash
213+
# For local repo PR
214+
qkflow pr approve 123 -c "LGTM" -m
215+
# Everything done automatically! 🚀
216+
217+
# 🆕 For different repo (just copy the URL!)
218+
qkflow pr approve https://github.com/owner/repo/pull/123 -c "LGTM" -m
219+
# Works from anywhere! No --repo flag needed! 🎉
220+
```
221+
222+
**Key Advantages:**
223+
- ✅ URL support - no need to specify owner/repo separately
224+
- ✅ Copy-paste friendly from browser
225+
- ✅ Auto cleanup after merge
226+
- ✅ Single command for approve + merge
227+
- ✅ Works cross-repository seamlessly
228+
229+
### Future Enhancements
230+
231+
Potential improvements for future versions:
232+
233+
- [ ] Request changes workflow
234+
- [ ] Bulk approve multiple PRs
235+
- [ ] Conditional merge (wait for CI)
236+
- [ ] Custom merge strategies (squash, rebase)
237+
- [ ] Slack/notification integration
238+
239+
---
240+
241+
**Related Commands:**
242+
- `qkflow pr create` - Create a new PR
243+
- `qkflow pr merge` - Merge an existing PR
244+
- `qkflow jira read` - Read Jira issues
245+
246+
**Documentation:**
247+
- See [README.md](README.md) for general usage
248+
- See [CONTRIBUTING.md](CONTRIBUTING.md) for development guide
249+

0 commit comments

Comments
 (0)