github v3 API - 删除/删除存储库

发布于 2024-12-27 21:37:49 字数 1307 浏览 2 评论 0原文

在为我的应用程序设置单元测试环境时,我想以编程方式删除 github 存储库。

我已经在使用 v3 API,它似乎是最受支持的并且是前进的道路。我正在使用以下 python 行成功创建一个存储库,很好:

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?我在 http://developer.github.com/v3/repos/< 找不到删除规范/a>

我根据猜测尝试了以下代码,因为它遵循 API 模式,但它不起作用。返回 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)

我从以下位置获得了 python http DELETE 代码: 如何使用urllib2创建HTTP DELETE方法?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文