Skip to content

Instantly share code, notes, and snippets.

@busches
Forked from EverlastingBugstopper/rover_check_markdown.sh
Last active September 23, 2021 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save busches/811012cd1df8243efcbef71ae5c90410 to your computer and use it in GitHub Desktop.
Save busches/811012cd1df8243efcbef71ae5c90410 to your computer and use it in GitHub Desktop.
A shell script to parse the JSON output of `rover subgraph check` or `rover graph check`
#!/usr/bin/env sh
set -euo pipefail
# This script performs a subgraph check and generates a markdown file from Rover's JSON output
# Change the following line to refer to your graph ref, schema, and subgraph name
CHECK_OUTPUT=$(rover subgraph check my-graph --schema ./products.graphql --name products --output json) || true
CHECK_SUCCESS=$(echo $CHECK_OUTPUT | jq '.data.success')
if [ $CHECK_SUCCESS = "true" ]; then
echo "### $ENVIRONMENT Check Success"
echo ""
echo "#### Change Details"
echo ""
fi
CHANGES=$(echo "${CHECK_OUTPUT}" | jq '.data.changes')
if [ "$CHANGES" != "null" ]; then
CHANGE_SIZE=$(echo "${CHECK_OUTPUT}" | jq -r '.data.changes | length')
if [ "$CHANGE_SIZE" = "0" ]; then
echo "No changes"
fi
if [ "$CHANGE_SIZE" != "0" ]; then
echo "| Severity | Code | Description |"
echo "| -------- | ---- | ----------- |"
for CHANGE in $(echo "${CHECK_OUTPUT}" | jq -r '.data.changes[] | @base64'); do
_jq() {
echo ${CHANGE} | base64 -d | jq -r ${1}
}
CHANGE_SEVERITY=$(_jq '.severity')
CHANGE_CODE=$(_jq '.code')
CHANGE_DESCRIPTION=$(_jq '.description')
echo "| $CHANGE_SEVERITY | $CHANGE_CODE | $CHANGE_DESCRIPTION |"
done
fi
echo ""
fi
if [ $CHECK_SUCCESS = "false" ]; then
echo "### $ENVIRONMENT Check Failure"
echo ""
echo $CHECK_OUTPUT | jq -r '.error.message'
echo ""
echo "#### Error Details"
echo ""
for BUILD_ERROR in $(echo "${CHECK_OUTPUT}" | jq -r '.error.details.build_errors[] | @base64'); do
_jq() {
echo ${BUILD_ERROR} | base64 -d | jq -r ${1}
}
BUILD_ERROR_CODE=$(_jq '.code')
if [ $BUILD_ERROR_CODE != "null" ]; then
echo "$BUILD_ERROR_CODE: $(_jq '.message')"
else
echo "UNKNOWN: $(_jq '.message')"
fi
exit 1
done
fi
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment