Skip to content

Instantly share code, notes, and snippets.

@agarman
Last active October 4, 2019 20:21
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 agarman/f7a85564ee687d88514beb49603ca928 to your computer and use it in GitHub Desktop.
Save agarman/f7a85564ee687d88514beb49603ca928 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Authentication variables
USER=${BITBUCKET_USER:-`cat .user`}
SECRET=${BITBUCET_SECRET:-`cat .secret`}
ORG=${BITBUCKET_ORG:-`cat .org`}
# Setup Initial URI
PAGELEN_QS="pagelen=${PAGELEN:-100}"
FIELDS_QS="fields=${FIELDS:-next,values.full_name,values.updated_on,values.language}"
PROJECT_QS="q=project.key=%22${PROJECT:-CP}%22"
SORT_QS="sort=-updated_on"
URI="https://api.bitbucket.org/2.0/repositories/${ORG}/?${PAGELEN_QS}&${FIELDS_QS}&${PROJECT_QS}&${SORT_QS}"
# Go to a safe place
RETURN_DIR=`pwd`
WORK_DIR=`mktemp -d`
cd $WORK_DIR
n=0
while [[ ! -z ${URI} ]]
do
http -a ${USER}:${SECRET} ${URI} > ${n}.json
URI=`jq -r '.next // empty' ${n}.json`
n=$((n+1))
done
# Return from safe place
cd $RETURN_DIR
# Output relevant json
cat ${WORK_DIR}/*.json \
| jq .values \
| jq -s add \
&& rm -rf ${WORK_DIR}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment