Last active
June 20, 2024 14:50
-
-
Save xalvarez/e7297ca58e28617b6158663c7238a992 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 | |
function print_help { | |
echo "usage: $APPLICATION_NAME <organization> <repository>" | |
echo " organization Name of a GitHub organization." | |
echo " team Name of a GitHub repository." | |
exit 1 | |
} | |
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 "$2" ]]; then | |
print_help | |
fi | |
echo "Retrieving all analysis results in $ORGANIZATION/$REPOSITORY" | |
ANALYSIS_IDS=$(gh api -X GET "repos/$ORGANIZATION/$REPOSITORY/code-scanning/analyses?per_page=100&direction=asc" --paginate --jq='.[] | select(.deletable==true) | .id') | |
for analysis_id in ${ANALYSIS_IDS} | |
do | |
delete_analysis_result "$analysis_id" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment