Github API create commit

纵然是瞬间 提交于 2019-12-22 10:17:58

问题


I need help with Github API,

I need commit new version of file through api, I'm trying to achieve this by sending post request to

https://api.github.com/repos/:username/:repo:/git/commits/

with data

{
    "login": "username",
    "token": "auth_token",
    "parent_commit": "sha",
    "message": "commit message.",
    "content": {
        "path": "full/path",
        "mode": "edit",
        "data": "new content"
    }
}

But it fails with result - not found.

Have anyone idea where to send this request and if this format is right?

(Format is inspired by - http://swanson.github.com/blog/2011/07/23/digging-around-the-github-api-take-2.html)

Thank you!


回答1:


I puzzled over this one too!

Committing new content is actually a multi-step process, using their low level and powerful API.

Here is a gist I made to share one solution. Note that a few things are hard coded, like the branch name "master".

Please feel free to fork and improve the gist, or let me know if you're having trouble getting this to run.




回答2:


Note that since May 2013, you have a CRUD API available:

That includes a file update API

{
  "message": "my commit message",
  "committer": {
    "name": "Scott Chacon",
    "email": "schacon@gmail.com"
  },
  "content": "bXkgdXBkYXRlZCBmaWxlIGNvbnRlbnRz",
  "sha": "329688480d39049927147c162b9d2deaf885005f"
}

(with content being the updated file content, Base64 encoded.)



来源:https://stackoverflow.com/questions/11301989/github-api-create-commit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!