diff --git a/scripts/insert-nids.sh b/scripts/insert-nids.sh index 81da0bf..852aff7 100755 --- a/scripts/insert-nids.sh +++ b/scripts/insert-nids.sh @@ -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]}" @@ -20,8 +15,16 @@ 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")]}]') -curl -s -X POST \ - --header "Authorization: Bearer $ACCESS_TOKEN" \ - --header "Content-Type: application/json" \ - --data @<(echo "$PAYLOAD") \ - "$API_URL?valueInputOption=RAW" +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") + +if [ "${STATUS}" != 200 ]; then + echo "Failed to update spreadsheet with node IDs" + cat /tmp/gsup.log + exit 1 +fi