【发布时间】:2023-03-10 08:35:01
【问题描述】:
我正在尝试通过 Github API 使用 PHP 构建 PHP 函数以在 Github 存储库中创建和更新文件。
PHP 文件是从标准共享主机帐户运行的。因此,使用依赖于安装 Composer 或其他库的框架对我来说不是一个选择。例如,这个https://github.com/KnpLabs/php-github-api 不是一个选项。
到目前为止
我已经设法使用 PHP 访问和列出文件,使用此处提供的信息:
Github API List all repositories and repo's content
我使用了第 2 和第 6 答案的组合(第 2 以 这里是一个很好的方式,只是使用 curl。 由肉食者和第 6 答案与 当你说“显示回购及其内容” Ivan Zuzak)。
两者都清楚地列出了列出文件和获取内容所需的代码和步骤(感谢@flesheater 和@Ivan Zuzak)
我为此搜索了帮助或解决方案。到目前为止,我还没有找到任何使用 PHP 的示例,无论是否正常工作。
Git API 文档
Git 数据 API 信息 (https://developer.github.com/v3/git/) 表示:
举个例子,如果你想对你的 存储库,你会:
get the current commit object retrieve the tree it points to retrieve the content of the blob object that tree has for that particular file path change the content somehow and post a new blob object with that new content, getting a blob SHA back post a new tree object with that file path pointer replaced with your new blob SHA getting a tree SHA back create a new commit object with the current commit SHA as the parent and the new tree SHA, getting a commit SHA back update the reference of your branch to point to the new commit SHA
但是没有代码示例说明这是如何完成的,我不确定“提交”是否是我需要的(如果我理解正确,这不是创建文件,只是创建内容)。
Git 存储库 API 信息 (https://developer.github.com/v3/repos/contents/#create-a-file):
“创建文件”部分显示了执行此操作的方法,但没有代码示例。我知道如何或是否可以在语法上使用它。
相似主题
在我看来,由于问题或答案,没有人提供足够的清晰度或信息来提供解决方案。因此我不认为这是重复的。
How to create a commit and push into repo with GitHub API v3?
这个帖子有两个答案。一个只是 Github API 的链接,没有给出代码示例。另一个是 Pearl 解决方案(看起来),但使用的是单独的 Pearlframework。因此,即使尝试转换显示的 Pearl 也是不切实际的。
How to create github Repository and upload files from PHP?
答案只重复另一个线程,即应该创建一个 blob。但这只是通过 Github API 实际创建/更新文件所需的一切的开始。该线程有一个 Python 示例,但该示例需要一个单独的 Pearl 框架。
这是链接到的线程。用户回答了一个不太清楚的问题,但没有任何细节或清晰度。
【问题讨论】:
标签: php github github-api