diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index df755d3e1680e2..7fdbed406e3527 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -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" diff --git a/.gitpod.yml b/.gitpod.yml index 2ddaf4e6090a08..1e5a6c2ff29112 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -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 diff --git a/dev/github-token.sh b/dev/github-token.sh new file mode 100755 index 00000000000000..8be07b2260e6e7 --- /dev/null +++ b/dev/github-token.sh @@ -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 diff --git a/dev/setup-github-auth.sh b/dev/setup-github-auth.sh new file mode 100755 index 00000000000000..e04591f950da56 --- /dev/null +++ b/dev/setup-github-auth.sh @@ -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"