xxxxxxxxxx
import requests
# API endpoint to delete the repository
url = 'https://api.github.com/repos/username/repository'
# Personal access token for authentication
headers = {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN'
}
# Send a DELETE request to the API
response = requests.delete(url, headers=headers)
# Check the response status code
if response.status_code == 204:
print("Repository deleted successfully!")
else:
print("Error deleting the repository. Status code:", response.status_code)
xxxxxxxxxx
#step by step Process
>> Login github
>> Profile # right side of the page profile icon
>> Your repositories
>> Select repositories
>> Goto Settings # repository level settings
>> Delete this repository
>> Please type <repository name> to confirm.
xxxxxxxxxx
const axios = require('axios');
// Function to delete a GitHub repository
async function deleteRepository(repoOwner, repoName, authToken) {
try {
const url = `https://api.github.com/repos/${repoOwner}/${repoName}`;
const authHeaderValue = `token ${authToken}`;
// Using Axios library to send a DELETE request
const response = await axios.delete(url, {
headers: {
Authorization: authHeaderValue,
Accept: 'application/vnd.github.v3+json', // Using GitHub API v3
},
});
if (response.status === 204) {
console.log(`Repository '${repoOwner}/${repoName}' deleted successfully.`);
} else {
console.log(`Repository deletion failed with status: ${response.status}`);
}
} catch (error) {
console.error('Error deleting repository:', error);
}
}
// Example usage:
const owner = 'your-github-username';
const repo = 'your-repo-name';
const token = 'your-personal-access-token';
deleteRepository(owner, repo, token);
xxxxxxxxxx
import requests
def delete_github_repo(username, access_token, repo_name):
url = f"https://api.github.com/repos/{username}/{repo_name}"
headers = {
"Authorization": f"token {access_token}"
}
response = requests.delete(url, headers=headers)
if response.status_code == 204:
print(f"Repository {repo_name} deleted successfully.")
elif response.status_code == 404:
print(f"Repository {repo_name} not found.")
else:
print(f"Failed to delete repository {repo_name}. Error: {response.content.decode()}")
xxxxxxxxxx
import requests
username = "YourGitHubUsername"
repository = "YourRepositoryName"
token = "YourAccessToken" # Generate a personal access token with "delete_repo" scope from your GitHub account settings
# Construct the API endpoint URL
api_url = f"https://api.github.com/repos/{username}/{repository}"
# Send a DELETE request to the API endpoint with the access token as a header
headers = {
"Authorization": f"Token {token}"
}
response = requests.delete(api_url, headers=headers)
# Check the response status to see if the repository was deleted successfully
if response.status_code == 204:
print("Repository deleted successfully.")
else:
print("Failed to delete repository.")
print(response.text)
xxxxxxxxxx
import shutil
# Specify the path to the repository
repository_path = '/path/to/your/repository'
# Delete the repository directory
shutil.rmtree(repository_path)
xxxxxxxxxx
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# Open GitHub repository page
driver = webdriver.Chrome()
driver.get("https://github.com/your-username/your-repository")
# Click on Settings tab
settings_tab = driver.find_element(By.XPATH, "//a[contains(@href, '/settings')]")
settings_tab.click()
# Scroll to Danger Zone section
driver.execute_script("arguments[0].scrollIntoView(true);", WebDriverWait(driver, 10).until(EC.element_to_be_clickable(
(By.XPATH, "//h2[text()='Danger Zone']"))))
# Click on Delete this repository button
delete_button = driver.find_element(By.XPATH, "//button[@data-dialog-id='delete_repo_confirm']")
delete_button.click()
# Confirm repository name and delete
confirm_name_input = driver.find_element(By.XPATH, "//input[@name='verify']")
confirm_name_input.send_keys("your-repository-name")
submit_button = driver.find_element(By.XPATH, "//form[@class='js-normalize-submit']//button[text()='I understand the consequences, delete this repository']")
submit_button.click()
# Close the browser
driver.quit()