Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a new repository with PyGithub

Tags:

git

python

github

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?

like image 691
ustroetz Avatar asked Feb 23 '15 13:02

ustroetz


People also ask

How do I create a new VSCode repository?

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.

How do I create a repository on GH?

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.

What is the command used to create a new repository?

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.


2 Answers

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

like image 145
MXWest Avatar answered Sep 27 '22 19:09

MXWest


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.

like image 37
edunham Avatar answered Sep 27 '22 18:09

edunham