-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPRIVATE REPOS QUICK SETUP
More file actions
148 lines (127 loc) Β· 4.29 KB
/
PRIVATE REPOS QUICK SETUP
File metadata and controls
148 lines (127 loc) Β· 4.29 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/bash
# Quick setup for private repository merging
# This script handles GitHub authentication and setup
set -e
echo "π Private Repository Merge Setup"
echo "=================================="
echo ""
# Check if GITHUB_TOKEN is already set
if [ -n "$GITHUB_TOKEN" ]; then
echo "β GITHUB_TOKEN already set in environment"
else
echo "GitHub Personal Access Token required for private repos"
echo ""
echo "To create a token:"
echo "1. Go to: https://github.com/settings/tokens"
echo "2. Click 'Generate new token (classic)'"
echo "3. Select scopes: 'repo' (full control)"
echo "4. Copy the token"
echo ""
read -p "Enter your GitHub token: " -s token
echo ""
export GITHUB_TOKEN="$token"
# Save to ~/.bashrc or ~/.zshrc for persistence
read -p "Save token to shell profile? (y/N) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
if [ -f ~/.bashrc ]; then
echo "export GITHUB_TOKEN='$token'" >> ~/.bashrc
echo "β Saved to ~/.bashrc"
elif [ -f ~/.zshrc ]; then
echo "export GITHUB_TOKEN='$token'" >> ~/.zshrc
echo "β Saved to ~/.zshrc"
fi
fi
fi
# Verify token works
echo ""
echo "Verifying token..."
response=$(curl -s -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/user)
if echo "$response" | grep -q "login"; then
username=$(echo "$response" | grep -o '"login": *"[^"]*"' | sed 's/"login": *"\(.*\)"/\1/')
echo "β Token valid! Authenticated as: $username"
else
echo "β Token invalid or expired"
exit 1
fi
# Check rate limit
echo ""
echo "Checking API rate limits..."
rate_info=$(curl -s -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/rate_limit)
remaining=$(echo "$rate_info" | grep -o '"remaining": *[0-9]*' | head -1 | grep -o '[0-9]*')
limit=$(echo "$rate_info" | grep -o '"limit": *[0-9]*' | head -1 | grep -o '[0-9]*')
echo "Rate limit: $remaining / $limit remaining"
if [ "$remaining" -lt 100 ]; then
echo "β οΈ Warning: Low rate limit remaining"
echo "Consider waiting or using a different token"
fi
# Get organization access
echo ""
read -p "Enter your GitHub organization name: " org_name
echo ""
echo "Fetching accessible repositories..."
repos_response=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/orgs/$org_name/repos?per_page=1")
if echo "$repos_response" | grep -q "Not Found"; then
echo "β Organization '$org_name' not found or token lacks access"
echo ""
echo "Make sure:"
echo "1. Organization name is correct"
echo "2. Token has 'repo' scope"
echo "3. You're a member of the organization"
exit 1
fi
echo "β Access to '$org_name' confirmed"
# Generate repo list
echo ""
echo "Generating repository list..."
python3 generate-repo-list.py "$org_name" --token "$GITHUB_TOKEN"
if [ -f "repos-list.txt" ]; then
repo_count=$(grep -c "^https://" repos-list.txt || echo "0")
echo ""
echo "β Found $repo_count repositories"
echo "β Created: repos-list.txt"
fi
# Setup git credentials
echo ""
echo "Configuring git credentials..."
git config --global credential.helper store
# Create credentials file
mkdir -p ~/.git-credentials-backup
if [ -f ~/.git-credentials ]; then
cp ~/.git-credentials ~/.git-credentials-backup/backup-$(date +%s)
fi
echo "https://${GITHUB_TOKEN}@github.com" > ~/.git-credentials
chmod 600 ~/.git-credentials
echo "β Git credentials configured"
# Final instructions
echo ""
echo "======================================"
echo "β Setup complete!"
echo "======================================"
echo ""
echo "Next steps:"
echo "1. Review repos-list.txt (optional)"
echo " nano repos-list.txt"
echo ""
echo "2. Start the merge:"
echo " ./merge-repos.sh repos-list.txt"
echo ""
echo "3. Monitor progress in merge-logs/"
echo ""
echo "Note: Your token is stored in:"
echo " - Environment variable (this session)"
echo " - ~/.git-credentials (for git operations)"
# Offer to start merge
echo ""
read -p "Start merge now? (y/N) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
if [ -f "repos-list.txt" ] && [ -f "merge-repos.sh" ]; then
chmod +x merge-repos.sh
./merge-repos.sh repos-list.txt
else
echo "β Required files not found"
echo "Make sure merge-repos.sh exists"
fi
fi