Last active
February 20, 2023 19:08
-
-
Save Collin3/be4b1051b3c60d85f1e98db29ebcc70d to your computer and use it in GitHub Desktop.
Script to convert Apollo Schema Check JSON responses to markdown for github comments.
This file contains hidden or 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
#!/usr/bin/env sh | |
set -euo pipefail | |
# 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)CHECK_SUCCESS=$(echo $CHECK_OUTPUT | jq '.data.success') | |
if [ $CHECK_SUCCESS = "true" ]; then | |
echo "### Status: :white_check_mark:" | |
echo "" | |
fi | |
if [ $CHECK_SUCCESS = "false" ]; then | |
echo "### Status: :x:" | |
echo "" | |
echo $CHECK_OUTPUT | jq -r '.error.message' | tr -d '"' | |
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 | |
done | |
fi | |
CHANGES=$(echo "${CHECK_OUTPUT}" | jq '.data.changes') | |
if [ "$CHANGES" != "null" ]; then | |
echo "<details>" | |
echo "<summary>Change Details</summary>" | |
echo "" | |
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 "</details>" | |
echo "" | |
fi | |
CHECK_URL=$(echo $CHECK_OUTPUT | jq '.data.target_url') | |
if [ $CHECK_URL != null ]; then | |
echo "" | |
echo "See more details in [Apollo Studio]($CHECK_URL)" | tr -d '"' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Found a link to this on a comment you made back in October of 2021, saved me about 4 hours of work 🙏
What would this look like if the schema had breaking changes? Would it be a BUILD_ERROR?