是否有 github api 端点可让团队访问存储库?
Is there a github api endpoint to give Team access to a repo?
可以通过 api 添加协作者,如下所述:https://developer.github.com/v3/repos/collaborators/#add-user-as-a-collaborator
端点:/repos/:owner/:repo/collaborators/:username
但是如何添加团队访问权限,这绝对可以通过 "Settings > Collaborators & Teams"
中的 Web 界面实现
实际上我发现这可以通过 api 以这种方式完成,它只需要 headers 和指示什么权限的数据。:
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)
可以通过 api 添加协作者,如下所述:https://developer.github.com/v3/repos/collaborators/#add-user-as-a-collaborator
端点:/repos/:owner/:repo/collaborators/:username
但是如何添加团队访问权限,这绝对可以通过 "Settings > Collaborators & Teams"
中的 Web 界面实现实际上我发现这可以通过 api 以这种方式完成,它只需要 headers 和指示什么权限的数据。:
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)