Skip to content

Fall back to unauthenticated GitHub access when stored token has bad credentials#831

Open
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-github-commits-fetch-error
Open

Fall back to unauthenticated GitHub access when stored token has bad credentials#831
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-github-commits-fetch-error

Conversation

Copy link
Contributor

Copilot AI commented Mar 20, 2026

The GitHub token in Secret Manager has expired/been revoked, causing get_latest_github_commits() to fail with 401 Bad credentials and return None.

Since the repo is public, unauthenticated access is sufficient. The fix catches BadCredentialsException and retries without auth rather than failing entirely.

Changes

  • app.py: Import BadCredentialsException from github
  • app.py: Wrap g.get_repo() to catch BadCredentialsException and fall back to an unauthenticated gh() client
try:
    repo = g.get_repo("EastsidePreparatorySchool/epschedule")
except BadCredentialsException:
    logging.warning("GitHub token has bad credentials, falling back to unauthenticated access")
    repo = gh().get_repo("EastsidePreparatorySchool/epschedule")

Action required: Rotate the gh_token secret in Secret Manager to restore authenticated access and the associated higher rate limits.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

… bad credentials

Co-authored-by: codingses <149913839+codingses@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix error fetching GitHub commits due to bad credentials Fall back to unauthenticated GitHub access when stored token has bad credentials Mar 20, 2026
Copilot AI requested a review from codingses March 20, 2026 16:06
Copy link
Collaborator

@codingses codingses left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@codingses codingses marked this pull request as ready for review March 20, 2026 16:38
@codingses codingses enabled auto-merge (squash) March 20, 2026 16:38
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves resilience of get_latest_github_commits() by handling revoked/expired GitHub tokens from Secret Manager and falling back to unauthenticated GitHub API access (sufficient for this public repository), instead of failing and returning None.

Changes:

  • Import BadCredentialsException from github.
  • Catch BadCredentialsException from the authenticated get_repo() call and retry with an unauthenticated GitHub client.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants