Github企业版API:合并后删除分支

9

我目前正在使用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数据,因为我不想修改或创建任何内容,而是“仅仅”删除它。我是对的吗?还有什么可能会缺失吗?


1
现在您可以安装这个 GitHub 应用程序,它可以在 PR 合并后删除分支。https://github.com/apps/delete-merged-branch - Sebass van Boxel
1个回答

6

实际上我的解决方案是正确的。我只有一个愚蠢的问题:授权用户不是我的分支协作者,因此无法删除该分支。 在我看来,这应该被添加到文档中,因为它仅在未找到引用时才会给出404错误。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接