有没有办法以编程的方式(使用PyGithub,GitPython或dulwich)之类的库将任何文件加载到MyRepo.wiki.git存储库中?当然,使用Python。
在PyGithub,的帮助下,我可以轻松地将文件上传到MyRepo.git存储库中,但不幸的是,这个库没有API或使用MyRepo.wiki.git存储库的方法。
下面是如何将文件上载到MyRepo.git存储库的方法:
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)那么,-如果你能提供一个使用PyGithub库的例子,那就太好了。
我能用Gollum API做这个吗?
没有人使用过任何类型的python库来处理*.wiki.git吗?我不相信:
如果我不够清楚:我不想以任何方式创建本地存储库。我只想在飞行中修改回购结构--就像我的例子一样。但是有了*.wiki.git存储库。
谢谢!
发布于 2013-02-03 15:22:10
您不能通过PyGithub独家使用的github访问github。但是您可以将GitPython指向wiki的git。在此之后,您可以访问此git中的文件,就像任何其他回购一样。
编辑的
正如您所指出的,您限制自己不创建git存储库的本地克隆,我建议如下:
阅读https://github.com/github/gollum/blob/master/lib/gollum/frontend/app.rb中的代码,它可能定义了所有外部HTTP接口。
Python的良好包装器并不存在。但是,当您做一个(部分)时,我建议您使用REST客户机库,如这里所提到的:https://stackoverflow.com/questions/2176561/which-is-the-best-python-library-to-make-rest-request-like-put-get-delete-pos
如果您现在认为可以更改您的限制:
文档提供了一个很好的教程,用一点git知识涵盖了您所需要的一切。归根结底是:
import git
repo = git.Repo.clone_from("git@github.com:user/project.wiki.git", "some-path")
repo.index.add(["your-new-file"])
repo.index.commit("your message to the world")
repo.remotes.origin.push()https://stackoverflow.com/questions/14587632
复制相似问题