can you delete a repo via pygithub?

1.3k views Asked by At

Can you delete a repo using pygithub? For example, as shown in this example, you can delete a file like so:

repo = g.get_repo("userName/repoName")
contents = repo.get_contents("filename.txt", ref="test")
repo.delete_file(contents.path, "remove test", contents.sha, branch="test")

Is there something analogous for deleting entire repos? If not, how can one do this via the github API?

2

There are 2 answers

4
VonC On BEST ANSWER

The pygithub documentation does include a delete() method, which calls the exact GitHub repo DELETE API delete /repos/{owner}/{repo}

So it should be possible to call that method, as in PyGithub/PyGithub tests/Repository.py

g=Github('token')
repo = self.g.get_user().get_repo("TestPyGithub")
repo.delete()
0
MastroGeppetto On

Confirm @VonC, it works.

Notice that the token must be enabled to delete a repo (tick the delete_repo box when creating the token on GitHub portal)