Last active
October 4, 2019 20:21
-
-
Save agarman/f7a85564ee687d88514beb49603ca928 to your computer and use it in GitHub Desktop.
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
#!/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