【问题标题】:Getting a user's organization repositories in the GitHub API在 GitHub API 中获取用户的组织仓库
【发布时间】:2013-10-03 20:19:31
【问题描述】:

我们在 Stack Overflow Careers 上使用 GitHub API 来引入用户的存储库。我们尚未成功引入属于组织的用户存储库。

例如,wycats 是 jQuery 项目的贡献者。然而通过 API 的querying his repositories 并没有表明这一点——jQuery repojQuery organization 所有。

知道 wycats 是 jQuery 存储库的贡献者的 API 调用是什么?正确答案将采用 URL 的形式,该 URL 返回给定用户名的组织存储库列表。如果它需要多个电话,那很好。

谢谢!

【问题讨论】:

    标签: github github-api


    【解决方案1】:

    我想这就是你要找的。​​p>

    Checking Organization Membership

    /user/show/:user/organizations [GET]
    

    https://github.com/api/v2/json/user/show/wycats/organizations

    列出任何组织的所有公共存储库

    /organizations/:org/public_repositories [GET]
    

    https://github.com/api/v2/json/organizations/jquery/public_repositories

    【讨论】:

    • 这就是你所追求的。你是对的,组织“拥有”回购。 “给定用户名的组织存储库”确实没有上下文……组织有存储库,组织也有用户。除此之外,这只是用户拥有什么权限的问题,据我所知,公共 API 不提供这些权限。
    • 感谢您的保证 - 我没有使用 GitHub API 的经验,但我可以阅读 API 文档。
    • 谢谢,我希望做得比文档提供的更好。有一个 /organizations/repositories 路线承诺做我正在寻找的东西,但它对我来说出错了。
    • @Matt 我认为这条路线的问题在于它只显示“您可以访问”的组织(无论这意味着什么),并且无法指定除您自己之外的用户。
    【解决方案2】:

    您可以使用github api 进行身份验证。我在没有先检索令牌的情况下出错。这是工作代码(只需使用您自己的组织和用户名:-))

    organization="write-here-the-organization"
    githubuser="your-github-user"
    token=`curl -i -u ${githubuser}  -d '{"scopes": ["repo"]}' https://api.github.com/authorizations | grep token | cut -d\" -f 4`
    curl -i -H "Authorization: token ${token}" https://api.github.com/orgs/${organization}/repos 
    

    作为上述结果,您将获得一个包含所有存储库及其信息的长 json。你可以从这里继续。

    在我的情况下,我只想要 ssh 路径,所以我将在循环中克隆所有路径,所以我这样做了

    curl -i -H "Authorization: token ${token}" https://api.github.com/orgs/${organization}/repos | grep "ssh_url" | cut -d\" -f 4
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-26
      • 2023-04-07
      • 1970-01-01
      • 2016-02-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多