add org= option

This commit is contained in:
Trevor Batley 2023-06-03 16:22:03 +10:00
parent a7eebc7ac7
commit 7fb53cc776

View File

@ -8,6 +8,8 @@ if [[ -z $1 ]] ; then
echo "<param file> = name of file containing parameters"
echo "<script> script to run (e.g. rename-e-smith-pkh.sh)"
echo "optional params can appear in any order"
echo " <org='organisation'> run for each repo in 'organisation' (e.g. org=smeserver)"
echo " <review> show line being executed but do NOTHING!"
echo " <noisy> show line being executed"
echo " <additional> additional params to be passed (up to 3)"
exit 0
@ -23,13 +25,20 @@ if [[ $(which $2 | grep "no $2") ]] ; then
exit 1
fi
REVIEW=
NOISY=
PROCESSORG=
EXTRAPARAMS=
for param in $3 $4 $5 $6; do
if [ $param ] ; then
case $param in
review )
REVIEW=true ;;
noisy )
NOISY=true ;;
org=* )
PROCESSORG=${$param#*=}
;;
* )
EXTRAPARAMS=$EXTRAPARAMS" "$param ;;
esac
@ -38,10 +47,38 @@ for param in $3 $4 $5 $6; do
fi
done
if [ $PROCESSORG ] ; then
# cycle through the repos in the specified organisation
# get a list of repositories in the source organisation
for page in {1..10} ; do
if [ $DEBUG ] ; then echo "getting page $page of repos from $GITHOST $1" ; fi
RESPONSE=$(curl $curlsilent -X 'GET' \
"$GITEAHOST/api/v1/orgs/$1/repos?page=$page" \
-H 'accept: application/json' \
-H "Authorization: token $ACCESSTOKEN"
)
if [ $DEBUG ] ; then echo "RESPONSE=$RESPONSE" ; fi
if [[ $RESPONSE == '[]' ]] ; then
# we have them all
break
else
echo $RESPONSE | grep -oP '(?<="name":").+?(?=")' | while read repo; do
if [[ $NOISY || $REVIEW ]] ; then echo "$2 $repo $EXTRAPARAMS" ; fi
if [[ ! $REVIEW ]] ; then
if [[ $repo ]] ; then $2 $repo $EXTRAPARAMS ; fi
fi
done
fi
done
else
# read through input file and run script using params from file
while read -r line
do
if [[ $NOISY ]] ; then echo "$2 $line $EXTRAPARAMS" ; fi
if [[ $NOISY || $REVIEW ]] ; then echo "$2 $line $EXTRAPARAMS" ; fi
if [[ ! $REVIEW ]] ; then
if [[ $line ]] ; then $2 $line $EXTRAPARAMS ; fi
fi
done < $1
fi
exit 0