- Pushes the code to GitHub
- Creates a pull request between the current branch and master
- Includes the JIRA story link in the pull request description
create_pull_request <story number:required> <title:optional>
Requires jq to be installed via homebrew.
Currently, this always creates a PR for the current branch, but could easily be modified to create a PR for a different branch. I figured we normally want to create a PR for whatever branch we are on, and that's one less argument to specify.
If no title is provided, it will use the branch name. If you provide a title that is more than one word, you need to put the whole string in quotes.
If you provide a story number with a pound sign, it will strip that before creating the PR.
Uses the current directory to pick which GitHub project you are pushing to. This will not work if you named your local directory something different than the project name.
This requires that you have the following variable in your fish config:
GITHUB_API_TOKENcreated and obtained on GitHub in your personal account
File in ~/.config/fish/functions/create_pull_request.fish
function create_pull_request
if test (count $argv) -eq 0
echo "Must specify a story number"
else
set -l branch (git rev-parse --abbrev-ref HEAD)
echo "Pushing and creating Pull Request for $branch..."
git push --set-upstream origin $branch
sleep 1
set -l story (string replace -a '#' '' $argv[1])
set -l title $branch
if test (count $argv) -eq 2
set title $argv[2]
end
set -l current_project (string split -r -m1 / (pwd))[2]
set -l pr_url (curl -H "Authorization: bearer $GITHUB_API_TOKEN" -X POST -d "
\
{ \
\"title\": \"$title\",
\"body\": \"**Story:** https://gsc.atlassian.net/browse/$story\",
\"head\": \"$branch\",
\"base\": \"master\"
} " https://api.github.com/repos/gospotcheck/$current_project/pulls | jq -r '.html_url')
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome $pr_url
echo ""
echo "PR created at: $pr_url"
end
end