Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update or enhancing delete_repo.sh #1

Merged
merged 1 commit into from
Jun 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions scripts/delete_repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -23,13 +29,16 @@ auth_header="Authorization: token <PAT>"
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."