Created
November 18, 2024 19:50
-
-
Save se7enack/14b52d2c18fa8736227a148fcb97c7b5 to your computer and use it in GitHub Desktop.
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
import requests | |
access_token_file = "/Users/sburke/.ghp" | |
repo_name = "test123" | |
base_url = "https://api.github.com" | |
def create_repo(access_token, repo_name, repo_descr=None): | |
url = f"{base_url}/user/repos" | |
headers = { | |
"Authorization": f"token {access_token}", | |
} | |
data = { | |
"name": repo_name, | |
"description": repo_descr, | |
} | |
response = requests.post(url, headers=headers, json=data) | |
if response.status_code == 201: | |
repo_data = response.json() | |
return repo_data | |
else: | |
return None | |
with open(access_token_file, 'r') as file: | |
access_token = file.read().strip() | |
repo_descr = f"{repo_name} repo created using GitHub's API." | |
new_repo = create_repo(access_token, repo_name, repo_descr) | |
if new_repo: | |
print(f"The new public repo ({repo_name}) was created successfully!") | |
else: | |
print(f"Failed to create new public repo: {repo_name}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment