diff --git a/README.md b/README.md index 21b3191..1d825c1 100644 --- a/README.md +++ b/README.md @@ -101,3 +101,37 @@ python download_and_compare.py ``` The script will automatically load your `.env` file for local testing. + +## Troubleshooting + +### Git Authentication Issues + +If you encounter authentication errors like "could not read Username", try these steps: + +1. **Verify your `.env` file** contains all required variables: + ```bash + GIT_REPO_URL=https://github.com/yourusername/yourrepo.git + GIT_USERNAME=yourusername + GIT_EMAIL=your.email@example.com + GITHUB_TOKEN=ghp_your_token_here + ``` + +2. **Test Git configuration** in the container: + ```bash + docker-compose run --rm download-compare python test_git_config.py + ``` + +3. **Check Personal Access Token permissions**: + - Ensure the token has `repo` scope + - Verify the token hasn't expired + - Check that the token belongs to the correct GitHub account + +4. **Verify repository access**: + - Ensure your GitHub account has access to the repository + - Check if the repository is private and requires authentication + +### Common Issues + +- **"No such device or address"**: Usually means Git is trying to prompt for credentials interactively +- **"Authentication failed"**: Check your Personal Access Token and repository permissions +- **"Repository not found"**: Verify the repository URL and your access permissions diff --git a/docker-compose.yml b/docker-compose.yml index 16a4508..ce14b5b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,7 +8,7 @@ services: - GIT_USERNAME=${GIT_USERNAME} - GIT_EMAIL=${GIT_EMAIL} - GIT_BRANCH=${GIT_BRANCH:-main} + - GITHUB_TOKEN=${GITHUB_TOKEN} volumes: - - ./data:/app/data - - ./.git:/app/.git + - .:/app working_dir: /app diff --git a/download_and_compare.py b/download_and_compare.py index 3a0712c..737fccf 100644 --- a/download_and_compare.py +++ b/download_and_compare.py @@ -58,13 +58,44 @@ def setup_git_repo(): return True +def verify_git_remote(): + result = subprocess.run("git remote -v", shell=True, capture_output=True, text=True, cwd="/app") + if result.returncode != 0: + print("Error checking Git remote configuration") + return False + + remote_output = result.stdout.strip() + if not remote_output: + print("No Git remote configured") + return False + + print(f"Git remote configuration: {remote_output}") + return True + def commit_and_push_changes(): if not os.path.exists("/app/.git"): return False + if not verify_git_remote(): + print("Git remote not properly configured") + return False + try: run_git_command("git add .") run_git_command("git commit -m 'Update language files'") + + github_token = os.environ.get('GITHUB_TOKEN') + if github_token: + git_repo_url = os.environ.get('GIT_REPO_URL') + git_username = os.environ.get('GIT_USERNAME') + if git_repo_url.startswith('https://'): + auth_url = git_repo_url.replace('https://', f'https://{git_username}:{github_token}@') + print(f"Setting authenticated remote URL: {auth_url}") + run_git_command(f"git remote set-url origin {auth_url}") + + print("Updated Git remote configuration:") + run_git_command("git remote -v") + run_git_command("git push origin HEAD") print("Changes committed and pushed to Git repository") return True diff --git a/test_git_config.py b/test_git_config.py new file mode 100644 index 0000000..50be94a --- /dev/null +++ b/test_git_config.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 +import os +import subprocess +from dotenv import load_dotenv + +load_dotenv() + +def test_git_config(): + print("=== Git Configuration Test ===") + print(f"Working directory: {os.getcwd()}") + print(f"Git repo exists: {os.path.exists('.git')}") + + if os.path.exists('.git'): + print("\n=== Git Remote Configuration ===") + result = subprocess.run("git remote -v", shell=True, capture_output=True, text=True) + if result.returncode == 0: + print(result.stdout) + else: + print(f"Error: {result.stderr}") + + print("\n=== Git Config ===") + subprocess.run("git config --list", shell=True) + + print("\n=== Environment Variables ===") + git_vars = ['GIT_REPO_URL', 'GIT_USERNAME', 'GIT_EMAIL', 'GITHUB_TOKEN'] + for var in git_vars: + value = os.environ.get(var) + if value: + if 'TOKEN' in var: + print(f"{var}: {value[:10]}...") + else: + print(f"{var}: {value}") + else: + print(f"{var}: Not set") + +if __name__ == "__main__": + test_git_config()