【问题标题】:Github enterprise API delete branch after mergeGithub 企业 API 合并后删除分支
【发布时间】:2017-11-23 12:47:52
【问题描述】:

我目前正在使用 Github API(企业版)。经过反复试验,我能够使用 curl -X POST 更改拉取请求的状态:

curl -u <token>:x-oauth-basic --header "Content-Type: application/json" -X POST --data "{\"state\":\"success\",\"target_url\":\"%BUILD_URL%\",\"description\":\"my description\",\"context\":\"continuous-integration/mycontext\"}" http://<server>/api/v3/repos/<myuserid>/<myreponame>/statuses/%COMMIT_SHA%

如果使用 curl -X PUT 成功,也会自动合并:

curl -u <token>:x-oauth-basic --header "Content-Type: application/json" -X PUT --data "{\"state\":\"merged\",\"commit_title\":\"automatic merge\",\"commit_message\":\"automatic merge\",\"sha\":\"%COMMIT_SHA%\",\"merge_method\":\"merge\"}" http://<server>/api/v3/repos/<myuserid>/<myreponame>/pulls/%PullRequest%/merge

到目前为止一切顺利...但是我无法在成功合并后删除分支。我想使用 Github API,因为控制它的 Jenkins 作业对存储库或其分支一无所知。

我尝试了以下内容:

curl -u <token>:x-oauth-basic -X DELETE http://<server>/api/v3/repos/<myuserid>/<myreponame>/git/refs/heads/develop

返回:

{
  "message": "Not Found",
  "documentation_url": "https://developer.github.com/enterprise/2.11/v3/git/refs/#update-a-reference"
}

从我的角度来看,该 URL 很好。在浏览器中打开,我得到了一些不错的 JSON 行。 我的想法是,这次我不需要 JSON 数据,因为我不想修补或创建某些东西,而是“只”删除它。我对吗?这里还可能遗漏什么?

【问题讨论】:

标签: git curl github github-api


【解决方案1】:

其实我的解决方案是正确的。我只有一个愚蠢的问题:授权用户不是我 fork 的合作者,因此不允许删除分支。 恕我直言,这应该添加到文档中,因为它说如果找不到参考,它只会给出 404 错误。

【讨论】:

    猜你喜欢
    • 2013-09-13
    • 2020-02-29
    • 1970-01-01
    • 2012-08-26
    • 2020-10-19
    • 2012-06-01
    • 2021-12-11
    • 2011-10-30
    • 1970-01-01
    相关资源
    最近更新 更多