Created
August 16, 2018 09:38
-
-
Save leapingfrogs/c19dd4c9c71685ae615b5cf2db38945e to your computer and use it in GitHub Desktop.
Basic bash script to create an all projects workspace in Pivotal Tracker.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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).