mirror of
https://github.com/acedanger/finance.git
synced 2025-12-05 22:50:12 -08:00
trying several things to correct the PAT inclusion. things are broken and I'm trying to resolve that.
This commit is contained in:
@@ -68,7 +68,7 @@
|
||||
"command": "bash",
|
||||
"args": [
|
||||
"-c",
|
||||
"source ${containerWorkspaceFolder}/.devcontainer/library-scripts/load-env.sh && docker run -i --rm -e GITHUB_PERSONAL_ACCESS_TOKEN=\"$GITHUB_PERSONAL_ACCESS_TOKEN\" ghcr.io/github/github-mcp-server"
|
||||
"source ${containerWorkspaceFolder}/.devcontainer/library-scripts/load-env.sh && if [ -n \"${GITHUB_PERSONAL_ACCESS_TOKEN}\" ]; then docker run -i --rm -e GITHUB_PERSONAL_ACCESS_TOKEN=\"${GITHUB_PERSONAL_ACCESS_TOKEN}\" ghcr.io/github/github-mcp-server; else echo 'Error: GITHUB_PERSONAL_ACCESS_TOKEN not set' >&2; exit 1; fi"
|
||||
],
|
||||
"env": {}
|
||||
}
|
||||
|
||||
@@ -8,37 +8,53 @@ set -o errtrace
|
||||
set -o nounset
|
||||
# Catch the error in case mysqldump fails (but gzip succeeds) in `mysqldump |gzip`
|
||||
set -o pipefail
|
||||
# Turn on traces, useful while debugging but commented out by default
|
||||
# set -o xtrace
|
||||
|
||||
# Load environment variables from .env file
|
||||
readonly ENV_FILE="/workspaces/finance/.devcontainer/.env"
|
||||
# Try to get PAT from environment first
|
||||
pat="${GITHUB_PERSONAL_ACCESS_TOKEN:-}"
|
||||
|
||||
if [[ ! -f "${ENV_FILE}" ]]; then
|
||||
echo >&2 "Error: Environment file not found: ${ENV_FILE}"
|
||||
exit 1
|
||||
# If not in environment, try to get from GitHub CLI
|
||||
if [[ -z "${pat}" ]] || [[ "${#pat}" -lt 30 ]]; then
|
||||
if command -v gh &> /dev/null; then
|
||||
if gh auth status &> /dev/null; then
|
||||
pat=$(gh auth token)
|
||||
if [[ -n "${pat}" ]] && [[ "${#pat}" -gt 30 ]]; then
|
||||
# Save the token to .env file if it's valid
|
||||
ENV_FILE="/workspaces/finance/.devcontainer/.env"
|
||||
echo "# GitHub Finance Devcontainer Configuration" > "${ENV_FILE}"
|
||||
echo "GITHUB_PERSONAL_ACCESS_TOKEN=${pat}" >> "${ENV_FILE}"
|
||||
chmod 600 "${ENV_FILE}"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Loading environment variables from ${ENV_FILE}"
|
||||
# If still not found, try .env file
|
||||
if [[ -z "${pat}" ]] || [[ "${#pat}" -lt 30 ]]; then
|
||||
ENV_FILE="/workspaces/finance/.devcontainer/.env"
|
||||
if [[ -f "${ENV_FILE}" ]]; then
|
||||
# Try to extract PAT from .env file
|
||||
env_pat=$(grep -E '^GITHUB_PERSONAL_ACCESS_TOKEN=.+' "${ENV_FILE}" | cut -d'=' -f2-)
|
||||
|
||||
# Read the env file line by line to handle special characters correctly
|
||||
while IFS= read -r line || [[ -n "${line}" ]]; do
|
||||
# Skip comments and empty lines
|
||||
[[ "${line}" =~ ^[[:space:]]*# ]] && continue
|
||||
[[ -z "${line}" ]] && continue
|
||||
# Clean up the extracted PAT
|
||||
env_pat="${env_pat#\"}"
|
||||
env_pat="${env_pat%\"}"
|
||||
env_pat="${env_pat#\'}"
|
||||
env_pat="${env_pat%\'}"
|
||||
env_pat="${env_pat%%[[:space:]]}"
|
||||
env_pat="${env_pat##[[:space:]]}"
|
||||
|
||||
# Export the variable
|
||||
if [[ "${line}" =~ ^[[:alpha:]][[:alnum:]_]*= ]]; then
|
||||
export "${line}"
|
||||
else
|
||||
echo >&2 "Warning: Skipping invalid line: ${line}"
|
||||
if [[ -n "${env_pat}" ]] && [[ "${#env_pat}" -gt 30 ]]; then
|
||||
pat="${env_pat}"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done < "${ENV_FILE}"
|
||||
|
||||
# Verify PAT loaded correctly (without printing the actual token)
|
||||
if [[ -n "${GITHUB_PERSONAL_ACCESS_TOKEN:-}" ]]; then
|
||||
# Export the PAT if valid
|
||||
if [[ -n "${pat}" ]] && [[ "${#pat}" -gt 30 ]]; then
|
||||
export GITHUB_PERSONAL_ACCESS_TOKEN="${pat}"
|
||||
echo "GitHub Personal Access Token loaded successfully"
|
||||
exit 0
|
||||
else
|
||||
echo >&2 "ERROR: GitHub Personal Access Token not loaded"
|
||||
echo >&2 "ERROR: Could not find valid GitHub Personal Access Token"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user