Skip to content

Commit 25838c2

Browse files
committed
small bug fix for the unaothorized error
1 parent 47eede8 commit 25838c2

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

β€Žcommit_checker/checker.pyβ€Ž

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,20 @@ def check_github_commits(username, token=None):
8383
response = requests.get(url, headers=headers)
8484
response.raise_for_status()
8585
except requests.RequestException as e:
86-
return f"❌ GitHub API error: {e}", []
86+
# Enhanced error handling for common GitHub API issues
87+
error_msg = str(e)
88+
89+
if "401" in error_msg:
90+
if not token:
91+
return "⚠️ GitHub API requires authentication. Run --setup to add a GitHub token for private repos, or skip GitHub checks", []
92+
else:
93+
return "❌ GitHub token expired or invalid. Run --setup to update your token", []
94+
elif "403" in error_msg:
95+
return "⚠️ GitHub API rate limit exceeded. Try again later or add a token via --setup", []
96+
elif "404" in error_msg:
97+
return f"❌ GitHub user '{username}' not found", []
98+
else:
99+
return f"❌ GitHub API error: {e}", []
87100

88101
today = get_today_date()
89102
events = response.json()

β€Žcommit_checker/cli.pyβ€Ž

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,13 +799,16 @@ def silent_output(text):
799799
output(f"❌ No active repositories found this {timeframe}.")
800800
sys.exit(0)
801801

802-
# Check GitHub commits
803-
if config.get('github_username'):
802+
# Check GitHub commits (optional)
803+
if config.get('github_username') and not config.get('skip_github', False):
804804
output(f"🌐 GitHub: @{config['github_username']}")
805805
try:
806806
error, commits = check_github_commits(config["github_username"], config.get("github_token"))
807807
if error:
808808
output(error)
809+
# If it's an auth error and no token, suggest skipping GitHub checks
810+
if "requires authentication" in error and not config.get("github_token"):
811+
output("πŸ’‘ Run --setup and choose 'Skip GitHub checks' to disable this warning")
809812
elif not commits:
810813
output("😒 No public commits found today.")
811814
silent_output("No GitHub commits today")
@@ -816,6 +819,8 @@ def silent_output(text):
816819
silent_output(f"{repo}: {count} commit(s)")
817820
except Exception as e:
818821
output(f"⚠️ GitHub check failed: {e}")
822+
elif config.get('skip_github', False):
823+
output("🌐 GitHub checks disabled (run --setup to re-enable)")
819824

820825
# Handle both old and new config formats
821826
local_paths = config.get('local_paths', [config.get('local_path', '')]) if config.get('local_path') else config.get('local_paths', [])

β€Žcommit_checker/config.pyβ€Ž

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ def load_config():
4747
100: "πŸ’Ž Century of Code! 100 days! πŸ†\nYou are unstoppable!"
4848
}
4949

50+
if "skip_github" not in config:
51+
config["skip_github"] = False # Default to checking GitHub
52+
5053
# Save updated config if any changes were made
5154
save_config(config)
5255

@@ -60,8 +63,21 @@ def save_config(data):
6063
def prompt_config():
6164
print("πŸ› οΈ First-time setup: Let's configure your commit-checker!\n")
6265

63-
username = input("πŸ‘€ GitHub username: ").strip()
64-
token = input("πŸ”‘ GitHub personal token (optional - hit Enter to skip): ").strip()
66+
print("🌐 GitHub Configuration:")
67+
print(" 1. Track GitHub commits (requires username)")
68+
print(" 2. Skip GitHub checks (local commits only)")
69+
70+
github_choice = input("πŸ“ Enter 1 or 2 (default: 1): ").strip()
71+
72+
if github_choice == "2":
73+
username = None
74+
token = None
75+
skip_github = True
76+
print("βœ… GitHub checks disabled - focusing on local commits only")
77+
else:
78+
username = input("πŸ‘€ GitHub username: ").strip()
79+
token = input("πŸ”‘ GitHub personal token (optional - hit Enter to skip): ").strip()
80+
skip_github = False
6581

6682
# Smart path detection
6783
print("\nπŸ“ Setting up local development folder...")
@@ -113,6 +129,7 @@ def prompt_config():
113129
config = {
114130
"github_username": username,
115131
"github_token": token if token else None,
132+
"skip_github": skip_github,
116133
"local_paths": paths,
117134
"repo_folder": repo_folder,
118135
"output": output_mode,

0 commit comments

Comments
Β (0)