Skip to content

Instantly share code, notes, and snippets.

@AdrianTP
Created April 3, 2014 21:15
Show Gist options
  • Save AdrianTP/9963079 to your computer and use it in GitHub Desktop.
Save AdrianTP/9963079 to your computer and use it in GitHub Desktop.
Easily attach a newly-pushed fork branch to an existing issue on the original repo as a pull request -- currently does nothing with the output from the GitHub API.
#!/bin/bash
function beginIssuePull {
# Get info for pull request
echo "Please specify the following:\n"
read -e -p "GitHub username: " USERNAME
read -e -p "Issue number: " ISSUE
read -e -p "Fork branch name: " FORKBRANCH
read -e -p "Destination branch name (e.g. master): " DESTBRANCH
read -e -p "Destination repository (<original_user>/<repo_name>): " DESTREPO
# Verify info is correct
echo "\nPlease verify the following information is correct:\n\n\
GitHub username: $USERNAME\n\
Issue Number: $ISSUE\n\
Fork branch name: $USERNAME:$FORKBRANCH\n\
Destination branch name: $DESTBRANCH\n\
Destination repository: $DESTREPO\n"
echo "Is that all correct?"
select yn in "Yes" "No"; do
case $yn in
Yes ) echo "\nAlright, then. Moving on...\n"
break
;;
No ) echo "\nPlease start over. Bye!\n"
exit
;;
esac
done
# Prepare to use TFA if necessary
echo "Do you use Two-Factor Authentication?"
select yn in "Yes" "No"; do
case $yn in
Yes ) echo ""
read -e -p "Current One-Time Password: " OTP
OTPSTRING="--header 'X-GitHub-OTP: $OTP' "
break
;;
No ) OTPSTRING=""
break
;;
esac
done
CMDSTRING="curl -u $USERNAME $OTPSTRING--request POST --data '{\"issue\":\"$ISSUE\", \"head\":\"$USERNAME:$FORKBRANCH\", \"base\":\"$DESTBRANCH\"}' https://api.github.com/repos/$DESTREPO/pulls"
echo "\nRunning the following command:\n\n$CMDSTRING\n\nPrepare to enter your password..."
eval $CMDSTRING;
exit
}
#curl -u AdrianTP --header 'X-GitHub-OTP: 263878' --request POST --data '{"issue":"43", "head":"AdrianTP:issue43", "base":"master"}' https://api.github.com/repos/tedivm/Fetch/pulls
echo "Do you need to append a pull request to an existing issue?"
select yn in "Yes" "No"; do
case $yn in
No ) echo "\nOK, bye!\n"
exit
;;
Yes ) echo "\nOK, here we go!\n"
beginIssuePull
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment