-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add node IDs to insert spreadsheet (#21)
- Loading branch information
Showing
2 changed files
with
41 additions
and
6 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eou pipefail | ||
|
||
if [ ! -f islandora_workbench/input_data/rollback.csv ]; then | ||
echo "rollback.csv does not exist" | ||
exit 0 | ||
fi | ||
|
||
regex='^(https:\/\/docs\.google\.com\/spreadsheets\/d\/[a-zA-Z0-9_-]+)' | ||
if [[ "$URL" =~ $regex ]]; then | ||
URL="${BASH_REMATCH[1]}" | ||
else | ||
echo "Invalid URL" | ||
exit 1 | ||
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 -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") | ||
|
||
if [ "${STATUS}" != 200 ]; then | ||
echo "Failed to update spreadsheet with node IDs" | ||
cat /tmp/gsup.log | ||
exit 1 | ||
fi |