How can I create a new repository with PyGithub on Github?
In particular I like to know how to use the create_repo
method? How do I generate a AuthenticatedUser
?
Create a Github Repository From VSCodePress Ctrl + Shift + P (on Windows), or Command + Shift + P (on Mac). Select whether to Publish a private or a public repository. Stage and commit the changes from the source control panel. Publish and push the changes.
To create a repository interactively, use gh repo create with no arguments. To create a remote repository non-interactively, supply the repository name and one of --public , --private , or --internal . Pass --clone to clone the new repository locally.
The git init command creates a new Git repository. It can be used to convert an existing, unversioned project to a Git repository or initialize a new, empty repository. Most other Git commands are not available outside of an initialized repository, so this is usually the first command you'll run in a new project.
I stumbled across this question trying to figure out how to coax PyGithub into creating a Repository within an Organization and thought it would be relevant here.
g = Github(token)
organization = g.get_organization("org-name")
organization.create_repo(
name,
allow_rebase_merge=True,
auto_init=False,
description=description,
has_issues=True,
has_projects=False,
has_wiki=False,
private=True,
)
The full set of keyword arguments may be found here: https://developer.github.com/v3/repos/#input
I stumbled onto this question when trying to figure out how to create an AuthenticatedUser object. Turns out you get a NamedUser when you pass any argument to get_user, and if you give it no arguments, you get the AuthenticatedUser corresponding to the creds you used when creating the Github object.
As a minimal example, the following:
from github import Github
g = Github("my GitHub API token")
user = g.get_user('myname')
print user
authed = g.get_user()
print authed
yields
<github.NamedUser.NamedUser object at 0x7f95d5eeed10>
<github.AuthenticatedUser.AuthenticatedUser object at 0x7f95d5684410>
Once you have an AuthenticatedUser object, you can call CreateRepo as explained in the docs that you linked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With