Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/dev/github-token.sh
2486 views
1
#!/bin/bash
2
3
# GitHub Token Helper
4
# Dynamically retrieves GitHub token from git credentials
5
# Safe to source - will not error if git credentials are unavailable
6
7
# Only set GH_TOKEN if not already set and git credential is available
8
if [ -z "$GH_TOKEN" ] && command -v git >/dev/null 2>&1; then
9
# Attempt to get token from git credentials, suppress errors
10
TOKEN=$(printf 'protocol=https\nhost=github.com\n' | git credential fill 2>/dev/null | awk -F= '/password/ {print $2}' 2>/dev/null)
11
12
# Only export if we got a non-empty token
13
if [ -n "$TOKEN" ]; then
14
export GH_TOKEN="$TOKEN"
15
fi
16
17
unset TOKEN
18
fi
19
20