github API - 使用curl PUT 将存储库添加到团队
我正在尝试向 github 上的团队添加一个存储库,因此:(
curl -i -u username:password -X PUT -d "" https://api.github.com/teams/:team/repos/:user/:repo
省略了具体细节)
几乎如不太详细的文档中所示。
这会产生 500 内部服务器错误
。
如果我省略 -d""
它会给出 411“Content-Length required”
,
如果我指定(使用-H
)“Content-Length:0”
:再次出现500
错误...
有什么线索吗?
[编辑] 答案:API 给出了虚假响应,并且那里的文档不是很好:
“:team
”是系统分配的数字 ID(不是您给它的名称..arg!) - 它只能通过 API 查询或在浏览器中查看 url 来获得你访问团队。多么优雅。
此外,您似乎不能在您的帐户下分配任何 ol' 存储库 - 它必须位于团队所属的“组织”中。
想要到达那里显然需要一些有趣的体操……如果我弄清楚的话,还需要更多。到目前为止 GitHub 可用性评级:(1-10) 2.
[编辑 2] 结论:github 上的文档规定了这一点:
添加团队存储库
为了向团队添加存储库,经过身份验证的用户必须是与团队关联的组织的所有者。
PUT /teams/:id/repos/:user/:repo
不起作用。 的作用是这样的:
PUT /teams/:id/repos/:org/:repo
将“:user
”替换为“:org
”(团队所属的“组织”的名称) 希望这
可以帮助某人避免同样有趣的下午。
I am trying to add a repo to a team on github, thus:
curl -i -u username:password -X PUT -d "" https://api.github.com/teams/:team/repos/:user/:repo
(specifics left out)
Pretty much as indicated in the not so verbose documentation.
This gives a 500 Internal server error
.
If I leave out the -d""
it gives a 411 "Content-Length required"
,
if I specify (using -H
) "Content-Length: 0"
: again the 500
error...
Any clues?
[edit] Answer: the API was giving spurious responses and the docs are not very good there:
":team
" is a numerical id assigned by the system (not the name you gave it .. arg!) - it is available only from an API query or from looking at the url in the browser when you visit the team. How elegant.
Moreover, it does not seem that you can assign just any ol' repo under your account - it must be in the "organization" to which the team belongs.
Getting it there will apparently require some entertaining gymnastics... more if I figure it out. GitHub Usablity rating so far: (1-10) 2.
[edit 2] The conclusion: the documents on github prescribe this:
Add team repo
In order to add a repo to a team, the authenticated user must be an owner of the org that the team is associated with.
PUT /teams/:id/repos/:user/:repo
Does not work. What does work is this:
PUT /teams/:id/repos/:org/:repo
Replacing ":user
" with ":org
" (the name of the "organization" that the team belongs to.
Case closed. Hopefully this helps somebody avoid a similarly entertaining afternoon.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于再次遇到此问题的人...看起来 :org 现在是全名而不是 ID
For anyone coming across this again... it looks like :org is now the full name and not the ID
您还需要确保 :repo 是
repo["name"]
字段,而不是repo["id"]
字段。You also need to make sure that the :repo is the
repo["name"]
field, NOT therepo["id"]
field.“github 上的文档是这样规定的:”
PUT /teams/:id/repos/:user/:repo
不起作用。有效的方法是:
PUT /teams/:id/repos/:org/:repo
将“:user”替换为“:org”(团队所属“组织”的名称) 。
"The documents on github prescribe this:"
PUT /teams/:id/repos/:user/:repo
Does not work. What does work is this:
PUT /teams/:id/repos/:org/:repo
Replacing ":user" with ":org" (the name of the "organization" that the team belongs to.