mirror of
https://github.com/gitpod-io/gitpod.git
synced 2025-12-08 17:36:30 +00:00
[dev] Automatically authorize gh (#20971)
Co-authored-by: Ona <no-reply@ona.com>
This commit is contained in:
parent
7137b3a8ba
commit
6c6f43fa40
@ -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"
|
||||
|
||||
@ -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
|
||||
|
||||
18
dev/github-token.sh
Executable file
18
dev/github-token.sh
Executable file
@ -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
dev/setup-github-auth.sh
Executable file
23
dev/setup-github-auth.sh
Executable file
@ -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…
x
Reference in New Issue
Block a user