- Adds 'ready_for_release' label to the pull request
- Merges the PR
- Adds the Merge and Branch to Tracker story
- Add release_label to Tracker
- Sets tracker story state to 'Accepted'
finish_testing <story number:required> <pr number:required> <release_label:required>
Requires jq
to be installed via homebrew.
This will automate the steps needed to complete a story after it has been tested.
function finish_testing
if test (count $argv) -lt 3
echo "Must specify 3 arguments..."
echo "1.) Pivotal Tracker Story number. ex. '#12345678'"
echo "2.) The PR number. ex '1005'"
echo "3.) The release marker for Pivotal Tracker '20180215_release'"
else
set -l branch (git rev-parse --abbrev-ref HEAD)
set -l current_project (string split -r -m1 / (pwd))[2]
set -l story (string replace -a '#' '' $argv[1])
set -l pr_number $argv[2]
set -l release_label $argv[3]
echo 'Attempting to add label ready_for_release to Pull Request...'
set -l merge_url (curl -H "Authorization: bearer $GITHUB_API_TOKEN" -d '["ready_for_release"]' -X POST "https://api.github.com/repos/gospotcheck/$current_project/issues/$pr_number/labels" | jq -r '.html_url')
echo "Attempting to merge $branch with master..."
set -l merge_url "https://github.com/gospotcheck/$current_project/pull/$pr_number"
curl -H "Authorization: bearer $GITHUB_API_TOKEN" -X PUT "https://api.github.com/repos/gospotcheck/$current_project/pulls/$pr_number/merge" | jq -r '.html_url'
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome $merge_url
echo "Adding comment to Pivotal Tracker..."
set -l merge_comment "Merged: $merge_url"
set -l branch_comment "Branch: $branch"
set -l comment_response (curl -X POST -H "X-TrackerToken: $PIVOTAL_TRACKER_API_TOKEN" -H "Content-Type: application/json" -d '{"text": "'$merge_comment'\n'$branch_comment'"}' "https://www.pivotaltracker.com/services/v5/projects/$TRACKER_PROJECT_ID/stories/$story/comments" | jq -r ".kind")
echo "Adding label(s) to Pivotal Tracker"
curl -X PUT -H "X-TrackerToken: $PIVOTAL_TRACKER_API_TOKEN" -H "Content-Type: application/json" -d '{"labels":[{"name": "'$release_label'"}]}' "https://www.pivotaltracker.com/services/v5/projects/$TRACKER_PROJECT_ID/stories/$story" | jq -r ".kind"
echo "Accepting Pivotal Tracker story"
curl -X PUT -H "X-TrackerToken: $PIVOTAL_TRACKER_API_TOKEN" -H "Content-Type: application/json" -d '{"current_state": "accepted"}' "https://www.pivotaltracker.com/services/v5/projects/$TRACKER_PROJECT_ID/stories/$story" | jq -r ".kind"
echo "DONE!"
end
end