parse historyResponse

This commit is contained in:
felixlohmeier 2022-11-08 13:10:10 +00:00
parent 51c15ea0e0
commit c7d5273b1c
2 changed files with 14 additions and 12 deletions

14
orcli
View File

@ -889,9 +889,9 @@ orcli_transform_command() {
# read each operation into one line # read each operation into one line
mapfile -t jsonlines < <(jq -c '.[]' "${files[$i]}") mapfile -t jsonlines < <(jq -c '.[]' "${files[$i]}")
for line in "${jsonlines[@]}"; do for line in "${jsonlines[@]}"; do
# parse operation into curl options # parse one line/operation into array
declare -A data="($(echo "$line" | jq -r 'to_entries | map("[\(.key)]=" + @sh "\(.value|tostring)") | .[]'))" declare -A data="($(echo "$line" | jq -r 'to_entries | map("[\(.key)]=" + @sh "\(.value|tostring)") | .[]'))"
# map operation name to command # map operation names to command endpoints
com="${data[op]#core/}" com="${data[op]#core/}"
if [[ $com == "row-reorder" ]]; then com="reorder-rows"; fi if [[ $com == "row-reorder" ]]; then com="reorder-rows"; fi
unset "data[op]" unset "data[op]"
@ -900,17 +900,17 @@ orcli_transform_command() {
unset "data[engineConfig]" unset "data[engineConfig]"
# drop description # drop description
unset "data[description]" unset "data[description]"
# prepare curl options
mapfile -t curloptions < <(for K in "${!data[@]}"; do mapfile -t curloptions < <(for K in "${!data[@]}"; do
echo "--data" echo "--data"
echo "$K=${data[$K]}" echo "$K=${data[$K]}"
done) done)
# get project id and csrf token; post data to it's individual endpoint # get project id and csrf token; post data to it's individual endpoint
set -x if response="$(curl -fs --data "project=$(get_id "${args[project]}")" "${curloptions[@]}" "${OPENREFINE_URL}/command/core/${com}$(get_csrf)")"; then
# debug: remove -fs log "applied ${com} to ${args[project]}" "Response: $(jq '.historyEntry.description' <<< "$response")"
if ! curl --data "project=$(get_id "${args[project]}")" "${curloptions[@]}" "${OPENREFINE_URL}/command/core/${com}$(get_csrf)"; then else
error "applying ${op} from ${files[$i]} failed!" error "applying ${com} from ${files[$i]} to ${args[project]} failed!"
fi fi
set +x
unset data unset data
done done
done done

View File

@ -31,9 +31,9 @@ for i in "${!files[@]}"; do
# read each operation into one line # read each operation into one line
mapfile -t jsonlines < <(jq -c '.[]' "${files[$i]}") mapfile -t jsonlines < <(jq -c '.[]' "${files[$i]}")
for line in "${jsonlines[@]}"; do for line in "${jsonlines[@]}"; do
# parse operation into curl options # parse one line/operation into array
declare -A data="($(echo "$line" | jq -r 'to_entries | map("[\(.key)]=" + @sh "\(.value|tostring)") | .[]'))" declare -A data="($(echo "$line" | jq -r 'to_entries | map("[\(.key)]=" + @sh "\(.value|tostring)") | .[]'))"
# map operation name to command # map operation names to command endpoints
com="${data[op]#core/}" com="${data[op]#core/}"
if [[ $com == "row-reorder" ]]; then com="reorder-rows"; fi if [[ $com == "row-reorder" ]]; then com="reorder-rows"; fi
unset "data[op]" unset "data[op]"
@ -42,14 +42,16 @@ for i in "${!files[@]}"; do
unset "data[engineConfig]" unset "data[engineConfig]"
# drop description # drop description
unset "data[description]" unset "data[description]"
# prepare curl options
mapfile -t curloptions < <(for K in "${!data[@]}"; do mapfile -t curloptions < <(for K in "${!data[@]}"; do
echo "--data" echo "--data"
echo "$K=${data[$K]}" echo "$K=${data[$K]}"
done) done)
# get project id and csrf token; post data to it's individual endpoint # get project id and csrf token; post data to it's individual endpoint
# debug: remove -fs option temporarily if response="$(curl -fs --data "project=$(get_id "${args[project]}")" "${curloptions[@]}" "${OPENREFINE_URL}/command/core/${com}$(get_csrf)")"; then
if ! curl --data "project=$(get_id "${args[project]}")" "${curloptions[@]}" "${OPENREFINE_URL}/command/core/${com}$(get_csrf)"; then log "applied ${com} to ${args[project]}" "Response: $(jq '.historyEntry.description' <<< "$response")"
error "applying ${op} from ${files[$i]} failed!" else
error "applying ${com} from ${files[$i]} to ${args[project]} failed!"
fi fi
unset data unset data
done done