Skip to content

Instantly share code, notes, and snippets.

@lhoestq
Created March 30, 2023 15:47
Show Gist options
  • Save lhoestq/735ada9340475ef85af5cb3622bce498 to your computer and use it in GitHub Desktop.
Save lhoestq/735ada9340475ef85af5cb3622bce498 to your computer and use it in GitHub Desktop.
GitHub: Clone, Checkout and open VSCode to PR from its URL
function getJsonVal () {
python -c "import json,sys;sys.stdout.write(str(json.load(sys.stdin)$1))";
}
prUrl=$1
apiUrl=$(echo "$prUrl" | sed -e 's/pull/pulls/g' -e 's/github.com/api.github.com\/repos/g')
upstreamUrl=$(echo "$prUrl" | sed -re 's/\/pull\/[0-9]+/.git/g')
prData=`curl "$apiUrl"`
userName=$(echo $prData | getJsonVal "['head']['repo']['owner']['login']")
repoName=$(echo $prData | getJsonVal "['head']['repo']['name']")
repoFullName=$(echo $prData | getJsonVal "['head']['repo']['full_name']")
ref=$(echo $prData | getJsonVal "['head']['ref']")
mkdir -p $userName
cd $userName
[ ! -d $repoName ] && git clone https://github.com/$repoFullName.git
cd $repoName
packageName=$(python setup.py --name)
git remote add upstream "$upstreamUrl"
git checkout "$ref"
git pull
pip uninstall "$packageName" -y
pip install -e .
code .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment