Skip to content

Commit 5bd70af

Browse files
Kamal Sai DevarapalliKamal Sai Devarapalli
authored andcommitted
feat: Add GitHub repository forking scripts
- Add script to fork all 17 open source repositories via GitHub API - Add script to set up fork remotes for local repositories - Successfully forked 17 repositories to Ricky512227 account - All local repos now have 'origin' (original) and 'fork' (your fork) remotes
1 parent 6e543f4 commit 5bd70af

File tree

2 files changed

+249
-0
lines changed

2 files changed

+249
-0
lines changed

scripts/fork_all_repos.sh

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
#!/bin/bash
2+
# Script to fork all open source repositories using GitHub API
3+
4+
set -e
5+
6+
# List of repositories to fork
7+
declare -a REPOS=(
8+
"tiangolo/fastapi"
9+
"pytest-dev/pytest"
10+
"dpkp/kafka-python"
11+
"gohugoio/hugo"
12+
"docker/cli"
13+
"helm/helm"
14+
"kubernetes/kubernetes"
15+
"segmentio/kafka-go"
16+
"vitejs/vite"
17+
"typescript-eslint/typescript-eslint"
18+
"vitest-dev/vitest"
19+
"mui/material-ui"
20+
"streamich/react-use"
21+
"Leaflet/Leaflet"
22+
"electron/electron"
23+
"cypress-io/cypress"
24+
"ToolJet/ToolJet"
25+
)
26+
27+
echo "=========================================="
28+
echo "GitHub Repository Forking Script"
29+
echo "=========================================="
30+
echo ""
31+
echo "This script will fork ${#REPOS[@]} repositories to your GitHub account."
32+
echo ""
33+
34+
# Check if token provided as argument
35+
if [ ! -z "$1" ]; then
36+
GITHUB_TOKEN="$1"
37+
fi
38+
39+
# Check if GITHUB_TOKEN is set
40+
if [ -z "$GITHUB_TOKEN" ]; then
41+
echo "⚠️ GITHUB_TOKEN environment variable is not set."
42+
echo ""
43+
echo "Usage: $0 [GITHUB_TOKEN]"
44+
echo " or: export GITHUB_TOKEN='your-token' && $0"
45+
echo ""
46+
echo "To get a token:"
47+
echo "1. Go to: https://github.com/settings/tokens"
48+
echo "2. Generate a new token (classic) with 'repo' scope"
49+
echo "3. Copy the token and run: $0 YOUR_TOKEN"
50+
echo ""
51+
read -p "Or enter your token now (will not be saved): " -s GITHUB_TOKEN
52+
echo ""
53+
if [ -z "$GITHUB_TOKEN" ]; then
54+
echo "❌ Token is required. Exiting."
55+
exit 1
56+
fi
57+
fi
58+
59+
# Get GitHub username
60+
echo "Fetching your GitHub username..."
61+
USER_RESPONSE=$(curl -s -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/user)
62+
USERNAME=$(echo "$USER_RESPONSE" | grep -o '"login":"[^"]*' | head -1 | cut -d'"' -f4)
63+
64+
# Fallback to Python if grep fails
65+
if [ -z "$USERNAME" ]; then
66+
USERNAME=$(echo "$USER_RESPONSE" | python3 -c "import sys, json; print(json.load(sys.stdin)['login'])" 2>/dev/null)
67+
fi
68+
69+
if [ -z "$USERNAME" ]; then
70+
echo "❌ Failed to authenticate. Please check your token."
71+
exit 1
72+
fi
73+
74+
echo "✅ Authenticated as: $USERNAME"
75+
echo ""
76+
read -p "Continue forking ${#REPOS[@]} repositories? (y/n) " -n 1 -r
77+
echo ""
78+
79+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
80+
echo "Cancelled."
81+
exit 1
82+
fi
83+
84+
echo ""
85+
echo "Starting to fork repositories..."
86+
echo "=========================================="
87+
88+
SUCCESS=0
89+
FAILED=0
90+
ALREADY_FORKED=0
91+
92+
for repo in "${REPOS[@]}"; do
93+
repo_name=$(basename "$repo")
94+
echo ""
95+
echo "Forking $repo..."
96+
97+
# Check if already forked
98+
response=$(curl -s -w "\n%{http_code}" -H "Authorization: token $GITHUB_TOKEN" \
99+
-H "Accept: application/vnd.github.v3+json" \
100+
"https://api.github.com/repos/$USERNAME/$repo_name")
101+
102+
http_code=$(echo "$response" | tail -n1)
103+
body=$(echo "$response" | sed '$d')
104+
105+
if [ "$http_code" == "200" ]; then
106+
echo " ⚠️ Already forked: https://github.com/$USERNAME/$repo_name"
107+
((ALREADY_FORKED++))
108+
continue
109+
fi
110+
111+
# Fork the repository
112+
response=$(curl -s -w "\n%{http_code}" -X POST \
113+
-H "Authorization: token $GITHUB_TOKEN" \
114+
-H "Accept: application/vnd.github.v3+json" \
115+
"https://api.github.com/repos/$repo/forks")
116+
117+
http_code=$(echo "$response" | tail -n1)
118+
body=$(echo "$response" | sed '$d')
119+
120+
if [ "$http_code" == "202" ] || [ "$http_code" == "200" ]; then
121+
echo " ✅ Successfully forked: https://github.com/$USERNAME/$repo_name"
122+
((SUCCESS++))
123+
elif [ "$http_code" == "403" ]; then
124+
echo " ❌ Rate limit exceeded or insufficient permissions"
125+
echo " Response: $body"
126+
((FAILED++))
127+
elif [ "$http_code" == "404" ]; then
128+
echo " ❌ Repository not found: $repo"
129+
((FAILED++))
130+
else
131+
echo " ❌ Failed (HTTP $http_code)"
132+
echo " Response: $body"
133+
((FAILED++))
134+
fi
135+
136+
# Be nice to GitHub API - small delay
137+
sleep 1
138+
done
139+
140+
echo ""
141+
echo "=========================================="
142+
echo "Forking Complete!"
143+
echo "=========================================="
144+
echo "✅ Successfully forked: $SUCCESS"
145+
echo "⚠️ Already forked: $ALREADY_FORKED"
146+
echo "❌ Failed: $FAILED"
147+
echo ""
148+
echo "View your forks at: https://github.com/$USERNAME?tab=repositories"
149+
echo ""
150+

scripts/setup_forked_repos.sh

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/bin/bash
2+
# Script to update local repos with fork remotes after forking
3+
4+
set -e
5+
6+
REPOS_DIR="/Users/alwayskamalsai/CustomProjects"
7+
8+
# Check if GITHUB_TOKEN is set to get username
9+
if [ -z "$GITHUB_TOKEN" ]; then
10+
echo "⚠️ GITHUB_TOKEN not set. Please provide your GitHub username:"
11+
read -p "GitHub Username: " GITHUB_USERNAME
12+
else
13+
USER_RESPONSE=$(curl -s -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/user)
14+
GITHUB_USERNAME=$(echo "$USER_RESPONSE" | grep -o '"login":"[^"]*' | head -1 | cut -d'"' -f4)
15+
if [ -z "$GITHUB_USERNAME" ]; then
16+
GITHUB_USERNAME=$(echo "$USER_RESPONSE" | python3 -c "import sys, json; print(json.load(sys.stdin)['login'])" 2>/dev/null)
17+
fi
18+
echo "✅ Detected GitHub username: $GITHUB_USERNAME"
19+
fi
20+
21+
if [ -z "$GITHUB_USERNAME" ]; then
22+
echo "❌ GitHub username is required. Exiting."
23+
exit 1
24+
fi
25+
26+
# List of repositories
27+
declare -a REPOS=(
28+
"fastapi"
29+
"pytest"
30+
"kafka-python"
31+
"hugo"
32+
"cli"
33+
"helm"
34+
"kubernetes"
35+
"kafka-go"
36+
"vite"
37+
"typescript-eslint"
38+
"vitest"
39+
"material-ui"
40+
"react-use"
41+
"Leaflet"
42+
"electron"
43+
"cypress"
44+
"ToolJet"
45+
)
46+
47+
echo "=========================================="
48+
echo "Setting up fork remotes for local repos"
49+
echo "=========================================="
50+
echo ""
51+
52+
cd "$REPOS_DIR"
53+
54+
for repo_name in "${REPOS[@]}"; do
55+
if [ ! -d "$repo_name" ]; then
56+
echo "⚠️ $repo_name not found, skipping..."
57+
continue
58+
fi
59+
60+
echo "Setting up $repo_name..."
61+
cd "$repo_name"
62+
63+
# Check if fork remote already exists
64+
if git remote | grep -q "^fork$"; then
65+
echo " ⚠️ Fork remote already exists, skipping..."
66+
cd ..
67+
continue
68+
fi
69+
70+
# Add fork remote
71+
git remote add fork "https://github.com/$GITHUB_USERNAME/$repo_name.git" 2>/dev/null || {
72+
echo " ⚠️ Could not add fork remote (may already exist)"
73+
}
74+
75+
# Rename origin to upstream if it points to original repo
76+
origin_url=$(git remote get-url origin 2>/dev/null || echo "")
77+
if [[ "$origin_url" == *"github.com"* ]] && [[ "$origin_url" != *"$GITHUB_USERNAME"* ]]; then
78+
echo " ℹ️ Origin points to original repo, keeping as is"
79+
echo " ✅ Added 'fork' remote pointing to your fork"
80+
else
81+
echo " ✅ Added 'fork' remote"
82+
fi
83+
84+
cd ..
85+
echo ""
86+
done
87+
88+
echo "=========================================="
89+
echo "Setup Complete!"
90+
echo "=========================================="
91+
echo ""
92+
echo "Your local repos now have:"
93+
echo " - 'origin': Original repository"
94+
echo " - 'fork': Your forked repository"
95+
echo ""
96+
echo "To push to your fork:"
97+
echo " git push fork your-branch-name"
98+
echo ""
99+

0 commit comments

Comments
 (0)