From dea583e0154fc949959394a9649f0b3961d4579b Mon Sep 17 00:00:00 2001 From: Bhavya Prasad <125134136+bhavya1857@users.noreply.github.com> Date: Fri, 23 Jun 2023 01:34:41 +0530 Subject: [PATCH] Update or enhancing delete_repo.sh --- scripts/delete_repo.sh | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/scripts/delete_repo.sh b/scripts/delete_repo.sh index 2cd9500..961a571 100644 --- a/scripts/delete_repo.sh +++ b/scripts/delete_repo.sh @@ -3,6 +3,12 @@ # Prompt the user to enter the repository name read -p "Enter the name of the repository to delete: " repo_name +# Check if the repo name is empty +if [[ -z $repo_name ]]; then + echo "Please enter a repository name." + exit 1 +fi + # Prompt for confirmation read -p "Are you sure you want to delete the repository '$repo_name'? This action cannot be undone. (y/n): " confirm @@ -23,13 +29,16 @@ auth_header="Authorization: token " response=$(curl -X DELETE -s -H "$auth_header" "https://api.github.com/repos/$repo_name") # Check the response status code -if [[ $(echo "$response" | jq -r '.message') == "Not Found" ]]; then - echo "Repository '$repo_name' not found." -elif [[ $(echo "$response" | jq -r '.message') == "Bad credentials" ]]; then - echo "Authentication failed. Please check your credentials." -elif [[ $(echo "$response" | jq -r '.message') == "Repository marked for deletion." ]]; then - echo "Repository '$repo_name' successfully deleted." -else +if [[ $response -ne 202 ]]; then + # The response status code is not 202, which means the deletion failed. + # Check the response body for the error message. + error_message=$(echo "$response" | jq -r '.message') echo "An error occurred while deleting the repository." - echo "Response: $response" + echo "Error message: $error_message" + exit 1 fi + +# The repository was deleted successfully. +echo "Repository '$repo_name' successfully deleted." + +