3

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?

Mathew
  • 1,116
  • 5
  • 27
  • 59
  • Does this answer your question? [How to delete a GitHub repo using the API](https://stackoverflow.com/questions/19319516/how-to-delete-a-github-repo-using-the-api) – Nico Haase Oct 16 '20 at 06:39
  • Ideally I would like to use the python library pygithub, however if this is not possible then yes, this would suffice. If you could demonstrate that this is not possible using pygithub then I'll accept this an answer. – Mathew Oct 16 '20 at 06:49

1 Answers1

3

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()
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks, as an additin `g=Github('token') – Timo Jun 10 '21 at 07:53
  • 1
    @Timo Good point, thank you. I have edited the answer accordingly. – VonC Jun 10 '21 at 09:14
  • Do you know why in linux there is my vscode workspace folder named with a 13 digit number: `/home/tk/.config/Code/Workspaces/1619293380488`. New question? – Timo Jun 10 '21 at 18:09
  • @Timo that would be a new question indeed (while I am looking into it). Do mention your vscode version. – VonC Jun 10 '21 at 18:51