From e2b990642912f795dc519de34ed20f5b6e2ca417 Mon Sep 17 00:00:00 2001 From: Brian Read Date: Thu, 20 Jul 2023 20:00:36 +0100 Subject: [PATCH] Add in asseturls to options for git-list.. --- README.md | 1 + git-list-all-org-repos.sh | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7a8b67f..9d53ff2 100644 --- a/README.md +++ b/README.md @@ -166,6 +166,7 @@ optional: (in any order) * \ Show all releases * \ Show the url to use to clone this repo * \ Show the url to get the zipped contents of the repo +* \ Show the URLs of the assets associated with the release Does: diff --git a/git-list-all-org-repos.sh b/git-list-all-org-repos.sh index f7addd1..b44ed60 100755 --- a/git-list-all-org-repos.sh +++ b/git-list-all-org-repos.sh @@ -8,7 +8,7 @@ if [ ! -e $inifilename ] ; then # Not here, look at system default if [ ! -e /etc/smegit.ini ] ; then echo "No ini file found $inifilename or /etc/smegit.ini" - echo "git-list-all-org-repos.sh [draftrelease | prerelease | release | allreleases] [cloneurl] [zipurl]" + echo "git-list-all-org-repos.sh [draftrelease | prerelease | release | allreleases] [cloneurl] [zipurl] [asseturls]" exit 1 else inifilename="/etc/smegit.ini" @@ -62,6 +62,8 @@ for param in $2 $3 $4 $5 $6 $7 $8 $9 $10; do SHOWZIPURL=true ;; id ) SHOWID=true ;; + asseturls ) + SHOWASSETURLS=true ;; * ) EXTRAPARAMS=$EXTRAPARAMS" "$param ;; esac @@ -71,7 +73,7 @@ for param in $2 $3 $4 $5 $6 $7 $8 $9 $10; do done if [[ -z $1 ]] ; then - echo "git-list-all-org-repos.sh [draftrelease | prerelease | release | allreleases] [cloneurl] [zipurl]" + echo "git-list-all-org-repos.sh [draftrelease | prerelease | release | allreleases] [cloneurl] [zipurl] [asseturls]" exit 0 fi @@ -113,14 +115,18 @@ for item in $REPO_LIST ; do ID=$(echo $RESPONSE | jq -r '.[0].id') PRE=$(echo $RESPONSE | jq -r '.[0].prerelease') DRAFT=$(echo $RESPONSE | jq -r '.[0].draft') + # Get assets - json for any files uploaded + ASSETS=$(echo $RESPONSE | jq -r '.[0].assets') + # Number of assets + NUMASSETS=$(echo $ASSETS | jq length) + if [ $DEBUG ]; then echo "Assets:$NUMASSETS"; fi if [ $PRE = "true" ] ; then PRE="pre"; else PRE=""; fi if [ $DRAFT = "true" ] ; then DRAFT="draft"; else DRAFT=""; fi if [ $DEBUG ] ; then echo "pre:$PRE Draft:$DRAFT"; fi if [ $DEBUG ] ; then echo $REL; fi - if [ "$REL" ] ; then line="$line $REL $ID $PRE $DRAFT"; - else line="$line\tnone";fi + if [ "$REL" ] ; then line="$line $REL $ID $PRE $DRAFT $NUMASSETS"; fi if [ $SHOWCLONEURL ] ; then URL=$(echo $RESPONSE | jq -r '.[0].url') if [ "$URL" ] ; then line="$line $URL"; fi @@ -129,6 +135,13 @@ for item in $REPO_LIST ; do URL=$(echo $RESPONSE | jq -r '.[0].zipball_url') if [ "$URL" ] ; then line="$line $URL"; fi fi + if [[ $NUMASSETS -gt 0 && $SHOWASSETURLS ]]; then + ASSETURLS=$(echo $ASSETS | jq 'map("\(.name):\(.browser_download_url).")') + if [ $DEBUG ]; then echo "$ASSETURLS"; fi + # Turn the json into a list one on each line + ASSETURLS=$(echo $ASSETURLS | sed 's/\[//' | sed 's/\]//' | sed 's/,/\\n/g' | sed 's/\"//g') + line="$line\n$ASSETURLS"; + fi fi fi echo -e $line;