我们可以使用GitHub API创建提交吗?特别是v4? [英] Are we able to use GitHub API to create a commit? especially v4?

查看:123
本文介绍了我们可以使用GitHub API创建提交吗?特别是v4?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们能够使用GitHub API创建提交吗? 我们可以像使用Git命令那样使用API​​上传文件/blob吗? 特别是在API v4中?

解决方案

大概是,使用 GitHub提交API (在 GitHub应用程序 >)

您可以在" GitHub API Git数据"中看到所有序列:

  • 获取当前提交对象
  • 检索它指向的树
  • 检索树针对该特定文件路径的blob对象的内容
  • 以某种方式更改内容并发布具有该新内容的新blob对象,以恢复blob SHA
  • 发布一个新的树对象,并用新的blob SHA替换该文件路径指针,以重新获得树SHA
  • 使用当前提交SHA作为父提交并使用新树SHA创建一个新的提交对象,重新获得提交SHA.
  • 更新分支的引用以指向新的提交SHA

每个步骤都有其自己的GitHub API查询.

Are we able to use GitHub API to create a commit? Can we use API to upload a file/blob, like what we can do using Git command, especially in API v4?

解决方案

Presumably yes, using the GitHub Commits API (in the context of a GitHub application)

You can see the all sequence in "GitHub API Git Data":

  • 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

Each of those steps has its own GitHub API query.

这篇关于我们可以使用GitHub API创建提交吗?特别是v4?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆