Skip to content

Instantly share code, notes, and snippets.

@leapingfrogs
Created August 16, 2018 09:38
Show Gist options
  • Save leapingfrogs/c19dd4c9c71685ae615b5cf2db38945e to your computer and use it in GitHub Desktop.
Save leapingfrogs/c19dd4c9c71685ae615b5cf2db38945e to your computer and use it in GitHub Desktop.
Basic bash script to create an all projects workspace in Pivotal Tracker.
#!/usr/bin/env bash
set -euo pipefail
# This script requires:
# jq (brew install jq)
# pivotal tracker token (See API Token on https://www.pivotaltracker.com/profile while logged in)
promptValue() {
read -rp "$1"": " val
echo "${val}"
}
getProjectIds() {
project_ids=$(curl -sX GET -H "X-TrackerToken: $1" "https://www.pivotaltracker.com/services/v5/projects" | jq '.[] | .id' | tr '\n' ',' | sed 's/,$//') || false
echo "${project_ids}"
}
createWorkspace() {
token=${1:?Token not supplied}
name=${2:?Workspace name not supplied}
projects=${3:?Project id list not supplied}
curl -X POST -H "X-TrackerToken: ${token}" -H "Content-Type: application/json" -d "{\"name\": \"${name}\", \"project_ids\": [${projects}]}" "https://www.pivotaltracker.com/services/v5/my/workspaces"
}
command -v jq >/dev/null 2>&1 || { echo >&2 "I require jq but it's not installed. You can install it via \`brew install jq\`. Aborting."; exit 1; }
PT_TOKEN=${PIVOTAL_API_TOKEN:-$(promptValue "Please enter your PT API Token")}
echo "Retrieving list of projects..."
projectIds=$(getProjectIds "${PT_TOKEN}")
if [ -z "${projectIds}" ]
then
echo "API Token may be invalid, failed to call pivotal"
else
echo "Creating your workspace..."
createWorkspace "${PT_TOKEN}" "All Projects" "${projectIds}"
fi
@leapingfrogs
Copy link
Author

Download, save and then run . create_workspace.sh from the Terminal.

Note: You will need to have jq installed (brew install jq) and your Pivotal API Token (copy it from your profile page, creating it first if necessary).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment