sahil-sagwekar2652 / GitHub-Automation-scripts

Bash and Python scripts to automate your Git & GitHub workflow. Made by using only standard python libraries.
https://sahil-sagwekar2652.github.io/GitHub-Automation-scripts/
MIT License
52 stars 64 forks source link

enhancing- scripts/delete_repo.sh #111

Closed bhavya1857 closed 1 year ago

bhavya1857 commented 1 year ago

Issue Description: I just want to suggest a few suggestions in the code:

Use a more descriptive variable name for confirm. Something like delete_confirmation would be more clear. Add a comment explaining what the auth_header variable is for. Use a try/catch block to handle errors. This will help to prevent the script from crashing if there is an error. Add a check to make sure that the repo_name variable is not empty. Use the jq command to parse the response from the GitHub API. This will make it easier to check the status code and the message. Add an error message if the jq command fails.

Expected Behavior:

If you implement the changes to the script that I suggested, the following will happen:

The script will prompt the user to enter the name of the repository to delete. The script will check if the repo name is empty. If it is, the script will exit with an error message. The script will prompt the user for confirmation of the deletion. If the user confirms, the script will proceed with the deletion. The script will authenticate the user using a personal access token (PAT). The script will delete the repository using the GitHub API. The script will check the response status code. If the status code is 202, the deletion was successful. Otherwise, the script will exit with an error message.

Current Behavior:

The original code could encounter the following error messages:

Repository '$repo_name' not found. This error message would be displayed if the repository that the user entered does not exist. Bad credentials. Please check your credentials. This error message would be displayed if the user's personal access token is incorrect. An error occurred while deleting the repository. This error message would be displayed if there is an error while deleting the repository. The specific error message would depend on the cause of the error. The script does not currently handle any of these errors. If an error occurs, the script will simply exit without providing any information about the error. This could make it difficult to troubleshoot the problem

Labels: enhancement

sahil-sagwekar2652 commented 1 year ago

Can you elaborate more on the 'jq' command which you have talked about? I'm not aware of it. :)

bhavya1857 commented 1 year ago

sure The jq command to parse the response is: jq '.status_code, .message' This will extract the status code and message from the JSON response and print them to the console.

I have done the PR on this too.

sahil-sagwekar2652 commented 1 year ago

Please link the issue to the said PR.

bhavya1857 commented 1 year ago

113 is the PR name, its with the title- updating or enhancing delete_repo.sh

bhavya1857 commented 1 year ago

@sahil-sagwekar2652 you found the PR number right? Just let me know if u did

sahil-sagwekar2652 commented 1 year ago

I have explained how to link a PR to an issue in the contributing.md file. I think you should read that.