-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgit-pr-helper.sh
More file actions
executable file
·120 lines (93 loc) · 3.31 KB
/
git-pr-helper.sh
File metadata and controls
executable file
·120 lines (93 loc) · 3.31 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
set -e # Exit on error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo -e "${GREEN}=== Git PR Helper Script ===${NC}"
# 1. Prerequisites Check
echo -e "\n${YELLOW}[1/6] Checking prerequisites...${NC}"
# Check if gh CLI is installed
if ! command -v gh &> /dev/null; then
echo -e "${RED}Error: GitHub CLI (gh) is not installed.${NC}"
echo "Please install it from: https://cli.github.com/"
exit 1
fi
# Check if in git repo
if ! git rev-parse --git-dir &> /dev/null; then
echo -e "${RED}Error: Not in a git repository.${NC}"
exit 1
fi
echo -e "${GREEN}✓ Prerequisites check passed${NC}"
# 2. Clean Build Artifacts
echo -e "\n${YELLOW}[2/6] Cleaning build artifacts...${NC}"
# Remove __pycache__ directories
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
echo " Removed __pycache__ directories"
# Remove *.egg-info directories
find . -type d -name "*.egg-info" -exec rm -rf {} + 2>/dev/null || true
echo " Removed *.egg-info directories"
# Remove build directory
if [ -d "build" ]; then
rm -rf build/
echo " Removed build/ directory"
fi
echo -e "${GREEN}✓ Build artifacts cleaned${NC}"
# 3. Stage Changes
echo -e "\n${YELLOW}[3/6] Staging changes...${NC}"
git add -A
echo -e "${GREEN}✓ Changes staged${NC}"
# Show what will be committed
echo -e "\n${YELLOW}Changes to be committed:${NC}"
git status --short
# 4. Commit Changes
echo -e "\n${YELLOW}[4/6] Creating commit...${NC}"
# Get commit message
read -p "Enter commit message (or press Enter for default): " commit_msg
# Default commit message based on branch name and changes
if [ -z "$commit_msg" ]; then
branch_name=$(git branch --show-current)
commit_msg="Update changes on $branch_name"
fi
git commit -m "$commit_msg"
echo -e "${GREEN}✓ Commit created: $commit_msg${NC}"
# 5. Push to Remote
echo -e "\n${YELLOW}[5/6] Pushing to remote...${NC}"
current_branch=$(git branch --show-current)
git push -u origin "$current_branch"
echo -e "${GREEN}✓ Pushed to origin/$current_branch${NC}"
# 6. Create Pull Request
echo -e "\n${YELLOW}[6/6] Creating pull request...${NC}"
# Check if PR already exists
if gh pr view --json url &> /dev/null; then
echo -e "${YELLOW}A pull request already exists for this branch.${NC}"
read -p "Open existing PR in browser? (y/n): " open_pr
if [ "$open_pr" = "y" ] || [ "$open_pr" = "Y" ]; then
gh pr view --web
fi
else
# Get PR title (default to commit message)
read -p "Enter PR title (or press Enter to use commit message): " pr_title
if [ -z "$pr_title" ]; then
pr_title="$commit_msg"
fi
# Get PR description
read -p "Enter PR description (optional, press Enter to skip): " pr_body
# Create the PR
if [ -z "$pr_body" ]; then
gh pr create --title "$pr_title" --body "Changes: $pr_title"
else
gh pr create --title "$pr_title" --body "$pr_body"
fi
echo -e "${GREEN}✓ Pull request created${NC}"
# Open PR in browser
read -p "Open PR in browser? (y/n): " open_pr
if [ "$open_pr" = "y" ] || [ "$open_pr" = "Y" ]; then
gh pr view --web
fi
fi
echo -e "\n${GREEN}=== Workflow Complete ===${NC}"
echo -e "${YELLOW}Next steps:${NC}"
echo " 1. Review the pull request on GitHub"
echo " 2. Merge the pull request on GitHub when ready"