【问题标题】:How to GET private repositories using curl?如何使用 curl 获取私有存储库?
【发布时间】:2019-01-25 14:03:45
【问题描述】:

我想从 GitHub 获取我的私有存储库列表。在 GitHub REST API 文档中,它声明 the visibility as private can be supplied as parameter。但我不知道该怎么做。

我可以在命令行中使用以下命令获取我的公共存储库列表

curl -u "username:password" -X GET https://mygithuburl.com/users/username/repos

如何将visibility 参数提供给private 以获取仅包含私有存储库的列表?

【问题讨论】:

    标签: api curl github get


    【解决方案1】:

    你可以supply the parameters as regular query string arguments:

    许多 API 方法采用可选参数。对于GET请求,任何没有在路径中指定为段的参数都可以作为HTTP查询字符串参数传递:

    curl -i "https://api.github.com/repos/vmg/redcarpet/issues?state=closed"
    

    在此示例中,为路径中的 :owner:repo 参数提供了 'vmg' 和 'redcarpet' 值,同时在查询字符串中传递了 :state

    在你的情况下:

    curl \
        -u "username:password" \
        -X GET \
        https://mygithuburl.com/user/repos?visibility=private
    

    【讨论】:

    • 感谢您的回答。它无法正常工作,但确实为我指出了正确的文档。对我不起作用的是给定 url 的参数可见性。它总是给我一个空列表。在文档中提到可见性参数适用于GET user/repos 而不适用于GET /users/:username/repos。因此,如果我将我的 URL 更改为 https://mygithuburl.com/user/repos?visibility=private,那么我将获得私有的 repos 列表,我可以访问这些列表。如果您可以更改解决方案中的网址,那么我会接受它作为答案。
    猜你喜欢
    • 2016-09-04
    • 1970-01-01
    • 1970-01-01
    • 2015-10-17
    • 1970-01-01
    • 2016-05-30
    • 2023-03-20
    • 1970-01-01
    • 2023-04-07
    相关资源
    最近更新 更多