Skip to content

Instantly share code, notes, and snippets.

@s1lvester
Forked from sarimarton/fix_github_copilot.sh
Created April 6, 2023 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s1lvester/380c316b8439bf29884518bcc19c3a76 to your computer and use it in GitHub Desktop.
Save s1lvester/380c316b8439bf29884518bcc19c3a76 to your computer and use it in GitHub Desktop.
Fix Github Copilot in dealing with self-signed certificates
# Fix Github Co-pilot self-signed cert problem
# See: https://github.com/orgs/community/discussions/8866#discussioncomment-3517831
# The script is modified to handle .vscode-server too (in WSL2)
fix_github_copilot() {
patch_ext() {
_VSCODEDIR=$1
_EXTENSIONSPATH="$HOME/${_VSCODEDIR}/extensions"
_RE=$2
_NAME=$3
_COPILOTDIR=$(ls "${_EXTENSIONSPATH}" | grep -E "${_RE}" | sort -V | tail -n1)
_EXTENSIONFILEPATH="${_EXTENSIONSPATH}/${_COPILOTDIR}/dist/extension.js"
if [[ -f "$_EXTENSIONFILEPATH" ]]; then
echo "Found $_NAME extension, applying 'rejectUnauthorized' patches to '$_EXTENSIONFILEPATH'"
perl -pi -e 's/,rejectUnauthorized:[a-z]}(?!})/,rejectUnauthorized:false}/g' ${_EXTENSIONFILEPATH}
sed -i.bak 's/d={...l,/d={...l,rejectUnauthorized:false,/g' ${_EXTENSIONFILEPATH}
fi
}
do_fix() {
if [[ -d "$HOME/$1" ]]; then
patch_ext "$1" "github.copilot-[0-9].*" "Copilot"
patch_ext "$1" "github.copilot-nightly-[0-9].*" "Copilot Nightly"
patch_ext "$1" "github.copilot-labs-[0-9].*" "Copilot Labs"
fi
}
do_fix ".vscode"
do_fix ".vscode-server"
unset -f do_fix
unset -f patch_ext
}
fix_github_copilot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment