Created
April 9, 2019 17:14
-
-
Save aaronfay/91e78c6532789509a2fa54e89e316f38 to your computer and use it in GitHub Desktop.
Pull Suite Results from the Ghost Inspector API and write them to CSV
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
#!/bin/bash | |
# set up our variables | |
GI_API_KEY='<your-api-key-here>' | |
GI_SUITE_ID='<your-suite-id-here>' | |
# maintain where we are in the data with these variables | |
MORE_RESULTS=1 | |
COUNT=50 | |
OFFSET=0 | |
# adjust the headers here for your CSV | |
echo 'ID,Name,Passing,Count Passing,Count Failing,Count Unknown,Date Execution Finished' > results.csv | |
# request and loop over some results | |
while [ $MORE_RESULTS -gt 0 ]; do | |
# make a request to get the next set of results | |
results=$(curl -s "https://api.ghostinspector.com/v1/suites/$GI_SUITE_ID/results/?apiKey=$GI_API_KEY&count=$COUNT&offset=$OFFSET") | |
# if there is data in the response, there may be more results | |
MORE_RESULTS=$(echo $results | jq '.data | length') | |
# adjust our offset with the count to grab the next results | |
OFFSET=$((OFFSET + COUNT)) | |
# transform the JSON data array into individual lines and loop over them | |
echo $results | jq -c '.data[]' | while read LINE; do | |
# adjust the fields here to match what you wish to write out, note they must match the headers above | |
echo $LINE | jq -rc '. | [._id, .name, .passing, .countPassing, .countFailing, .countUnknown, .dateExecutionFinished] | @csv' >> results.csv | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment