forked from xai-org/grok-1
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
062eed9
commit 8eba722
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import requests | ||
|
||
def create_repo(token, name, private=True): | ||
""" Create a GitHub repository via the GitHub API. """ | ||
url = "https://api.github.com/user/repos" | ||
headers = { | ||
"Authorization": f"token {token}", | ||
"Accept": "application/vnd.github.v3+json" | ||
} | ||
data = { | ||
"name": name, | ||
"private": private, | ||
"auto_init": True, # Automatically create an initial commit with empty README | ||
} | ||
response = requests.post(url, headers=headers, json=data) | ||
if response.status_code == 201: | ||
print(f"Repository {name} created successfully.") | ||
return response.json() | ||
else: | ||
print(f"Failed to create repository: {response.content}") | ||
return None | ||
|
||
# Usage | ||
# Replace 'your_github_token_here' with your actual GitHub personal access token | ||
create_repo('your_github_token_here', 'NewRepositoryName') |