curl - 将 Org 中的 GitHub 团队添加到 REPO

标签 curl github github-api

我正在尝试执行 Curl 请求以将团队添加到这样的 repo 中:

curl --user $USERNAME:$TOKEN -X PUT -d "" "https://api.github.com/teams/<team name>/repos/<org>/$REPONAME"

我的变量是正确的,但我不断收到一条消息未找到错误。有人对如何进行有建议吗?

最佳答案

来自 here 的正确端点是 :

PUT /teams/:id/repos/:org/:repo

您必须指定团队 ID 而不是团队名称

以下将获得 Developers 的团队 ID团队并执行 PUT请求将 repo 添加到指定团队:
username=your_user
password=your_password

org=your_org
repo=your_repo

team=Developers

teamid=$(curl -s --user $username:$password "https://api.github.com/orgs/$org/teams" | \
    jq --arg team "$team" '.[] | select(.name==$team) | .id')

curl -v --user $username:$password -d "" -X PUT "https://api.github.com/teams/$teamid/repos/$org/$repo"

注意这个例子的 JSON 解析是用 jq 完成的

还可以考虑使用 Personal access token带范围 admin:org而不是您的用户名/密码(然后使用 -H "Authorization: Token $TOKEN" )

关于curl - 将 Org 中的 GitHub 团队添加到 REPO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43498035/

相关文章:

html - 在网站中嵌入 Github 贡献图

php - 如何获取相同的firebug "network"部分信息?

git - 我的新 Github 页面没有显示

ruby - 使用命令行公开 Git 存储库的可见性

git - 无法 promise 在 Windows 10 (GnuPG) 上使用 gpg2 进行签名

python - 需要一些帮助以python身份验证github API

javascript - 公共(public) Github 页面站点上的 Github API 速率限制

php - 在 PHP 中模拟启用 cookie 的浏览器

curl: (60) SSL 证书问题:无法获取本地颁发者证书

php - 如何避免 curl_exec() 中的 echo ?