Reputation: 43077
Our company shares a number of corporate code repos in a central company account; the URL is https://github.com/COMPANY_NAME. When I'm logged in with my corporate username, I can access and fork repos under this account using Github's web interface.
My github corporate account is https://github.com/mpennington-te. I routinely have to fork repos from https://github.com/COMPANY_NAME to https://github.com/mpennington-te.
Once I have forked a repo to mpennington-te, I clone https://github.com/mpennington-te/REPO_NAME.git to my laptop, do work, and then push the changes back to https://github.com/mpennington-te/REPO_NAME.git.
At this point, I submit pull requests in https://github.com/COMPANY_NAME/REPO_NAME to send my work upstream.
I am trying to automate some of this workflow, but I can't find anything in PyGithub to fork a repo from https://github.com/COMPANY_NAME/REPO_NAME to https://github.com/mpennington-te/REPO_NAME.
I looked through the PyGithub API for a way to do this and nothing jumps out...
import github
gg = github.Github('mpennington-te', "GITHUB-PERSONAL-ACCESS-TOKEN")
org = gg.get_organization('COMPANY_NAME')
repo = org.get_repo('REPO_NAME')
Question: How can I fork github repos like this with PyGithub?
Upvotes: 0
Views: 1580
Reputation: 43077
This seems to work...
>>> from github import Github
>>> gg = Github("USER_NAME", "GITHUB-PERSONAL-ACCESS-TOKEN")
>>> github_user = gg.get_user()
>>> repo = gg.get_repo('COMPANY_NAME/REPO_NAME')
>>> myfork = github_user.create_fork(repo)
>>> myfork
Repository(full_name="USER_NAME/REPO_NAME")
>>>
I found this embedded in this PyGithub issue... The API is documented, but the issue made usage more clear.
You can also delete()
the fork:
>>> myfork.delete()
>>>
Upvotes: 2