diff options
| author | Paul Buetow <paul@buetow.org> | 2025-06-23 23:38:55 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-06-23 23:38:55 +0300 |
| commit | 42d3df9fe18663f5c6f7067b964f0b09071910e6 (patch) | |
| tree | fff4b4708115caa29c4daadc1444e02ab14c41b7 /test | |
| parent | 006724744a943aad877a92406a5e2b4d5d12acd3 (diff) | |
Add debugging features and improve error handling
- Add --test-github-token flag to validate GitHub authentication
- Improve error messages for 401 authentication failures
- Add merge conflict detection before sync attempts
- Stop sync on first error for easier debugging
- Add GitHub repo creation support for --sync and --sync-all commands
- Add detailed token loading debug output
- Create test script for GitHub token validation
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'test')
| -rwxr-xr-x | test/test_github_token.sh | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/test/test_github_token.sh b/test/test_github_token.sh new file mode 100755 index 0000000..3078f6f --- /dev/null +++ b/test/test_github_token.sh @@ -0,0 +1,86 @@ +#!/bin/bash + +# Test script to validate GitHub token +set -e + +echo "Testing GitHub token authentication..." + +# Try to load token from different sources +TOKEN="" + +# 1. Environment variable +if [ -n "$GITHUB_TOKEN" ]; then + echo "Found GITHUB_TOKEN environment variable" + TOKEN="$GITHUB_TOKEN" +fi + +# 2. Token file +if [ -z "$TOKEN" ] && [ -f ~/.gitsyncer_github_token ]; then + echo "Found ~/.gitsyncer_github_token file" + TOKEN=$(cat ~/.gitsyncer_github_token | tr -d '\n\r ') +fi + +if [ -z "$TOKEN" ]; then + echo "ERROR: No GitHub token found!" + echo "Please set GITHUB_TOKEN environment variable or create ~/.gitsyncer_github_token file" + exit 1 +fi + +echo "Token length: ${#TOKEN}" +echo "Token prefix: ${TOKEN:0:10}..." + +# Test the token +echo "" +echo "Testing token with GitHub API..." +RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}" \ + -H "Authorization: Bearer $TOKEN" \ + -H "Accept: application/vnd.github.v3+json" \ + https://api.github.com/user) + +HTTP_STATUS=$(echo "$RESPONSE" | grep HTTP_STATUS | cut -d: -f2) +BODY=$(echo "$RESPONSE" | grep -v HTTP_STATUS) + +echo "HTTP Status: $HTTP_STATUS" + +if [ "$HTTP_STATUS" = "200" ]; then + echo "SUCCESS: Token is valid!" + echo "Authenticated as: $(echo "$BODY" | jq -r .login)" +elif [ "$HTTP_STATUS" = "401" ]; then + echo "ERROR: Token is invalid (401 Unauthorized)" + echo "Response: $BODY" + echo "" + echo "Common issues:" + echo "1. Token has expired" + echo "2. Token doesn't have required scopes (need 'repo' scope)" + echo "3. Token was revoked" + echo "" + echo "To create a new token:" + echo "1. Go to https://github.com/settings/tokens" + echo "2. Click 'Generate new token (classic)'" + echo "3. Select 'repo' scope" + echo "4. Save the token to ~/.gitsyncer_github_token" +else + echo "ERROR: Unexpected status code: $HTTP_STATUS" + echo "Response: $BODY" +fi + +# Test specific repository access +echo "" +echo "Testing access to snonux/dtail repository..." +REPO_RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}" \ + -H "Authorization: Bearer $TOKEN" \ + -H "Accept: application/vnd.github.v3+json" \ + https://api.github.com/repos/snonux/dtail) + +REPO_STATUS=$(echo "$REPO_RESPONSE" | grep HTTP_STATUS | cut -d: -f2) +REPO_BODY=$(echo "$REPO_RESPONSE" | grep -v HTTP_STATUS) + +echo "Repository check status: $REPO_STATUS" +if [ "$REPO_STATUS" = "200" ]; then + echo "SUCCESS: Can access repository" +elif [ "$REPO_STATUS" = "404" ]; then + echo "Repository does not exist" +elif [ "$REPO_STATUS" = "401" ]; then + echo "ERROR: Authentication failed for repository" + echo "Response: $REPO_BODY" +fi
\ No newline at end of file |
