-
-
Save ctcampbell/a73bf1fa482e12f385f3dcc8e22ef823 to your computer and use it in GitHub Desktop.
Remove all GitHub code scanning analysis results for a given repository and organization
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 -e | |
# Remove all GitHub code scanning analysis results for a given repository and organization. | |
# | |
# The script assumes that github-cli (https://github.com/cli/cli) is installed and that authentication has already been | |
# performed. You might still need to request additional permissions as follows: | |
# | |
# gh auth refresh -h github.com -s admin:repo_hook | |
# gh auth refresh -h github.com -s delete_repo | |
APPLICATION_NAME=$0 | |
ORGANIZATION=$1 | |
REPOSITORY=$2 | |
TOOL_NAME=$3 | |
function print_help { | |
echo "usage: $APPLICATION_NAME <organization> <repository> <tool_name>" | |
echo " organization Name of a GitHub organization." | |
echo " repo Name of a GitHub repository." | |
echo " tool_name Name of the tool analyses to delete." | |
exit 1 | |
} | |
function get_analysis_ids { | |
ANALYSIS_IDS=$(gh api -X GET "repos/$ORGANIZATION/$REPOSITORY/code-scanning/analyses?tool_name=$TOOL_NAME&per_page=100&direction=asc" --paginate --jq='.[] | select(.deletable==true) | .id') | |
} | |
function delete_analysis_result { | |
analysis_id=$1 | |
echo "Deleting analysis result $analysis_id" | |
gh api -X DELETE "repos/$ORGANIZATION/$REPOSITORY/code-scanning/analyses/$analysis_id?confirm_delete=true" --silent | |
} | |
if [[ -z "$3" ]]; then | |
print_help | |
fi | |
echo "Retrieving all analysis results in $ORGANIZATION/$REPOSITORY" | |
while get_analysis_ids; do | |
for analysis_id in ${ANALYSIS_IDS} | |
do | |
delete_analysis_result "$analysis_id" | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment