4

I would like to programmatically delete a github repo, when setting up a unit test environment for my application.

I am already using the v3 API, which seems to be most supported and the path going forward. I am using the following python lines to successfully CREATE a repo, just fine:

import urllib2, base64 createData = '{\"name\": \"UnitTest-SubModules\", \"description\": \"This is a Fake repo used for testing\"}' request = urllib2.Request("https://api.github.com/user/repos") base64string = base64.encodestring('%s:%s' % ('user', 'pass')).replace('\n', '') request.add_header("Authorization", "Basic %s" % base64string) result = urllib2.urlopen(request, data=createData) 

How do I set this up to DELETE a repo? I cannot find the specification for deleting at http://developer.github.com/v3/repos/

I have tried, based off guestimating, the following code, as it follows the API pattern, but it did not work. Came back with urllib2.HTTPError: HTTP Error 404: Not Found

request = urllib2.Request("https://api.github.com/repos/nyeates/UnitTest-SubModules") base64string = base64.encodestring('%s:%s' % ('user', 'pass')).replace('\n', '') request.add_header("Authorization", "Basic %s" % base64string) request.get_method = lambda: 'DELETE' result = urllib2.urlopen(request) 

I got the python http DELETE code from: How to make HTTP DELETE method using urllib2?

2
  • I don't think the v3 API allows you to delete repos. We've run into this issue as well and are waiting for an official response from them. Commented Apr 17, 2012 at 13:51
  • Also, this would be far more elegant written using requests. Commented Feb 5, 2013 at 15:54

1 Answer 1

4

The DELETE method is now here: http://developer.github.com/v3/repos/#delete-a-repository

Sign up to request clarification or add additional context in comments.

2 Comments

Is this also true for organisations? I have admin rights (eg I'm an owner) I tried to do this in curl for testing. 'curl -H "Authorization: token blarblar" -X DELETE -i api.github.com/repos/OrgName/Test5'; but it says 404 not found. The auth is working since it says my limit is 4980 and not 50odd. If I do it without the -X DELETE it returns all the details about the repo. so I have URL correct.
You probably haven't set the scope for your token. By default the scope of tokens don't allow to delete repositories.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.