Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
joecorall committed Dec 4, 2024
1 parent 7c29a96 commit ab3fd65
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions scripts/insert-nids.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

set -eou pipefail

if [ ! -f islandora_workbench/input_data/rollback.csv ]; then
echo "No rollback file to append to spreadsheet"
exit 0
fi

regex='^(https:\/\/docs\.google\.com\/spreadsheets\/d\/[a-zA-Z0-9_-]+)'
if [[ "$URL" =~ $regex ]]; then
URL="${BASH_REMATCH[1]}"
Expand All @@ -18,10 +13,18 @@ fi
# extract sheet ID from https://docs.google.com/spreadsheets/d/foo/edit?gid=0#gid=0
SHEET_ID=$(echo "$URL" | sed -n 's|.*/d/\(.*\)|\1|p')
API_URL="https://sheets.googleapis.com/v4/spreadsheets/$SHEET_ID/values/Sheet1!D2:append"
PAYLOAD=$(tail +4 islandora_workbench/input_data/rollback.csv | jq -nR '[inputs | {"values": [split("\n")]}]')
PAYLOAD=$(tail +4 islandora_workbench/input_data/rollback.csv | jq -R 'tonumber? | [if . == null then empty else . end]' | jq -s '{"values": [.[] | . ]}')

STATUS=$(curl -s -X POST \
-o /tmp/gsup.log \
-w '%{http_code}' \
--header "Authorization: Bearer $ACCESS_TOKEN" \
--header "Content-Type: application/json" \
--data @<(echo "$PAYLOAD") \
"$API_URL?valueInputOption=RAW")

curl -s -X POST \
--header "Authorization: Bearer $ACCESS_TOKEN" \
--header "Content-Type: application/json" \
--data @<(echo "$PAYLOAD") \
"$API_URL?valueInputOption=RAW"
if [ "${STATUS}" != 200 ]; then
echo "Failed to update spreadsheet with node IDs"
cat /tmp/gsup.log
exit 1
fi

0 comments on commit ab3fd65

Please sign in to comment.