-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpr-checkout.sh
More file actions
executable file
·30 lines (25 loc) · 838 Bytes
/
pr-checkout.sh
File metadata and controls
executable file
·30 lines (25 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash
# Check if required commands are available
if ! command -v gh &> /dev/null; then
echo "Error: GitHub CLI (gh) is not installed"
exit 1
fi
if ! command -v fzf &> /dev/null; then
echo "Error: fzf is not installed"
exit 1
fi
# Fetch PRs and use fzf to select one
selected_pr=$(gh pr list --limit 100 --json number,title,headRefName,author --template \
'{{range .}}{{printf "#%v\t%v\t(branch: %v, author: %v)\n" .number .title .headRefName .author.login}}{{end}}' |
fzf --delimiter='\t' --preview 'gh pr view {1}' --preview-window=right:70% |
cut -f1)
# Check if a PR was selected
if [ -n "$selected_pr" ]; then
# Remove the '#' character from the PR number
pr_number=${selected_pr#"#"}
# Checkout the PR
gh pr checkout "$pr_number"
else
echo "No PR selected"
exit 0
fi