如何使用API​​删除GitHub存储库 [英] How to delete a GitHub repo using the API

查看:81
本文介绍了如何使用API​​删除GitHub存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我熟悉GitHub API http://developer.github.com/v3/我正在尝试既可以使用Firefox的RESTClient插件,也可以使用curl命令行工具.

I am getting familiar with the GitHub API http://developer.github.com/v3/ I am trying things out both with RESTClient plugin for Firefox and with curl command line tool.

我已经找到了如何使用API​​创建存储库的方法,但是我似乎无法使用API​​删除它.

I have found out how to create a repo with the API, however I can't seem to delete it with the API.

根据此处的帮助: http://developer.github.com/v3/repos/#delete-a-repository 我必须发送这样的DELETE请求:

According to the help here: http://developer.github.com/v3/repos/#delete-a-repository I must send a DELETE request like this:

curl -X DELETE -H 'Authorization: token xxx' https://api.github.com/repos/:owner/:repo

该帮助未指定,我不确定:owner和:repo的含义-这些是名称还是ID,但是我尝试了几种组合的名称和ID,但均未成功.我收到的答复是:

The help does not specify and I am not sure what they mean by :owner and :repo - whether these are the names or the ids but I tried both names and ids in several combinations without success. What I receive as a response is:

404 Not Found

我想念什么?

推荐答案

如果您通过应用程序"页面创建了要使用的令牌,,则此令牌将具有以下范围:userpublic_reporepogist.您可以通过使用该令牌发出API请求并查看响应HTTP标头来验证这一点:

If you created the token you're using through the Applications page, then this token will have these scopes: user, public_repo, repo, gist. You can verify this by making an API request with that token and looking at the response HTTP headers:

curl -v -H 'Authorization: token xxx' https://api.github.com

寻找X-OAuth-Scopes响应标头,其中将包含范围列表:

Look for the X-OAuth-Scopes response header which will have the list of scopes:

X-OAuth-Scopes: user, public_repo, repo, gist

但是,要删除存储库,令牌必须具有delete_repo范围.

However, to delete a repository, the token needs to have the delete_repo scope.

因此,您需要一个令牌,该令牌的作用域与您的令牌不同.您可以使用 Authorizations API :

So, you need a token that has different scopes than the one you have. You can create such a token using the Authorizations API:

curl -v -u username -X POST https://api.github.com/authorizations -d '{"scopes":["delete_repo"], "note":"token with delete repo scope"}'

这将返回带有新令牌的JSON文档,您应该可以使用该令牌删除存储库:

This will return a JSON document with the new token which you should be able to use to delete a repository:

{
  "id": XXXXX,
  "url": "https://api.github.com/authorizations/XXXXX",
  "app": {
    "name": "GitHub API",
    "url": "http://developer.github.com/v3/oauth/#oauth-authorizations-api",
    "client_id": "00000000000000000000"
  },
  "token": "XXXXXX",
  "note": "token with delete repo scope",
  "note_url": null,
  "created_at": "2013-10-11T20:34:49Z",
  "updated_at": "2013-10-11T20:34:49Z",
  "scopes": [
    "delete_repo"
  ]
}

当然,以这种方式创建令牌时,您可以要求多个作用域,而不仅仅是delete_repo范围.

Of course, when creating a token this way, you can ask for multiple scopes, not just the delete_repo scope.

此外,作为一个旁注,当您没有正确的授权时,API返回404错误的原因是

Also, as a side-note, the reason why the API is returning a 404 error when you don't have the right authorization is to prevent information leakage.

这篇关于如何使用API​​删除GitHub存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆