Skip to content

[dev] Automatically authorize gh #20971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"mounts": [
"source=/usr/local/gitpod/config/,target=/usr/local/gitpod/config/,type=bind"
],
"onCreateCommand": "bash /workspace/gitpod/dev/setup-github-auth.sh",
"remoteEnv": {
"GIT_EDITOR": "code --wait",
"KUBE_EDITOR": "code --wait"
Expand Down
4 changes: 4 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ tasks:
leeway run components/local-app:install-cli
leeway run components/local-app:cli-completion
exit 0
- name: Setup GitHub CLI Auth
init: |
bash /workspace/gitpod/dev/setup-github-auth.sh
exit 0
# This task takes care of configuring your workspace so it can manage and interact
# with preview environments.
- name: Preview environment configuration
Expand Down
18 changes: 18 additions & 0 deletions dev/github-token.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# GitHub Token Helper
# Dynamically retrieves GitHub token from git credentials
# Safe to source - will not error if git credentials are unavailable

# Only set GH_TOKEN if not already set and git credential is available
if [ -z "$GH_TOKEN" ] && command -v git >/dev/null 2>&1; then
# Attempt to get token from git credentials, suppress errors
TOKEN=$(printf 'protocol=https\nhost=github.com\n' | git credential fill 2>/dev/null | awk -F= '/password/ {print $2}' 2>/dev/null)

# Only export if we got a non-empty token
if [ -n "$TOKEN" ]; then
export GH_TOKEN="$TOKEN"
fi

unset TOKEN
fi
23 changes: 23 additions & 0 deletions dev/setup-github-auth.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# GitHub CLI Authentication Setup
# Adds sourcing of GitHub token helper to shell profiles

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
GITHUB_TOKEN_HELPER="$SCRIPT_DIR/github-token.sh"

{
echo ""
echo "# GitHub token helper"
echo "source \"$GITHUB_TOKEN_HELPER\""
} >> ~/.bashrc

{
echo ""
echo "# GitHub token helper"
echo "source \"$GITHUB_TOKEN_HELPER\""
} >> ~/.zshrc

source "$GITHUB_TOKEN_HELPER"

echo "✅ GitHub CLI configured"
Loading