Skip to content

Commit

Permalink
Simplify claim_bosh_lite function
Browse files Browse the repository at this point in the history
- Remove dependency on git-together
- Remove dependency on direnv
- Remove dependency on lastpass CLI
- Remove Pivotal Tracker integration
- No longer prompts for Pivotal Tracker story id
- Adds Jira integration (not really; just kidding)
- No longer changes your working directory
- Fix hostname for zsh (no $HOSTNAME environment variable)
  • Loading branch information
Gerg committed May 23, 2024
1 parent e7bd827 commit e884357
Showing 1 changed file with 5 additions and 66 deletions.
71 changes: 5 additions & 66 deletions lib/claim-bosh-lite.bash
Original file line number Diff line number Diff line change
@@ -1,71 +1,12 @@
env_pool="$HOME/workspace/capi-env-pool"
readonly LASTPASS_API_KEY_LABEL='tracker_api_token'

# TODO: have this script choose Tracker ID like our "story" script
project_id=1945579;

function fetch_tracker_api_token() {
set +x
API_TOKEN=$(lpass show "$LASTPASS_API_KEY_LABEL" --notes 2> /dev/null)
return $?
}

function get_stories() {
if [ -z "$API_TOKEN" ]; then
story_json="$(curl -s -H "Content-Type: application/json" \
"https://www.pivotaltracker.com/services/v5/projects/$project_id/stories?with_state=started" | tr '**' ' ')"
else
story_json="$(curl -s -H "Content-Type: application/json" -H "X-TrackerToken: $API_TOKEN" \
"https://www.pivotaltracker.com/services/v5/projects/$project_id/stories?with_state=started" | tr '**' ' ')"
fi
echo "$story_json" | tr '\n' ' ' | jq -r '.[] | "#\(.id) \(.name)"'
echo "No story"
}

function story_selector() {
stories="$(get_stories | sed 's/#//g')"

PS3="Select a story or 'q' to quit: "
OLD_IFS=$IFS
IFS=$'\n'
select story in $stories; do
echo $story
break
done
IFS=$OLD_IFS
}

function claim_bosh_lite() {
git_authors=$(git config --get git-together.active)
if [ -z "$git_authors" ]; then
echo "please set your git authors before running this!"
echo "maybe run 'story' while you're at it."
return
fi

fetch_tracker_api_token
if [ -z "$API_TOKEN" ]; then
echo "Could not find tracker API token in your lastpass vault as a note under \"$LASTPASS_API_KEY_LABEL\""
echo -e 'Attempting to pull stories without token \n'
fi

if [ -n "$1" ] ; then
STORY=$1
shift
else
echo "Please select a story for your bosh lite"

STORY=$(story_selector)
fi

if [ -z "${STORY}" ]; then
echo "Canceling bosh lite claim. Goodbye."
git_user=$(git config --get user.name)
if [ -z "$git_user" ]; then
echo "Please set your git user before running this!"
return
fi

STORY=$(echo $STORY | cut -c 1-20)...
echo Selected story \"${STORY}\"

env_dir=$(
set -e
Expand Down Expand Up @@ -197,7 +138,7 @@ EOF
}
function commit_and_push() {
git ci --quiet --message "manually claim ${env} on ${HOSTNAME} [$STORY]" --no-verify
git ci --quiet --message "manually claim ${env} on $( hostname )" --no-verify
msg "Pushing reservation to $( basename $PWD )..."
git push --quiet
}
Expand All @@ -213,9 +154,7 @@ EOF
)

if [[ "$?" == 0 ]]; then
direnv allow "${env_dir}"
echo "Changing directory to '${env_dir}'..."
cd "${env_dir}"
echo "Use 'target_bosh $( basename $env_dir )' to set bosh environment variables."
fi
}

Expand Down

0 comments on commit e884357

Please sign in to comment.