Is there any way to programmatically (using libraries like PyGithub
, GitPython
or dulwich
) load any file right into MyRepo.wiki.git
repository? Using Python, of course.
I can easily upload a file right into MyRepo.git
repository with a help of PyGithub
, but, unfortunately, this library has no API or ways to work with MyRepo.wiki.git
repository.
Here is how I can upload a file to MyRepo.git
repository:
github_repo = github_account.get_user().get_repo('MyRepo')
head_ref = gh_repo.get_git_ref("heads/%s" % github_branch)
latest_commit = gh_repo.get_git_commit(head_ref.object.sha)
base_tree = latest_commit.tree
new_tree = gh_repo.create_git_tree(
[github.InputGitTreeElement(
path="test.txt",
mode='100755' if github_executable else '100644',
type='blob',
content="test"
)],
base_tree)
new_commit = gh_repo.create_git_commit(
message="test commit message",
parents=[latest_commit],
tree=new_tree)
head_ref.edit(sha=new_commit.sha, force=False)
So, how can I do the same but with MyRepo.wiki.git
repository? If you can provide an example using PyGithub library - it would be really great.
P.S. Can I do this using Gollum API?
P.P.S. Has not anybody worked with *.wiki.git
using any kind of python library? I do not believe :(
P.P.P.S. If I was not clear enough: I DO NOT want to create a local repository in any way. All I want to modify repo structure on-the-fly - just how my example does. But with *.wiki.git repository.
Thank you!
You can't access a github wiki via the github web API, which PyGithub uses exclusivly. But you can point your GitPython at the git URL of the wiki. After that you can access files in this git repo as with any other repo.
Edited
As you pointed out, that you restrict yourself not to create a local clone of the git repository I recommend following:
Read the code in https://github.com/github/gollum/blob/master/lib/gollum/frontend/app.rb which defines maybe all of the external HTTP interface.
A nicely wrapper around it for Python doesn't exist. But when you do make one (partially) than I recommend using a REST client library like mentioned here: https://stackoverflow.com/questions/2176561/which-is-the-best-python-library-to-make-rest-request-like-put-get-delete-pos
If you now think, that your restriction could be changed:
The documentation provides a good tutorial covering everything one needs with a little git knowledge. It boils down to:
import git
repo = git.Repo.clone_from("[email protected]:user/project.wiki.git", "some-path")
repo.index.add(["your-new-file"])
repo.index.commit("your message to the world")
repo.remotes.origin.push()
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