Skip to content

Instantly share code, notes, and snippets.

@Carmer
Created February 15, 2018 23:46
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 Carmer/86d92548ccd85ebddac93376aab4e72c to your computer and use it in GitHub Desktop.
Save Carmer/86d92548ccd85ebddac93376aab4e72c to your computer and use it in GitHub Desktop.

Actions

  • 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'

Usage:

finish_testing <story number:required> <pr number:required> <release_label:required>

Requirements

Requires jq to be installed via homebrew.

Information

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment