-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_github_token.sh
More file actions
executable file
·100 lines (90 loc) · 2.98 KB
/
setup_github_token.sh
File metadata and controls
executable file
·100 lines (90 loc) · 2.98 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
#!/bin/bash
# Helper script to set up GITHUB_TOKEN for private repo automation
echo "=========================================="
echo "GitHub Token Setup for Private Repos"
echo "=========================================="
echo ""
# Check if token is already set in current session
if [ -n "$GITHUB_TOKEN" ]; then
echo "✅ GITHUB_TOKEN is already set in current session"
echo " Token: ${GITHUB_TOKEN:0:8}..."
echo ""
else
echo "❌ GITHUB_TOKEN is not set in current session"
echo ""
fi
# Check shell config files
SHELL_NAME=$(basename "$SHELL")
case "$SHELL_NAME" in
zsh)
CONFIG_FILE="$HOME/.zshrc"
;;
bash)
if [ -f "$HOME/.bash_profile" ]; then
CONFIG_FILE="$HOME/.bash_profile"
else
CONFIG_FILE="$HOME/.bashrc"
fi
;;
*)
CONFIG_FILE="$HOME/.profile"
;;
esac
echo "Detected shell: $SHELL_NAME"
echo "Config file: $CONFIG_FILE"
echo ""
# Check if token is in config file
if [ -f "$CONFIG_FILE" ] && grep -q "GITHUB_TOKEN" "$CONFIG_FILE"; then
echo "✅ GITHUB_TOKEN found in $CONFIG_FILE"
echo ""
echo "If the token isn't working, you may need to:"
echo " 1. Open a new terminal, OR"
echo " 2. Run: source $CONFIG_FILE"
else
echo "❌ GITHUB_TOKEN not found in $CONFIG_FILE"
echo ""
echo "To set up your GitHub token:"
echo ""
echo "1. Create a Personal Access Token:"
echo " → Go to: https://github.com/settings/tokens"
echo " → Click 'Generate new token (classic)'"
echo " → Select scope: 'repo' (full control of private repositories)"
echo " → Copy the generated token"
echo ""
echo "2. Add to your shell config:"
echo " → Run: echo 'export GITHUB_TOKEN=\"your_token_here\"' >> $CONFIG_FILE"
echo " → Then: source $CONFIG_FILE"
echo ""
echo "3. Or set temporarily (just for this session):"
echo " → Run: export GITHUB_TOKEN='your_token_here'"
echo ""
fi
echo "=========================================="
echo "Testing Access"
echo "=========================================="
echo ""
if [ -z "$GITHUB_TOKEN" ]; then
echo "⚠️ Cannot test - GITHUB_TOKEN not set"
echo ""
echo "After setting up, test with:"
echo " python check_private_repos.py"
else
echo "Testing GitHub API access..."
RESPONSE=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
https://api.github.com/user)
if echo "$RESPONSE" | grep -q '"login"'; then
LOGIN=$(echo "$RESPONSE" | grep '"login"' | head -1 | cut -d'"' -f4)
echo "✅ Token is valid! Authenticated as: $LOGIN"
echo ""
echo "Now run the diagnostic:"
echo " python check_private_repos.py"
else
echo "❌ Token test failed"
echo " Response: $RESPONSE"
echo ""
echo "The token may be invalid or expired."
echo "Create a new token at: https://github.com/settings/tokens"
fi
fi
echo ""
echo "=========================================="