Matthias
Matthias

Reputation: 1354

Github enterprise API delete branch after merge

I am currently working with the Github API (on enterprise edition). After some trial and error I was able to change the status of a pull request using 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%

and also to automatically merge if verything was successfull using 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

So far so good...But I am not able to delete the branch after successfull merge. I want to use the Github API, because the Jenkins job which is controlling this, does not know a thing about the repository or its branches.

What I tried was the following:

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

It returns:

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

The URL is fine from my perspective. Opened in a browser I get some nice JSON lines. My thought was, that I will not need JSON data this time, since I don't want to patch or create something, but rather "only" delete it. Am I right? What else might miss here?

Upvotes: 9

Views: 4186

Answers (1)

Matthias
Matthias

Reputation: 1354

Actually my solution was correct. I had only one stupid problem: the authorized user was no collaborator on my fork and thus not allowed to delete the branch. IMHO this should be added to the documentation, because it says it only gives 404 error if the refs is not found.

Upvotes: 6

Related Questions