【问题标题】:Is there a github api endpoint to give Team access to a repo?是否有 github api 端点可以让团队访问存储库?
【发布时间】:2020-01-09 00:39:26
【问题描述】:

可以通过此处描述的 api 添加协作者:https://developer.github.com/v3/repos/collaborators/#add-user-as-a-collaborator

端点:/repos/:owner/:repo/collaborators/:username

但是如何添加团队访问权限,这绝对可以通过“设置 > 协作者和团队”中的 Web 界面实现

【问题讨论】:

    标签: github github-api


    【解决方案1】:

    实际上我发现这可以通过 api 以这种方式完成,它只需要标头和数据来指示哪些权限。:

    curl -H "Accept: application/vnd.github.v3+json" -u YourUserName:YourPersonalAccessToken -X PUT -d '{"permission":"write"}' https://api.github.com/teams/$team_id/repos/$org_name/$repo
    

    或者,在 Python 中:

    import requests, json
    
    data = json.dumps({"permission": 'read'}) . #could be 'write', etc..
    headers = {
        'content-type': 'application/json',
        'accept': 'application/vnd.github.v3+json, text/plain, */*'
    }
    auth_tuple = (username, access_token)
    url = f"https://api.github.com/teams/{team_id}/repos/{org_name}/{repo}"
    requests.put(url, auth=auth_tuple, data=data, headers=headers)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-06-05
      • 2012-06-01
      • 2013-09-09
      • 2013-08-17
      • 2017-02-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多